74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
|
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
|
|||
|
{
|
|||
|
var unit = entity.As<Unit>();
|
|||
|
var 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)
|
|||
|
{
|
|||
|
var modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
|||
|
if (modifierContainer != null)
|
|||
|
{
|
|||
|
var (optionList, modifierLogic) = modifierContainer.GetSkillOptionBaseArr(ModifierEventCondition.当拥有modifier的单位生命值变化时);
|
|||
|
if (optionList != null)
|
|||
|
{
|
|||
|
foreach (var item in optionList)
|
|||
|
{
|
|||
|
var skillOptionLogicBase = SkillOptionFactory.AcquireSkillOptionLogic(item);
|
|||
|
modifierLogic.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|||
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|||
|
{
|
|||
|
caster = modifierLogic.skillLogic.owner,
|
|||
|
target = unit,
|
|||
|
skillLogic = modifierLogic.skillLogic,
|
|||
|
modifierLogic = modifierLogic,
|
|||
|
});
|
|||
|
}
|
|||
|
var skillLogic = modifierLogic.skillLogic;
|
|||
|
(skillLogic.dataOldX10000, skillLogic.dataX10000) = (skillLogic.dataX10000, skillLogic.dataOldX10000);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
if (unit.UnitType == UnitType.FamilyBossMonster)
|
|||
|
{
|
|||
|
BattleMgrCompnent.Instance.NotifyUnitHurt(unit,MathHelper.RoundToInt(value));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Hp, value);
|
|||
|
}
|
|||
|
catch (System.Exception e)
|
|||
|
{
|
|||
|
Log.Error(e);
|
|||
|
}
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|