SessionPlayerComponentSystem.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ET.Server
  4. {
  5. [FriendOf(typeof (SessionPlayerComponent))]
  6. public static class SessionPlayerComponentSystem
  7. {
  8. public class SessionPlayerComponentAwakeSystem: AwakeSystem<SessionPlayerComponent>
  9. {
  10. /// <summary>
  11. /// session玩家组件创建
  12. /// </summary>
  13. /// <param name="self"></param>
  14. protected override void Awake(SessionPlayerComponent self)
  15. {
  16. Log.Info($"创建session玩家绑定组件...");
  17. }
  18. }
  19. public class SessionPlayerComponentDestroySystem: DestroySystem<SessionPlayerComponent>
  20. {
  21. protected override void Destroy(SessionPlayerComponent self)
  22. {
  23. WNPlayer player = self.GetMyPlayer();
  24. if (player == null)
  25. {
  26. return;
  27. }
  28. Log.Info($"玩家断线了, playerId={self.PlayerId}, name={player.GetName()}");
  29. // 玩家离开
  30. player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
  31. Map map = player.Map;
  32. if (map != null)
  33. {
  34. // 记录玩家历史
  35. map.SyncPlayerHistoryData(player);
  36. // 战斗服场景玩家离开
  37. map.PlayerLeaveRequest(player, false);
  38. // 本地场景移除玩家
  39. map.RemovePlayer(player, false);
  40. // 移除本地组件数据
  41. map.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
  42. // 战斗服结束场景
  43. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  44. }
  45. player.Dispose();
  46. }
  47. }
  48. /// <summary>
  49. /// 绑定玩家id
  50. /// </summary>
  51. /// <param name="self"></param>
  52. /// <param name="playerId"></param>
  53. public static void BindPlayerId(this SessionPlayerComponent self, long playerId)
  54. {
  55. Log.Debug($"session玩家绑定组件 绑定玩家id={playerId}");
  56. self.PlayerId = playerId;
  57. }
  58. /// <summary>
  59. /// 获取当前玩家实体
  60. /// </summary>
  61. /// <param name="self"></param>
  62. /// <returns></returns>
  63. public static WNPlayer GetMyPlayer(this SessionPlayerComponent self)
  64. {
  65. return self.DomainScene().GetComponent<GamePlayerComponent>().Get(self.PlayerId);
  66. }
  67. }
  68. }