using System.Collections.Generic; using System.Linq; namespace ET.Server { [FriendOf(typeof (SessionPlayerComponent))] public static class SessionPlayerComponentSystem { public class SessionPlayerComponentAwakeSystem: AwakeSystem { protected override void Awake(SessionPlayerComponent self) { self.PlayerList = new List(); self.PlayerId = 0; } } public class SessionPlayerComponentDestroySystem: DestroySystem { protected override void Destroy(SessionPlayerComponent self) { WNPlayer player = self.GetMyPlayer(); if (player == null) { return; } Log.Info($"玩家断线了, playerId={self.PlayerId}, name={player.GetName()}"); // 玩家离开 player.GetComponent().MapData.ready = false; Map map = player.Map; if (map != null) { // 记录玩家历史 map.SyncPlayerHistoryData(player); // 场景移除玩家 map.RemovePlayer(player, false); map.PlayerLeaveRequest(player, false); } self.DomainScene().GetComponent().Remove(player.GetId()); player.Dispose(); } } /// /// 是否存在 /// /// /// /// public static bool IsExist(this SessionPlayerComponent self, long playerId) { return self.PlayerList.Any(info => info != null && info.PlayerId == playerId); } /// /// 获取 /// /// /// /// public static PlayerInfo Get(this SessionPlayerComponent self, long playerId) { return self.PlayerList.FirstOrDefault(info => info != null && info.PlayerId == playerId); } /// /// 添加 /// /// /// public static void Add(this SessionPlayerComponent self, PlayerInfo info) { if (info != null) { self.PlayerList.Add(info); } } /// /// 获取玩家实体 /// /// /// public static WNPlayer GetMyPlayer(this SessionPlayerComponent self) { return self.DomainScene().GetComponent().Get(self.PlayerId); } } }