mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace ET.Server
|
||
{
|
||
|
||
[FriendOf(typeof(MatchComponent))]
|
||
public static partial class MatchComponentSystem
|
||
{
|
||
public static async ETTask Match(this MatchComponent self, long playerId)
|
||
{
|
||
if (self.waitMatchPlayers.Contains(playerId))
|
||
{
|
||
return;
|
||
}
|
||
|
||
self.waitMatchPlayers.Add(playerId);
|
||
|
||
if (self.waitMatchPlayers.Count < LSConstValue.MatchCount)
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 申请一个房间
|
||
StartSceneConfig startSceneConfig = RandomGenerator.RandomArray(StartSceneConfigCategory.Instance.Maps);
|
||
Match2Map_GetRoom match2MapGetRoom = new();
|
||
foreach (long id in self.waitMatchPlayers)
|
||
{
|
||
match2MapGetRoom.PlayerIds.Add(id);
|
||
}
|
||
|
||
self.waitMatchPlayers.Clear();
|
||
|
||
Scene root = self.Root();
|
||
Map2Match_GetRoom map2MatchGetRoom = await root.GetComponent<ActorSenderComponent>().Call(
|
||
startSceneConfig.ActorId, match2MapGetRoom) as Map2Match_GetRoom;
|
||
|
||
Match2G_NotifyMatchSuccess match2GNotifyMatchSuccess = new() { ActorId = map2MatchGetRoom.ActorId };
|
||
ActorLocationSenderComponent actorLocationSenderComponent = root.GetComponent<ActorLocationSenderComponent>();
|
||
|
||
foreach (long id in match2MapGetRoom.PlayerIds) // 这里发送消息线程不会修改PlayerInfo,所以可以直接使用
|
||
{
|
||
actorLocationSenderComponent.Get(LocationType.Player).Send(id, match2GNotifyMatchSuccess);
|
||
// 等待进入房间的确认消息,如果超时要通知所有玩家退出房间,重新匹配
|
||
}
|
||
}
|
||
}
|
||
|
||
} |