2021-04-08 20:09:59 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-04-18 15:54:51 +08:00
|
|
|
|
if (!entity) return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = entity.As<Unit>();
|
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
ModifierContainerComponent modifierContainer = unit.GetComponent<ModifierContainerComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (modifierContainer != 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
|
|
|
|
modifierLogic.skillLogic.skillOptionLogics.Add(skillOptionLogicBase);
|
|
|
|
|
skillOptionLogicBase.HandleEvent(new ModifierSkillSender
|
|
|
|
|
{
|
|
|
|
|
caster = modifierLogic.skillLogic.owner,
|
|
|
|
|
target = unit,
|
|
|
|
|
skillLogic = modifierLogic.skillLogic,
|
|
|
|
|
modifierLogic = modifierLogic,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SkillLogic skillLogic = modifierLogic.skillLogic;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
(skillLogic.dataOldX10000, skillLogic.dataX10000) = (skillLogic.dataX10000, skillLogic.dataOldX10000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-01 11:27:41 +08:00
|
|
|
|
if (unit.UnitType == UnitType.Monster)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-05-01 11:27:41 +08:00
|
|
|
|
BattleMgrCompnent.Instance.NotifyUnitHurt(unit, MathHelper.RoundToInt(value)).Coroutine();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Hp, value);
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|