using Cal; using Cal.DataTable; using System; using System.Collections.Generic; namespace ET { public class SkillMgrComponentLoadSystem : LoadSystem { public override void Load(SkillMgrComponent self) { foreach (KeyValuePair kv in self.skillDic) { try { if (!SkillConfigComponent.SkillLogicCollection.skillDic.TryGetValue(kv.Key, out SkillLogicConfig skillLogicConfig)) { Log.Error($"skillLogicConfig==null where skillId = {kv.Key}"); return; } kv.Value.skillLogicConfig = skillLogicConfig; SkillConfig skillConfig = DataTableHelper.Get(kv.Key * 100); if (skillConfig == null) { Log.Error($"skillConfig == null where id = {kv.Key}"); } kv.Value.skillConfig = skillConfig; } catch (Exception e) { Log.Error(e); } } Log.Info($"替换技能配置成功"); } } public class SkillMgrComponentDstroySystem : DestroySystem { public override void Destroy(SkillMgrComponent self) { self.skillDic.Clear(); } } public static class SkillMgrComponentSystem { public static void AddSkill(this SkillMgrComponent self, Unit skillFrom, UnitSkill unitSkill) { if (unitSkill == UnitSkill.Null) { Log.Error($"unitSkill==null where unitId ={skillFrom.Id}"); return; } int skillId = (int)unitSkill.Id; Unit unit = self.GetParent(); if (self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic)) { ExecuteEvent(); return; } skillLogic = EntityFactory.CreateWithParent(skillFrom.DomainScene()); if (!SkillConfigComponent.SkillLogicCollection.skillDic.TryGetValue(skillId, out SkillLogicConfig skillLogicConfig)) { Log.Error($"skillLogicConfig==null where skillId = {skillId}"); return; } skillLogic.skillLogicConfig = skillLogicConfig; skillLogic.owner = skillFrom; skillLogic.skillLevel = unitSkill.Level; SkillConfig skillConfig = DataTableHelper.Get(skillId*100); if (skillConfig == null) { Log.Error($"skillConfig == null where id = {skillId}"); } skillLogic.skillConfig = skillConfig; if (!self.skillDic.TryAdd(skillId, skillLogic)) { Log.Error($"[上面已经判断了不含有这个键]"); return; } //!执行添加技能的事件 ExecuteEvent(); void ExecuteEvent() { if (unitSkill.IsPassive) skillLogic.HandleEvent(SkillEventCondition.当技能添加, new SkillSender { caster = skillFrom, skillLogic = skillLogic }); } } public static SkillLogic GetSkill(this SkillMgrComponent self, int skillId) { self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic); return skillLogic; } public static void UpdateSkill(this SkillMgrComponent self, Unit skillFrom, int skillId) { if (!self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic)) { Log.Error($"skillLogic == null where skillid = {skillId}"); return; } //!升级 skillLogic.UpdateLevel(); Unit unit = self.GetParent(); //!执行添加技能的事件 skillLogic.HandleEvent(SkillEventCondition.当技能升级, new SkillSender { caster = skillFrom, skillLogic = skillLogic }); } public static void RemoveSkill(this SkillMgrComponent self, Unit skillFrom, int skillId) { if (!self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic)) { Log.Error($"skillLogic == null where skillid = {skillId}"); return; } skillLogic.Dispose(); self.skillDic.Remove(skillId); Unit unit = self.GetParent(); //!执行添加技能的事件 skillLogic.HandleEvent(SkillEventCondition.当技能移除, new SkillSender { caster = skillFrom, skillLogic = skillLogic }); } } }