using Cal; using System; namespace ET { public class SkillOptionLogic_创建携带Modifier的子弹 : SkillOptionLogicBase { public override SkillOptionType skillOptionType => SkillOptionType.创建携带Modifier的子弹; public override SkillOptionBase skillOptionBase { get; set; } SkillOption_创建携带Modifier的子弹 skillOption; public override void HandleEvent(ISkillSender skillSender) { skillOption = skillOptionBase.As(); SelectTargetHelper.GetTarget(skillOption.selectTarget, skillSender, async (target, skillSender) => { try { SkillLogic logic = skillSender.skillLogic; Unit owner = logic.owner; int targetPos = target.GetComponent().pos; int minePos = owner.GetComponent().pos; float dis; if (owner.UnitType == UnitType.Player) { if (!PosConst.PosDistanceDic.TryGetValue(new PosConst.PosPair(minePos, targetPos), out dis)) { Log.Error($"posDic has not the key = {new PosConst.PosPair(minePos, targetPos)}"); } } else { if (!PosConst.PosDistanceDic.TryGetValue(new PosConst.PosPair(targetPos, minePos), out dis)) { Log.Error($"posDic has not the key = {new PosConst.PosPair(targetPos, minePos)}"); } } OnBulletCreate(owner, target, skillSender, skillOption.effectId, skillOption.time); Unit _target = skillSender.caster.GetComponent().currTarget; await TimerComponent.Instance.WaitAsync(skillOption.time); TargetableUnitComponent targetComponent = skillSender.caster.GetComponent(); if (!_target) { Log.Error($"taget is null where id is {target?.Id}"); return; } if (!skillSender.caster) { Log.Error($"caster is null where id is {target?.Id}"); return; } Unit oldTarget = targetComponent.currTarget; targetComponent.currTarget = _target; foreach (ModifierId Id in skillOption.modifierIds) { target.GetComponent().ApplyModifier(owner, logic, Id); } targetComponent.currTarget = oldTarget; } catch (Exception e) { Log.Error(e); } }); } private void OnBulletCreate(Unit owner, Unit target, ISkillSender skillSender, int effectId, int time) { target.GetComponent().BrocastInterval(new M2C_PlaySkillEffect { UnitId = owner.Id, TargetId = target.Id, EffectId = effectId, EffectPos = 0, EffectTargetType = 0, Time = time, }); } } }