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();
- }
- }
-
-
-
-
-
- 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);
- }
-
-
-
-
-
- public static WNPlayer GetMyPlayer(this SessionPlayerComponent self)
- {
- return self.DomainScene().GetComponent<GamePlayerComponent>().Get(self.PlayerId);
- }
- }
- }
|