PlayerSkillComponentSystem.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. Log.Debug($"玩家技能数据保存");
  30. self?.Save();
  31. }
  32. }
  33. /// <summary>
  34. /// 初始化
  35. /// </summary>
  36. /// <param name="self"></param>
  37. public static async ETTask Init(this PlayerSkillComponent self)
  38. {
  39. List<PlayerSkillInfo> list = await DBManagerComponent.Instance.GetZoneDB(self.DomainZone())
  40. .Query<PlayerSkillInfo>(p => p.Id == self.Player.GetId());
  41. if (list is { Count: > 0 })
  42. {
  43. self.Data = list[0];
  44. }
  45. if (self.Data is { Skills.Count: > 0 })
  46. {
  47. return;
  48. }
  49. self.Data = new PlayerSkillInfo();
  50. self.Data.Skills = new List<Struct.PlayerSkillBaseData>();
  51. Character config = CharacterCategory.Instance.Get(self.Player.GetPro());
  52. if (config != null && config.InitSkillList.Count > 0)
  53. {
  54. foreach (Struct.IntIntData intIntData in config.InitSkillList.Where(intIntData => intIntData != null))
  55. {
  56. self.Data.Skills.Add(new Struct.PlayerSkillBaseData(intIntData.value1, intIntData.value2, false, 0L));
  57. }
  58. }
  59. self?.Save();
  60. self.Player.ToJson4BattleServerSkillInfos = self.ToJson4BattleServer();
  61. }
  62. /// <summary>
  63. /// 保存数据
  64. /// </summary>
  65. /// <param name="self"></param>
  66. private static async ETTask Save(this PlayerSkillComponent self)
  67. {
  68. if (self.Data == null)
  69. {
  70. Log.Debug($"保存玩家技能组件数据, Data is null");
  71. return;
  72. }
  73. self.Data.Id = self.Player.GetId();
  74. await DBManagerComponent.Instance.GetZoneDB(self.DomainZone()).Save(self.Data);
  75. }
  76. /// <summary>
  77. /// 被动技能, 发给bs
  78. /// </summary>
  79. /// <param name="self"></param>
  80. /// <returns></returns>
  81. private static IEnumerable<Struct.SkillInfo> GetPassiveSkillInfoBS(this PlayerSkillComponent self)
  82. {
  83. List<Struct.SkillInfo> list = new List<Struct.SkillInfo>();
  84. foreach (SkillConfig prop in SkillConfigCategory.Instance.GetAll().Values.Where(prop => prop != null))
  85. {
  86. if (prop.ProId != self.Player.GetPro() || prop.SkillType != (int)SkillType.PLAYER_PASSIVE)
  87. {
  88. continue;
  89. }
  90. Struct.SkillInfo info = new ();
  91. info.type = prop.SkillType;
  92. info.id = prop.Id;
  93. info.level = 1;
  94. info.skillTime = 0L;
  95. info.cdTime = 0;
  96. list.Add(info);
  97. }
  98. return list;
  99. }
  100. /// <summary>
  101. /// 战斗服数据
  102. /// </summary>
  103. /// <param name="self"></param>
  104. /// <returns></returns>
  105. public static List<Struct.SkillInfo> ToJson4BattleServer(this PlayerSkillComponent self)
  106. {
  107. List<Struct.SkillInfo> skills = new List<Struct.SkillInfo>();
  108. foreach (Struct.PlayerSkillBaseData skill in self.Data.Skills.Where(skill => skill != null))
  109. {
  110. if (skill.isUnlock())
  111. {
  112. SkillConfig prop = SkillConfigCategory.Instance.Get(skill.id);
  113. if (prop != null && !SkillHelper.IsPassive(prop))
  114. {
  115. skills.Add(SkillHelper.NewSkillInfo(skill));
  116. }
  117. }
  118. }
  119. // 被动技能战斗服信息
  120. skills.AddRange(self.GetPassiveSkillInfoBS());
  121. return skills;
  122. }
  123. }
  124. }