PlayerTempDataComponentSystem.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System.Collections.Generic;
  2. using BattleIce;
  3. namespace ET.Server
  4. {
  5. [FriendOf(typeof (PlayerTempDataComponent))]
  6. public static class PlayerTempDataComponentSystem
  7. {
  8. public class PlayerTempDataComponentAwakeSystem: AwakeSystem<PlayerTempDataComponent, WNPlayer>
  9. {
  10. /// <summary>
  11. /// 玩家临时数据组件创建
  12. /// </summary>
  13. /// <param name="self"></param>
  14. /// <param name="player"></param>
  15. protected override void Awake(PlayerTempDataComponent self, WNPlayer player)
  16. {
  17. Log.Info($"创建玩家临时数据组件...");
  18. self.Player = player;
  19. }
  20. }
  21. public class PlayerTempDataComponentDestroySystem: DestroySystem<PlayerTempDataComponent>
  22. {
  23. /// <summary>
  24. /// 玩家临时数据组件销毁
  25. /// </summary>
  26. /// <param name="self"></param>
  27. protected override void Destroy(PlayerTempDataComponent self)
  28. {
  29. // todo 暂时去掉数据落地逻辑
  30. // Log.Debug($"玩家临时数据保存");
  31. // self?.Save();
  32. }
  33. }
  34. /// <summary>
  35. /// 初始化
  36. /// </summary>
  37. /// <param name="self"></param>
  38. public static async ETTask Init(this PlayerTempDataComponent self)
  39. {
  40. List<PlayerMapInfo> list = await DBManagerComponent.Instance.GetZoneDB(self.DomainZone())
  41. .Query<PlayerMapInfo>(p => p.Id == self.Player.GetId());
  42. if (list is { Count: > 0 })
  43. {
  44. self.MapData = list[0];
  45. }
  46. if (self.MapData != null)
  47. {
  48. return;
  49. }
  50. self.MapData = new PlayerMapInfo();
  51. self.MapData.mapId = 10098;
  52. // self?.Save();
  53. }
  54. private static async ETTask Save(this PlayerTempDataComponent self)
  55. {
  56. if (self.MapData == null)
  57. {
  58. Log.Debug($"保存玩家临时数据组件数据, Data is null");
  59. return;
  60. }
  61. self.MapData.Id = self.Player.GetId();
  62. await DBManagerComponent.Instance.GetZoneDB(self.DomainZone()).Save(self.Player.GetId(), self.MapData);
  63. }
  64. /** 同步场景出生数据 **/
  65. public static void SyncBornData(this PlayerTempDataComponent self, float bornX, float bornY, int bornAreaId)
  66. {
  67. self.MapData.bornX = bornX;
  68. self.MapData.bornY = bornY;
  69. self.MapData.bornMapId = bornAreaId;
  70. }
  71. /** 同步场景临时数据 **/
  72. public static void SyncNowData(this PlayerTempDataComponent self, int areaId, long instanceId, GetPlayerData data)
  73. {
  74. self.MapData.x = data.x;
  75. self.MapData.y = data.y;
  76. self.MapData.direction = data.direction;
  77. self.MapData.hp = data.hp;
  78. self.MapData.mp = data.mp;
  79. self.MapData.mapId = areaId;
  80. self.MapData.mapInstanceId = instanceId;
  81. }
  82. /** 同步场景历史数据 **/
  83. public static void SyncHistoryData(this PlayerTempDataComponent self, MapConfig prop, long instanceId, GetPlayerData data)
  84. {
  85. self.MapData.historyX = data.x;
  86. self.MapData.historyY = data.y;
  87. self.MapData.historyDirection = data.direction;
  88. self.MapData.historyMapId = prop.Id;
  89. self.MapData.historyMapInstanceId = instanceId;
  90. }
  91. }
  92. }