12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (SessionPlayerComponent))]
- public static class SessionPlayerComponentSystem
- {
- public class SessionPlayerComponentAwakeSystem: AwakeSystem<SessionPlayerComponent, PlayerInfo>
- {
- protected override void Awake(SessionPlayerComponent self, PlayerInfo playerInfo)
- {
- Log.Info($"创建session玩家绑定组件...");
- self.PlayerInfo = playerInfo;
- self.PlayerId = playerInfo.Id;
- }
- }
- public class SessionPlayerComponentDestroySystem: DestroySystem<SessionPlayerComponent>
- {
- 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<PlayerTempDataComponent>().MapData.ready = false;
- // 记录玩家历史
- map.SyncPlayerHistoryData(player);
- // 战斗服场景玩家离开
- map.PlayerLeaveRequest(player, false);
- // 本地场景移除玩家
- map.RemovePlayer(player, false);
- // 移除本地玩家数据
- self.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
- // 战斗服结束场景
- map.DestroyZoneRequest();
- // 移除本地场景数据
- map.DomainScene().GetComponent<GameMapComponent>().Remove(map.Id);
- map.Dispose();
- }
- player.Dispose();
- }
- }
- /// <summary>
- /// 绑定玩家id
- /// </summary>
- /// <param name="self"></param>
- /// <param name="player"></param>
- public static void BindPlayerId(this SessionPlayerComponent self, WNPlayer player)
- {
- Log.Debug($"session玩家绑定组件 绑定玩家id={player.GetId()}");
- self.PlayerId = player.GetId();
- // 添加本地玩家数据
- self.DomainScene().GetComponent<GamePlayerComponent>().Add(player.GetId(), player);
- }
- /// <summary>
- /// 获取当前玩家实体
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static WNPlayer GetMyPlayer(this SessionPlayerComponent self)
- {
- return self.DomainScene().GetComponent<GamePlayerComponent>().Get(self.PlayerId);
- }
- }
- }
|