PlayerTempDataComponentSystem.cs 3.0 KB

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