CTT/Server/Hotfix/Module/Numeric/NumericWatcher_Energy.cs

25 lines
860 B
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
namespace ET
{
[NumericWatcher(NumericType.Energy)]
public class NumericWatcher_Energy : INumericWatcher
{
public async ETTask Run(Entity entity, float old, float value)
{
if (entity == null) return;
var unit = entity.As<Unit>();
if (value <= 0)
{
value = 0;
var data = unit.GetComponent<PlayerData>();
data.ForbidExp = true;
var num = unit.GetComponent<NumericComponent>();
num.Set(NumericType.Energy, value,false);
UnitHelper.SaveComponenet(num).Coroutine();
UnitHelper.SaveComponenet(data).Coroutine();
}
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Energy, value);
await ETTask.CompletedTask;
}
}
}