CTT/Server/Hotfix/Game/Handler/UI/Character/C2M_AddPointHandler.cs

68 lines
2.4 KiB
C#
Executable File

using Cal;
using System;
using System.Collections.Generic;
namespace ET
{
[ActorMessageHandler]
public class C2M_AddPointHandler : AMActorLocationRpcHandler<Unit, C2M_AddPoint, M2C_AddPoint>
{
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<PlayerData>();
int totalCount = 0;
foreach (int item in request.PointList)
{
totalCount += item;
}
Character num = unit.GetComponent<Character>();
//var trans = CharacterHelper.GetTransmigrationByLevel(num.GetAsInt(NumericType.Level));
//if (trans < request.Trans)
//{
// Log.Error($"自身转生{trans} < 加点{request.Trans}");
// response.Message = "系统错误";
// reply();
// return;
//}
KeyValuePair<int, int> 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);
UnitHelper.SaveComponenet(num);
response.Character =await CharacterHelper.GetUnitCharacter(unit);
reply();
await ETTask.CompletedTask;
}
}
}