CTT/Server/Hotfix/Game/SkillSystem/NewSkill/Component/SkillOptions/SkillOptionLogic_创建携带Modifi...

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,
});
}
}
}