CTT/Server/Hotfix/Game/System/Battle/BattleComponentSystem.cs

246 lines
12 KiB
C#
Raw Permalink Normal View History

2021-04-08 20:09:59 +08:00
using Cal;
using System;
namespace ET
{
2023-09-07 00:06:37 +08:00
public class BattleComponentAwakeSystem: AwakeSystem<BattleComponent>
2021-04-08 20:09:59 +08:00
{
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)
{
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(attacker,
unit,
modifierLogic.skillConfigId,
modifierLogic));
2021-04-08 20:09:59 +08:00
}
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
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);
2023-09-07 00:06:37 +08:00
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}");
}
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
if (value <= 0) return;
if (attackComponent.isFirstAtk)
{
{
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
attacker,unit,modifierLogic.skillConfigId,modifierLogic ));
2021-04-08 20:09:59 +08:00
}
}
{
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
attacker,attacker,modifierLogic.skillConfigId,modifierLogic ));
2021-04-08 20:09:59 +08:00
}
}
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
//吸血
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)))
{
2023-09-07 00:06:37 +08:00
int treatValue = (int) (attNum.Get(NumericType.SuckV) * value);
2021-04-08 20:09:59 +08:00
if (treatValue > 0)
{
2023-09-07 00:06:37 +08:00
attacker.GetComponent<AttackComponent>()
?.TreatTarget(attacker, new BallisticData { isCrit = false, value = treatValue }, null);
2021-04-08 20:09:59 +08:00
}
}
if (attacker.UnitType == UnitType.Player)
2023-09-07 00:06:37 +08:00
Game.EventSystem.Publish(new ET.EventType.DamageEvent { attacker = attacker, damage = value }).Coroutine();
2021-04-08 20:09:59 +08:00
bool isDead = num.GetAsInt(NumericType.Hp) <= value;
2023-09-07 00:06:37 +08:00
Game.EventSystem.Publish(new ET.EventType.BattleSkillRet { targetUnit = unit, HpValue = -value, IsCrit = data.isCrit, })
.Coroutine();
2021-04-08 20:09:59 +08:00
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;
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
{
2023-09-07 00:06:37 +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
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
2023-09-07 00:06:37 +08:00
(
attacker, attacker, modifierLogic.skillConfigId, modifierLogic
));
2021-04-08 20:09:59 +08:00
}
}
{
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
attacker, unit, modifierLogic.skillConfigId, modifierLogic));
2021-04-08 20:09:59 +08:00
}
}
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);
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
attacker, modifierContainer.GetParent<Unit>(), modifierLogic.skillConfigId, modifierLogic));
2021-04-08 20:09:59 +08:00
}
}
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
2023-09-07 00:06:37 +08:00
if (skillSender != null)
2021-04-08 20:09:59 +08:00
{
2023-09-07 00:06:37 +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);
2023-09-07 00:06:37 +08:00
skillOptionLogicBase.HandleEvent(new ModifierSkillSender(
caster, unit, modifierLogic.skillConfigId, modifierLogic));
2021-04-08 20:09:59 +08:00
}
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
if (caster.UnitType == UnitType.Player)
2023-09-07 00:06:37 +08:00
Game.EventSystem.Publish(new ET.EventType.TreatEvent { attacker = caster, treat = value }).Coroutine();
2021-04-08 20:09:59 +08:00
num.AddSet(NumericType.Hp, value);
2023-09-07 00:06:37 +08:00
Game.EventSystem.Publish(new ET.EventType.BattleSkillRet { targetUnit = unit, HpValue = value, IsCrit = data.isCrit, })
.Coroutine();
2021-04-08 20:09:59 +08:00
}
}
catch (Exception e)
{
Log.Error(e);
}
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
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)
{
2023-09-07 00:06:37 +08:00
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】 battleBase == null");
2021-04-08 20:09:59 +08:00
return "系统错误";
}
2023-09-07 00:06:37 +08:00
2021-04-08 20:09:59 +08:00
string ret = BattleHelper.SelectFixedTarget(battleBase, unit, unitId, battleBase.targetTeam, teamType);
return ret;
}
}
2023-09-07 00:06:37 +08:00
}