PlayerBtlComponentSystem.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 void Init(this PlayerBtlComponent self)
  35. {
  36. self.CalProLvlData();
  37. self.CalFinalData();
  38. }
  39. /// <summary>
  40. /// 计算角色的职业和等级带来的属性
  41. /// </summary>
  42. /// <param name="self"></param>
  43. public static void CalProLvlData(this PlayerBtlComponent self)
  44. {
  45. self.Data_Pro_Lv.Clear();
  46. // 角色初始属性
  47. Dictionary<PlayerBtlData, int> iniProp = new Dictionary<PlayerBtlData, int>();
  48. iniProp.TryAdd(PlayerBtlData.MaxHP, self.CharacterProp.InitMaxHP);
  49. iniProp.TryAdd(PlayerBtlData.Attack, self.CharacterProp.InitAttack);
  50. iniProp.TryAdd(PlayerBtlData.RunSpeed, self.CharacterProp.BaseMoveSpeed);
  51. iniProp.TryAdd(PlayerBtlData.AttackSpeed, self.CharacterProp.BaseAtkSpeed);
  52. AttributeHelper.AddData2AllData(iniProp, self.Data_Pro_Lv);
  53. }
  54. /// <summary>
  55. /// 计算所有属性
  56. /// </summary>
  57. /// <param name="self"></param>
  58. public static void CalFinalData(this PlayerBtlComponent self)
  59. {
  60. // 各模块带来的属性
  61. self.CalModuleData();
  62. }
  63. /// <summary>
  64. /// 各模块带来的属性
  65. /// </summary>
  66. /// <param name="self"></param>
  67. public static void CalModuleData(this PlayerBtlComponent self)
  68. {
  69. self.AllInflus.Clear();
  70. // 角色初始化属性
  71. AttributeHelper.AddData2AllData(self.Data_Pro_Lv, self.AllInflus);
  72. }
  73. public static int GetAllInflus(this PlayerBtlComponent self, PlayerBtlData key)
  74. {
  75. return self.AllInflus.TryGetValue(key, out int value)? value : 0;
  76. }
  77. /// <summary>
  78. /// 发送给场景服的人物数据(战斗属性)
  79. /// </summary>
  80. /// <returns></returns>
  81. public static Dictionary<string, float> GetBattleServerEffects(this PlayerBtlComponent self)
  82. {
  83. Dictionary<string, float> data = new Dictionary<string, float>();
  84. foreach (var keyValue in self.AllInflus.Where(keyValue => keyValue.Value > 0))
  85. {
  86. data.Add(keyValue.Key.ToString(), keyValue.Value);
  87. }
  88. // 移动速度
  89. float runSpeed = data.TryGetValue(PlayerBtlData.RunSpeed.ToString(), out float value) ? value : 0;
  90. float moveSpeed = self.CharacterProp._InitSpeed * (runSpeed / self.Tenthousand);
  91. data.Add("MoveSpeed", moveSpeed);
  92. return data;
  93. }
  94. }
  95. }