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
|
|
|
|
|
{
|
2021-04-18 15:54:51 +08:00
|
|
|
|
if (!entity) return;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2021-06-29 11:28:15 +08:00
|
|
|
|
UnitHelper.SaveComponenet(num);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//!通知客户端
|
|
|
|
|
|
|
|
|
|
DelaySendSyncAttributeComponent.instance.Add(unit, NumericType.Exp, value);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"{e}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|