PlayerBtlComponentSystem.cs 3.5 KB

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