zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Module/Numeric/NumericWatcher_Exp.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using System;
using System.Collections.Generic;
namespace ET
{
/// <summary>
/// 监视Exp
/// </summary>
[NumericWatcher(NumericType.Exp)]
public class NumericWatcher_Exp : INumericWatcher
{
public async ETTask Run(Entity entity, float old, float value)
{
try
{
Unit unit = entity.As<Unit>();
2021-04-11 19:50:39 +08:00
NumericComponent num = unit.GetComponent<NumericComponent>();
2021-04-08 20:09:59 +08:00
int level = num.GetAsInt(NumericType.Level);
int trans = num.GetAsInt(NumericType.Transmigration);
int oldLevel = level;
long needExp = CharacterHelper.GetUpgradeLevelExp(unit);
while (value >= needExp)
{
value -= needExp;
level++;
needExp = CharacterHelper.GetUpgradeLevelExp(trans, level);
if (needExp == -1) break;
}
int transMaxLevel = CharacterHelper.GetTransmigrationLevelByTrans(trans);
if (level >= transMaxLevel)
{
level = transMaxLevel;
num.Set(NumericType.Exp, 0, false);
}
else
num.Set(NumericType.Exp, value, false);
if (level != oldLevel)
{
num.Set(NumericType.Level, level);
}
UnitHelper.SaveComponenet(num).Coroutine();
//!通知客户端
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Exp, value);
}
catch (Exception e)
{
Log.Error($"{e}");
}
await ETTask.CompletedTask;
}
}
}