PlayerBtlComponentSystem.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. namespace ET.Server
  7. {
  8. [FriendOf(typeof (PlayerBtlComponent))]
  9. public static class PlayerBtlComponentSystem
  10. {
  11. public class PlayerBtlComponentAwakeSystem: AwakeSystem<PlayerBtlComponent, WNPlayer>
  12. {
  13. protected override void Awake(PlayerBtlComponent self, WNPlayer player)
  14. {
  15. Log.Info($"创建玩家属性组件...");
  16. self.Player = player;
  17. self.CharacterProp = player.BasicProp;
  18. if (self.CharacterProp == null)
  19. {
  20. Log.Warning($"PlayerBtlComponentSystem 玩家职业信息为空: playerId={player.GetId()}, 职业={player.GetPro()}");
  21. }
  22. }
  23. }
  24. public class PlayerBtlComponentDestroySystem: DestroySystem<PlayerBtlComponent>
  25. {
  26. protected override void Destroy(PlayerBtlComponent self)
  27. {
  28. }
  29. }
  30. /// <summary>
  31. /// 初始化
  32. /// </summary>
  33. /// <param name="self"></param>
  34. public static async ETTask Init(this PlayerBtlComponent self)
  35. {
  36. self.CalProLvlData();
  37. self.CalFinalData();
  38. await ETTask.CompletedTask;
  39. }
  40. /// <summary>
  41. /// 计算角色的职业和等级带来的属性
  42. /// </summary>
  43. /// <param name="self"></param>
  44. public static void CalProLvlData(this PlayerBtlComponent self)
  45. {
  46. self.Data_Pro_Lv.Clear();
  47. // 角色初始属性
  48. Dictionary<PlayerBtlData, int> iniProp = new Dictionary<PlayerBtlData, int>();
  49. iniProp.TryAdd(PlayerBtlData.MaxHP, self.CharacterProp.InitMaxHP);
  50. iniProp.TryAdd(PlayerBtlData.Attack, self.CharacterProp.InitAttack);
  51. iniProp.TryAdd(PlayerBtlData.RunSpeed, self.CharacterProp.BaseMoveSpeed);
  52. iniProp.TryAdd(PlayerBtlData.AttackSpeed, self.CharacterProp.BaseAtkSpeed);
  53. AttributeHelper.AddData2AllData(iniProp, self.Data_Pro_Lv);
  54. }
  55. /// <summary>
  56. /// 计算所有属性
  57. /// </summary>
  58. /// <param name="self"></param>
  59. public static void CalFinalData(this PlayerBtlComponent self)
  60. {
  61. // 各模块带来的属性
  62. self.CalModuleData();
  63. }
  64. /// <summary>
  65. /// 各模块带来的属性
  66. /// </summary>
  67. /// <param name="self"></param>
  68. public static void CalModuleData(this PlayerBtlComponent self)
  69. {
  70. self.AllInflus.Clear();
  71. // 角色初始化属性
  72. AttributeHelper.AddData2AllData(self.Data_Pro_Lv, self.AllInflus);
  73. }
  74. /// <summary>
  75. /// 发送给场景服的人物数据(战斗属性)
  76. /// </summary>
  77. /// <returns></returns>
  78. public static Dictionary<string, float> GetBattleServerEffects(this PlayerBtlComponent self)
  79. {
  80. Dictionary<string, float> data = new Dictionary<string, float>();
  81. foreach (var keyValue in self.AllInflus.Where(keyValue => keyValue.Value > 0))
  82. {
  83. data.Add(keyValue.Key.ToString(), keyValue.Value);
  84. }
  85. // 移动速度
  86. float runSpeed = data.TryGetValue(PlayerBtlData.RunSpeed.ToString(), out float value) ? value : 0;
  87. float moveSpeed = self.CharacterProp._InitSpeed * (runSpeed / self.Tenthousand);
  88. data.Add("MoveSpeed", moveSpeed);
  89. return data;
  90. }
  91. }
  92. }