PlayerTempDataComponentSystem.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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>
  9. {
  10. protected override void Awake(PlayerTempDataComponent self)
  11. {
  12. Log.Info($"创建玩家临时数据组件...");
  13. self.MapData = new PlayerMapInfo();
  14. self.MapData.mapId = 10099;
  15. self.MapData.x = 1586;
  16. self.MapData.y = 1566;
  17. // self.MapData.direction = System.MathF.PI / 2;
  18. self.MapData.hp = PLAYER.initHp;
  19. self.MapData.mp = PLAYER.initMp;
  20. self.ToJson4BattleServerTempData = self.GetBattleServerTempData();
  21. }
  22. }
  23. public class PlayerTempDataComponentDestroySystem: DestroySystem<PlayerTempDataComponent>
  24. {
  25. protected override void Destroy(PlayerTempDataComponent self)
  26. {
  27. }
  28. }
  29. /** 同步场景出生数据 **/
  30. public static void SyncBornData(this PlayerTempDataComponent self, float bornX, float bornY, int bornAreaId)
  31. {
  32. self.MapData.bornX = bornX;
  33. self.MapData.bornY = bornY;
  34. self.MapData.bornMapId = bornAreaId;
  35. }
  36. /** 同步场景临时数据 **/
  37. public static void SyncNowData(this PlayerTempDataComponent self, int areaId, long instanceId, GetPlayerData data)
  38. {
  39. self.MapData.x = data.x;
  40. self.MapData.y = data.y;
  41. self.MapData.direction = data.direction;
  42. self.MapData.hp = data.hp;
  43. self.MapData.mp = data.mp;
  44. self.MapData.mapId = areaId;
  45. self.MapData.mapInstanceId = instanceId;
  46. }
  47. /** 同步场景历史数据 **/
  48. public static void SyncHistoryData(this PlayerTempDataComponent self, MapConfig prop, long instanceId, GetPlayerData data)
  49. {
  50. self.MapData.historyX = data.x;
  51. self.MapData.historyY = data.y;
  52. self.MapData.historyDirection = data.direction;
  53. self.MapData.historyMapId = prop.Id;
  54. self.MapData.historyMapInstanceId = instanceId;
  55. }
  56. /// <summary>
  57. /// 发送给场景服的数据
  58. /// </summary>
  59. /// <param name="self"></param>
  60. /// <returns></returns>
  61. private static Dictionary<string, object> GetBattleServerTempData(this PlayerTempDataComponent self)
  62. {
  63. Dictionary<string, object> data = new Dictionary<string, object>();
  64. data.Add("x", self.MapData.x);
  65. data.Add("y", self.MapData.y);
  66. data.Add("direction", self.MapData.direction);
  67. data.Add("hp", self.MapData.hp > 0 ? self.MapData.hp : self.GetParent<WNPlayer>().GetComponent<PlayerBtlComponent>().GetAllInflus(PlayerBtlData.MaxHP));
  68. data.Add("mp", self.MapData.mp);
  69. return data;
  70. }
  71. }
  72. }