96 lines
4.0 KiB
C#
Executable File
96 lines
4.0 KiB
C#
Executable File
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<SkillOption_创建携带Modifier的子弹>();
|
|
SelectTargetHelper.GetTarget(skillOption.selectTarget, skillSender, Action);
|
|
}
|
|
|
|
private async ETTask Action(Unit target, ISkillSender skillSender)
|
|
{
|
|
try
|
|
{
|
|
Unit owner = skillSender.caster;
|
|
int targetPos = target.GetComponent<Position>().pos;
|
|
int minePos = owner.GetComponent<Position>().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<TargetableUnitComponent>().currTarget;
|
|
long _targetInstanceId = _target.InstanceId;
|
|
long targetInstanceId = target.InstanceId;
|
|
await TimerComponent.Instance.WaitAsync(this.skillOption.time);
|
|
TargetableUnitComponent targetComponent = skillSender.caster.GetComponent<TargetableUnitComponent>();
|
|
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<SkillMgrComponent>();
|
|
SkillLogic skillLogic = skillMgrComponent.GetSkill(skillSender.skillConfigId / 100);
|
|
target.GetComponent<ModifierContainerComponent>().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<BrocastComponent>().BrocastInterval(new M2C_PlaySkillEffect
|
|
{
|
|
UnitId = owner.Id,
|
|
TargetId = target.Id,
|
|
EffectId = effectId,
|
|
EffectPos = 0,
|
|
EffectTargetType = 0,
|
|
Time = time,
|
|
});
|
|
}
|
|
}
|
|
} |