75 lines
3.0 KiB
C#
Executable File
75 lines
3.0 KiB
C#
Executable File
using Cal;
|
||
using System;
|
||
|
||
namespace ET
|
||
{
|
||
/// <summary>
|
||
/// 监视hp数值变化,改变血条值
|
||
/// </summary>
|
||
[NumericWatcher(NumericType.Hp)]
|
||
public class NumericWatcher_Hp : INumericWatcher
|
||
{
|
||
public async ETTask Run(Entity entity, float old, float value)
|
||
{
|
||
try
|
||
{
|
||
if (!entity) return;
|
||
Unit unit = entity.As<Unit>();
|
||
NumericComponent num = unit.GetComponent<NumericComponent>();
|
||
int maxHp = num.GetAsInt(NumericType.MaxHp);
|
||
if (value <= 0)
|
||
{
|
||
value = 0;
|
||
}
|
||
else
|
||
{
|
||
if (value > maxHp)
|
||
{
|
||
num.Set(NumericType.Hp, maxHp, false);
|
||
value = maxHp;
|
||
}
|
||
}
|
||
float times = CharacterHelper.GetCharacterPoint((float)old / maxHp, (float)value / maxHp, 0.1f);
|
||
if (MathF.Abs(times) > 1)
|
||
{
|
||
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
||
if (modifierContainer != null)
|
||
{
|
||
(SkillOptionBase[] optionList, ModifierLogic modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位生命值变化时);
|
||
if (optionList != null)
|
||
{
|
||
foreach (SkillOptionBase item in optionList)
|
||
{
|
||
SkillOptionLogicBase skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
||
modifierLogic.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
||
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
||
{
|
||
caster = modifierLogic.skillLogic.owner,
|
||
target = unit,
|
||
skillLogic = modifierLogic.skillLogic,
|
||
modifierLogic = modifierLogic,
|
||
});
|
||
}
|
||
SkillLogic skillLogic = modifierLogic.skillLogic;
|
||
(skillLogic.dataOldX10000, skillLogic.dataX10000) = (skillLogic.dataX10000, skillLogic.dataOldX10000);
|
||
}
|
||
|
||
}
|
||
}
|
||
if (unit.UnitType == UnitType.Monster)
|
||
{
|
||
BattleMgrCompnent.Instance.NotifyUnitHurt(unit, MathHelper.RoundToInt(value)).Coroutine();
|
||
}
|
||
|
||
|
||
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Hp, value);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
Log.Error(e);
|
||
}
|
||
await ETTask.CompletedTask;
|
||
}
|
||
}
|
||
}
|