using Cal; using System; using System.Collections.Generic; namespace ET { public class AttackComponentAwakeSystem : AwakeSystem { public override void Awake(AttackComponent self) { self.multipleDamageX10000 = 1; self.playAmount = 1; self.isFirstAtk = true; } } public class AttackComponentDstroySystem : DestroySystem { public override void Destroy(AttackComponent self) { self.attacker = null; } } public static class AttackComponentSystem { public static void Clear(this AttackComponent self) { self.attacker = null; self.attackData = default; self.isFirstAtk = false; } /// /// 《选择目标》 /// /// /// public static bool StartSpellSkill(this AttackComponent self, SkillLogic skillLogic) { Unit unit = self.GetParent(); self.isFirstAtk = true; TargetableUnitComponent targetCompoennt = self.Parent.GetComponent(); List allList = targetCompoennt.GetAllTarget(); var config = skillLogic.skillLogicConfig; SkillTypes skillTypes = config.skillType; skillLogic.HandleEvent(SkillEventCondition.当技能施法前, new SkillSender { caster = unit, skillLogic = skillLogic, }); return skillTypes switch { SkillTypes.普通 => SpellGeneralSkill(self, unit, skillLogic, allList), SkillTypes.被动 => false, SkillTypes.引导 => SpellChannelSkill(self, unit, skillLogic, allList), SkillTypes.开关 => SpellToggleSkill(self, unit, skillLogic, allList), _ => false, }; } private static bool SpellGeneralSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List allList) { int playAmount = skillLogic.GetPlayAmount(); Log.Info($"{playAmount}"); for (int i = playAmount - 1; i >= 0; i--) { SpellSkill(self, unit, skillLogic, allList).Coroutine(); } return true; } private static bool SpellChannelSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List allList) { SkillLogicConfig skillConfig = skillLogic.skillLogicConfig; int duration = skillConfig.duration; int interval = skillConfig.interval; SpellChannelSkillAsync(self, unit, skillLogic, duration, interval, allList).Coroutine(); return true; } private static async ETVoid SpellChannelSkillAsync(AttackComponent self, Unit unit, SkillLogic skillLogic, int duration, int interval, List allList) { if (AppConfig.inst.showBattleSkillInfo) Log.Info($"{unit}释放技能:【{skillLogic.skillLogicConfig.skillName}({skillLogic.skillConfigId})】"); //!广播释放技能 foreach (Unit u in allList) { M2C_PlaySkill m2C_PlayerSkill = new M2C_PlaySkill { SkillId = skillLogic.skillId, UnitId = unit.Id, }; MessageHelper.SendActor(u, m2C_PlayerSkill); } //!动画开始到产生特效的时间 int delayTime = 1000; await TimerComponent.Instance.WaitAsync(delayTime); skillLogic.HandleEvent(SkillEventCondition.当技能引导开始, new SkillSender { caster = unit, skillLogic = skillLogic, }); long start = TimeHelper.ClientNow(); long now = start; do { await TimerComponent.Instance.WaitTillAsync(now + interval); now = TimeHelper.ClientNow(); skillLogic.HandleEvent(SkillEventCondition.当技能引导时, new SkillSender { caster = unit, skillLogic = skillLogic }); } while (now + interval <= start + duration); skillLogic.HandleEvent(SkillEventCondition.当技能引导完成, new SkillSender { caster = unit, skillLogic = skillLogic, }); } private static bool SpellToggleSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List allList) { return false; } private static async ETVoid SpellSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List allList) { if (AppConfig.inst.showBattleSkillInfo) Log.Info($"{unit}释放技能:【{skillLogic.skillLogicConfig.skillName}({skillLogic.skillConfigId})】"); skillLogic.HandleEvent(SkillEventCondition.当技能施法开始, new SkillSender { caster = unit, skillLogic = skillLogic }); //!广播释放技能 foreach (Unit u in allList) { M2C_PlaySkill m2C_PlayerSkill = new M2C_PlaySkill { SkillId = skillLogic.skillId, UnitId = unit.Id, }; MessageHelper.SendActor(u, m2C_PlayerSkill); } //!动画开始到产生特效的时间 int delayTime = 1000; await TimerComponent.Instance.WaitAsync(delayTime); self.EndSpellSkill(unit, skillLogic); } public static void EndSpellSkill(this AttackComponent self, Unit unit, SkillLogic skillLogic) { skillLogic.HandleEvent(SkillEventCondition.当技能施法时, new SkillSender { caster = unit, skillLogic = skillLogic }); } /// /// 获取子弹数据,里面包含伤害等 /// public static BallisticData GetAttackData(this AttackComponent self) { return self.attackData; } /// /// 执行伤害 /// public static void AttackTarget(this AttackComponent self, Unit target, BallisticData data, ISkillSender skillSender, bool applyBallisticData = true) { Unit unit = self.GetParent(); if (AppConfig.inst.showBattleDamageInfo) Log.Debug($"{unit.Id}对{target.Id},伤害数据2:{data}"); if (data.value == 0) { } if (applyBallisticData) self.attackData = data; if (!target || !target.IsAlive) { // if(AppConfig.inst.isTest) // Log.Warning($"目标{target.Id}已经死亡 "); return; } AttackComponent attackComponent = target.GetComponent(); if (attackComponent!=null) attackComponent.attacker = unit; target.GetComponent().unit = unit; target.GetComponent().Damage(data, skillSender); } /// /// 执行治疗 /// public static void TreatTarget(this AttackComponent self, Unit target, BallisticData ballisticData, ISkillSender skillSender) { Unit unit = self.GetParent(); if (AppConfig.inst.showBattleDamageInfo) Log.Debug($"{self.GetParent().Id}对{target.Id},治疗数据:{ballisticData}"); AttackComponent attackComponent = target.GetComponent(); attackComponent.attacker = unit; target.GetComponent().Treat(ballisticData, skillSender); } } }