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, Action); } private async ETTask Action(Unit target, ISkillSender skillSender) { try { Unit owner = skillSender.caster; 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)}"); } } this.OnBulletCreate(owner, target, skillSender, this.skillOption.effectId, this.skillOption.time); Unit _target = skillSender.caster.GetComponent().currTarget; long _targetInstanceId = _target.InstanceId; long targetInstanceId = target.InstanceId; await TimerComponent.Instance.WaitAsync(this.skillOption.time); TargetableUnitComponent targetComponent = skillSender.caster.GetComponent(); if (_target.InstanceId != _targetInstanceId) { Log.Error($"taget is null where id is {_target?.Id} {_target.InstanceId} old instanceId = {_targetInstanceId}"); return; } if (target.InstanceId != targetInstanceId) { Log.Error($"taget is null where id is {target?.Id} {target.InstanceId} old instanceId = {targetInstanceId}"); return; } if (!skillSender.caster) { Log.Error($"caster is null where id is {target?.Id}"); return; } Unit oldTarget = targetComponent.currTarget; targetComponent.currTarget = _target; foreach (ModifierId modifierId in this.skillOption.modifierIds) { SkillMgrComponent skillMgrComponent = owner.GetComponent(); SkillLogic skillLogic = skillMgrComponent.GetSkill(skillSender.skillConfigId / 100); target.GetComponent().ApplyModifier(owner, skillLogic, modifierId); } 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, }); } } }