2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class BattleComponentAwakeSystem : AwakeSystem<BattleComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(BattleComponent self)
|
|
|
|
|
{
|
|
|
|
|
self.unit = self.GetParent<Unit>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class BattleComponentSystem
|
|
|
|
|
{
|
|
|
|
|
public static void Damage(this BattleComponent self, BallisticData data, ISkillSender skillSender)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = self.GetParent<Unit>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (unit.IsAlive && data.value > 0)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
AttackComponent attackComponent = unit.GetComponent<AttackComponent>();
|
|
|
|
|
Unit attacker = attackComponent.attacker;
|
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
int value = MathHelper.RoundToInt(data.value);
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
|
|
|
|
ModifierContainerComponent attackerModifierContainer = attacker.GetComponent<ModifierContainerComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if (attackComponent.isFirstAtk)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位被攻击时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (modifierContainer.HasState(ModifierStateType.免疫伤害))
|
|
|
|
|
return;
|
|
|
|
|
if (modifierContainer.HasState(ModifierStateType.无敌))
|
|
|
|
|
return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (ModifierLogic modifierLogic in modifierContainer.modifierDic.Values)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
int shield = modifierLogic.shield;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (shield <= 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (shield <= value)
|
|
|
|
|
{
|
|
|
|
|
value -= shield;
|
|
|
|
|
modifierLogic.shield = 0;
|
|
|
|
|
modifierContainer.RemoveModifier(modifierLogic);
|
|
|
|
|
if(AppConfig.inst.showBattleDamageInfo)
|
2021-04-18 15:54:51 +08:00
|
|
|
|
Log.Info($"【护盾】已破,buff消失,受到伤害 = {value}");
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modifierLogic.shield -= value;
|
|
|
|
|
value = 0;
|
|
|
|
|
if (AppConfig.inst.showBattleDamageInfo)
|
|
|
|
|
Log.Info($"【护盾】未破 = {modifierLogic.shield}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (value <= 0) return;
|
|
|
|
|
if (attackComponent.isFirstAtk)
|
|
|
|
|
{
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位受到伤害时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = attackerModifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位施加伤害时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//吸血
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent attNum = attacker.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (MathHelper.IsHit(attNum.Get(NumericType.SuckR)))
|
|
|
|
|
{
|
|
|
|
|
int treatValue = (int)(attNum.Get(NumericType.SuckV) * value);
|
|
|
|
|
if (treatValue > 0)
|
|
|
|
|
{
|
|
|
|
|
attacker.GetComponent<AttackComponent>()?.TreatTarget(attacker, new BallisticData
|
|
|
|
|
{
|
|
|
|
|
isCrit=false,
|
|
|
|
|
value=treatValue
|
|
|
|
|
}, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attacker.UnitType == UnitType.Player)
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.DamageEvent
|
|
|
|
|
{
|
|
|
|
|
attacker = attacker,
|
|
|
|
|
damage = value
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
|
|
|
|
|
bool isDead = num.GetAsInt(NumericType.Hp) <= value;
|
|
|
|
|
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.BattleSkillRet
|
|
|
|
|
{
|
|
|
|
|
targetUnit = unit,
|
|
|
|
|
HpValue = -value,
|
|
|
|
|
IsCrit = data.isCrit,
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
|
|
|
|
|
if (isDead)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (modifierContainer.HasState(ModifierStateType.不死))
|
|
|
|
|
return;
|
|
|
|
|
if (modifierContainer.HasState(ModifierStateType.死亡复活))
|
|
|
|
|
{
|
|
|
|
|
unit.DeadWillLive();
|
|
|
|
|
//!添加复活buff
|
|
|
|
|
Revival(modifierContainer, attacker, 6000).Coroutine();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unit.Dead(num);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
TargetableUnitComponent attackerTargerComponent = attacker.GetComponent<TargetableUnitComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (attackerTargerComponent.selectedEnermy?.Id == unit.Id)
|
|
|
|
|
{
|
|
|
|
|
attackerTargerComponent.selectedEnermy = null;
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = attackerModifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位击杀目标时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位死亡时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BattleMgrCompnent.Instance.NotifyUnitDead(unit);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
num.ReduceSet(NumericType.Hp, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async ETVoid Revival(ModifierContainerComponent modifierContainer, Unit attacker, int time)
|
|
|
|
|
{
|
|
|
|
|
await TimerComponent.Instance.WaitAsync(time);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位复活时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
modifierLogic.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = attacker,
|
|
|
|
|
target = modifierContainer.GetParent<Unit>(),
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Treat(this BattleComponent self, BallisticData data, ISkillSender skillSender)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = self.GetParent<Unit>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (unit.IsAlive && data.value > 0)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit caster = unit.GetComponent<AttackComponent>().attacker;
|
|
|
|
|
NumericComponent num = self.unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
int value = MathHelper.RoundToInt(data.value);
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if(skillSender!=null)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位受到治疗时);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (optionList != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (SkillOptionBase item in optionList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
skillSender.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = caster,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (caster.UnitType == UnitType.Player)
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.TreatEvent
|
|
|
|
|
{
|
|
|
|
|
attacker = caster,
|
|
|
|
|
treat = value
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
num.AddSet(NumericType.Hp, value);
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.BattleSkillRet
|
|
|
|
|
{
|
|
|
|
|
targetUnit = unit,
|
|
|
|
|
HpValue = value,
|
|
|
|
|
IsCrit = data.isCrit,
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static string SelectedEnermy(this BattleComponent self, long unitId, TeamType teamType)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = self.GetParent<Unit>();
|
2021-05-01 11:27:41 +08:00
|
|
|
|
CopyBattle battleBase = BattleMgrCompnent.Instance.GetBattle(unit);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (battleBase == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 battleBase == null");
|
|
|
|
|
return "系统错误";
|
|
|
|
|
}
|
|
|
|
|
string ret = BattleHelper.SelectFixedTarget(battleBase, unit, unitId, battleBase.targetTeam, teamType);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|