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, PlayerInfo playerInfo) { Log.Info($"创建session玩家绑定组件..."); self.PlayerInfo = playerInfo; self.PlayerId = playerInfo.Id; } } 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()}"); Map map = player.Map; if (map != null) { // 玩家离开 player.GetComponent().MapData.ready = false; // 记录玩家历史 map.SyncPlayerHistoryData(player); // 战斗服场景玩家离开 map.PlayerLeaveRequest(player, false); // 本地场景移除玩家 map.RemovePlayer(player, false); // 移除本地玩家数据 self.DomainScene().GetComponent().Remove(player.GetId()); // 战斗服结束场景 map.DestroyZoneRequest(); // 移除本地场景数据 map.DomainScene().GetComponent().Remove(map.Id); map.Dispose(); } player.Dispose(); } } /// /// 绑定玩家id /// /// /// public static void BindPlayerId(this SessionPlayerComponent self, WNPlayer player) { Log.Debug($"session玩家绑定组件 绑定玩家id={player.GetId()}"); self.PlayerId = player.GetId(); // 添加本地玩家数据 self.DomainScene().GetComponent().Add(player.GetId(), player); } /// /// 获取当前玩家实体 /// /// /// public static WNPlayer GetMyPlayer(this SessionPlayerComponent self) { return self.DomainScene().GetComponent().Get(self.PlayerId); } } }