using Cal.DataTable; using System; using System.Collections.Generic; namespace ET { /// /// 监视Exp /// [NumericWatcher(NumericType.Exp)] public class NumericWatcher_Exp : INumericWatcher { public async ETTask Run(Entity entity, float old, float value) { try { Unit unit = entity.As(); var num = unit.GetComponent(); 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; } } }