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

25 lines
850 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)
{
2021-04-18 15:54:51 +08:00
if (!entity) return;
2021-04-11 19:50:39 +08:00
Unit unit = entity.As<Unit>();
2021-04-08 20:09:59 +08:00
if (value <= 0)
{
value = 0;
2021-04-11 19:50:39 +08:00
PlayerData data = unit.GetComponent<PlayerData>();
2021-04-08 20:09:59 +08:00
data.ForbidExp = true;
2021-04-11 19:50:39 +08:00
NumericComponent num = unit.GetComponent<NumericComponent>();
2021-04-08 20:09:59 +08:00
num.Set(NumericType.Energy, value,false);
2021-06-29 11:28:15 +08:00
UnitHelper.SaveComponenet(num);
UnitHelper.SaveComponenet(data);
2021-04-08 20:09:59 +08:00
}
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Energy, value);
await ETTask.CompletedTask;
}
}
}