PlayerSkillComponentSystem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ET.Server
  4. {
  5. [FriendOf(typeof (PlayerSkillComponent))]
  6. public static class PlayerSkillComponentSystem
  7. {
  8. public class PlayerSkillComponentAwakeSystem: AwakeSystem<PlayerSkillComponent, WNPlayer>
  9. {
  10. /// <summary>
  11. /// 玩家技能组件创建
  12. /// </summary>
  13. /// <param name="self"></param>
  14. /// <param name="player"></param>
  15. protected override void Awake(PlayerSkillComponent self, WNPlayer player)
  16. {
  17. Log.Info($"创建玩家技能组件...");
  18. self.Player = player;
  19. }
  20. }
  21. public class PlayerSkillComponentDestroySystem: DestroySystem<PlayerSkillComponent>
  22. {
  23. /// <summary>
  24. /// 玩家技能组件销毁
  25. /// </summary>
  26. /// <param name="self"></param>
  27. protected override void Destroy(PlayerSkillComponent self)
  28. {
  29. // todo 暂时去掉数据落地逻辑
  30. // Log.Debug($"玩家技能数据保存");
  31. // self?.Save();
  32. }
  33. }
  34. /// <summary>
  35. /// 初始化
  36. /// </summary>
  37. /// <param name="self"></param>
  38. public static async ETTask Init(this PlayerSkillComponent self)
  39. {
  40. List<PlayerSkillInfo> list = await DBManagerComponent.Instance.GetZoneDB(self.DomainZone())
  41. .Query<PlayerSkillInfo>(p => p.Id == self.Player.GetId());
  42. if (list is { Count: > 0 })
  43. {
  44. self.Data = list[0];
  45. }
  46. if (self.Data is { Skills.Count: > 0 })
  47. {
  48. return;
  49. }
  50. self.Data = new PlayerSkillInfo();
  51. self.Data.Skills = new List<Struct.PlayerSkillBaseData>();
  52. CharacterConfig config = CharacterConfigCategory.Instance.Get(self.Player.GetPro());
  53. if (config != null && config.InitSkillList.Count > 0)
  54. {
  55. foreach (Struct.IntIntData intIntData in config.InitSkillList.Where(intIntData => intIntData != null))
  56. {
  57. self.Data.Skills.Add(new Struct.PlayerSkillBaseData(intIntData.value1, intIntData.value2, false, 0L));
  58. }
  59. }
  60. self.ToJson4BattleServerSkills = self.GetBattleServerSkills();
  61. // self?.Save();
  62. }
  63. /// <summary>
  64. /// 保存数据
  65. /// </summary>
  66. /// <param name="self"></param>
  67. private static async ETTask Save(this PlayerSkillComponent self)
  68. {
  69. if (self.Data == null)
  70. {
  71. Log.Debug($"保存玩家技能组件数据, Data is null");
  72. return;
  73. }
  74. self.Data.Id = self.Player.GetId();
  75. await DBManagerComponent.Instance.GetZoneDB(self.DomainZone()).Save(self.Data);
  76. }
  77. /// <summary>
  78. /// 被动技能, 发给bs
  79. /// </summary>
  80. /// <param name="self"></param>
  81. /// <returns></returns>
  82. private static IEnumerable<Struct.SkillInfo> GetPassiveSkillInfoBS(this PlayerSkillComponent self)
  83. {
  84. List<Struct.SkillInfo> list = new List<Struct.SkillInfo>();
  85. foreach (SkillConfig prop in SkillConfigCategory.Instance.GetAll().Values.Where(prop => prop != null))
  86. {
  87. if (prop.ProId != self.Player.GetPro() || prop.SkillType != (int)SkillType.PLAYER_PASSIVE)
  88. {
  89. continue;
  90. }
  91. Struct.SkillInfo info = new ();
  92. info.type = prop.SkillType;
  93. info.id = prop.Id;
  94. info.level = 1;
  95. info.skillTime = 0L;
  96. info.cdTime = 0;
  97. info.flag = 0;
  98. info.autoLaunch = false;
  99. list.Add(info);
  100. }
  101. return list;
  102. }
  103. /// <summary>
  104. /// 战斗服数据
  105. /// </summary>
  106. /// <param name="self"></param>
  107. /// <returns></returns>
  108. public static List<Struct.SkillInfo> GetBattleServerSkills(this PlayerSkillComponent self)
  109. {
  110. List<Struct.SkillInfo> skills = new List<Struct.SkillInfo>();
  111. foreach (Struct.PlayerSkillBaseData skill in self.Data.Skills.Where(skill => skill != null))
  112. {
  113. if (!skill.unlock)
  114. {
  115. continue;
  116. }
  117. SkillConfig prop = SkillConfigCategory.Instance.Get(skill.id);
  118. if (prop != null && !SkillHelper.IsPassive(prop))
  119. {
  120. skills.Add(SkillHelper.NewSkillInfo(skill));
  121. }
  122. }
  123. // 被动技能战斗服信息
  124. skills.AddRange(self.GetPassiveSkillInfoBS());
  125. return skills;
  126. }
  127. }
  128. }