using Cal; using System; using System.Collections.Generic; namespace ET { [ActorMessageHandler] public class C2M_AddPointHandler : AMActorLocationRpcHandler { protected override async ETTask Run(Unit unit, C2M_AddPoint request, M2C_AddPoint response, Action reply) { if(TeamComponent.Instance.Get(unit.TeamLeaderId).TeamState == TeamState.Fight) { response.Message = "战斗中..."; reply(); return; } PlayerData data = unit.GetComponent(); int totalCount = 0; foreach (int item in request.PointList) { totalCount += item; } Character num = unit.GetComponent(); //var trans = CharacterHelper.GetTransmigrationByLevel(num.GetAsInt(NumericType.Level)); //if (trans < request.Trans) //{ // Log.Error($"自身转生{trans} < 加点{request.Trans}"); // response.Message = "系统错误"; // reply(); // return; //} KeyValuePair kp = data.CharacterPointKV; int characterPoint = kp.Key; if (characterPoint < totalCount) { response.Message = "加点总数多于属性点,请重新分配!"; reply(); return; } //!力量 智慧 体质 耐力 敏捷 精神 int index = 0; foreach (int count in request.PointList) { AttributeType type = index++ switch { 0 => AttributeType.力量, 1 => AttributeType.智慧, 2 => AttributeType.体质, 3 => AttributeType.耐力, 4 => AttributeType.敏捷, 5 => AttributeType.精神, _ => throw new Exception($"not exist type : {index-1}"), }; CharacterHelper.AddPoint(num, type, count); } characterPoint -= totalCount; data.CharacterPointKV = KeyValuePair.Create(characterPoint, kp.Value); CharacterHelper.SyncNumeric(unit); UnitHelper.SaveComponenet(data).Coroutine(); UnitHelper.SaveComponenet(num).Coroutine(); response.Character =await CharacterHelper.GetUnitCharacter(unit); reply(); await ETTask.CompletedTask; } } }