246 lines
12 KiB
C#
Executable File
246 lines
12 KiB
C#
Executable File
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
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
if (unit.IsAlive && data.value > 0)
|
||
{
|
||
AttackComponent attackComponent = unit.GetComponent<AttackComponent>();
|
||
Unit attacker = attackComponent.attacker;
|
||
NumericComponent num = unit.GetComponent<NumericComponent>();
|
||
int value = MathHelper.RoundToInt(data.value);
|
||
|
||
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
||
ModifierContainerComponent attackerModifierContainer = attacker.GetComponent<ModifierContainerComponent>();
|
||
|
||
if (attackComponent.isFirstAtk)
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位被攻击时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(attacker,
|
||
unit,
|
||
modifierLogic.skillConfigId,
|
||
modifierLogic));
|
||
}
|
||
}
|
||
|
||
if (modifierContainer.HasState(ModifierStateType.免疫伤害))
|
||
return;
|
||
if (modifierContainer.HasState(ModifierStateType.无敌))
|
||
return;
|
||
foreach (ModifierLogic modifierLogic in modifierContainer.modifierDic.Values)
|
||
{
|
||
int shield = modifierLogic.shield;
|
||
if (shield <= 0)
|
||
continue;
|
||
if (shield <= value)
|
||
{
|
||
value -= shield;
|
||
modifierLogic.shield = 0;
|
||
modifierContainer.RemoveModifier(modifierLogic);
|
||
if (AppConfig.inst.showBattleDamageInfo)
|
||
Log.Info($"【护盾】已破,buff消失,受到伤害 = {value}");
|
||
}
|
||
else
|
||
{
|
||
modifierLogic.shield -= value;
|
||
value = 0;
|
||
if (AppConfig.inst.showBattleDamageInfo)
|
||
Log.Info($"【护盾】未破 = {modifierLogic.shield}");
|
||
}
|
||
}
|
||
|
||
if (value <= 0) return;
|
||
if (attackComponent.isFirstAtk)
|
||
{
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位受到伤害时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
|
||
attacker,unit,modifierLogic.skillConfigId,modifierLogic ));
|
||
}
|
||
}
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
attackerModifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位施加伤害时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
|
||
attacker,attacker,modifierLogic.skillConfigId,modifierLogic ));
|
||
}
|
||
}
|
||
}
|
||
|
||
//吸血
|
||
NumericComponent attNum = attacker.GetComponent<NumericComponent>();
|
||
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);
|
||
TargetableUnitComponent attackerTargerComponent = attacker.GetComponent<TargetableUnitComponent>();
|
||
if (attackerTargerComponent.selectedEnermy?.Id == unit.Id)
|
||
{
|
||
attackerTargerComponent.selectedEnermy = null;
|
||
}
|
||
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
attackerModifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位击杀目标时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
||
(
|
||
attacker, attacker, modifierLogic.skillConfigId, modifierLogic
|
||
));
|
||
}
|
||
}
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位死亡时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
|
||
|
||
attacker, unit, modifierLogic.skillConfigId, 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);
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位复活时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
|
||
|
||
attacker, modifierContainer.GetParent<Unit>(), modifierLogic.skillConfigId, modifierLogic));
|
||
}
|
||
}
|
||
|
||
public static void Treat(this BattleComponent self, BallisticData data, ISkillSender skillSender)
|
||
{
|
||
try
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
if (unit.IsAlive && data.value > 0)
|
||
{
|
||
Unit caster = unit.GetComponent<AttackComponent>().attacker;
|
||
NumericComponent num = self.unit.GetComponent<NumericComponent>();
|
||
int value = MathHelper.RoundToInt(data.value);
|
||
|
||
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
||
|
||
if (skillSender != null)
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) =
|
||
modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位受到治疗时);
|
||
if (optionList != null)
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
|
||
|
||
caster, unit, modifierLogic.skillConfigId, 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)
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
CopyBattle battleBase = BattleMgrCompnent.Instance.GetBattle(unit);
|
||
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;
|
||
}
|
||
}
|
||
} |