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

68 lines
2.5 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
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;
}
2021-04-11 19:50:39 +08:00
PlayerData data = unit.GetComponent<PlayerData>();
2021-04-08 20:09:59 +08:00
int totalCount = 0;
2021-04-11 19:50:39 +08:00
foreach (int item in request.PointList)
2021-04-08 20:09:59 +08:00
{
totalCount += item;
}
2021-04-11 19:50:39 +08:00
Character num = unit.GetComponent<Character>();
2021-04-08 20:09:59 +08:00
//var trans = CharacterHelper.GetTransmigrationByLevel(num.GetAsInt(NumericType.Level));
//if (trans < request.Trans)
//{
// Log.Error($"自身转生{trans} < 加点{request.Trans}");
// response.Message = "系统错误";
// reply();
// return;
//}
2021-04-11 19:50:39 +08:00
KeyValuePair<int, int> kp = data.CharacterPointKV;
int characterPoint = kp.Key;
2021-04-08 20:09:59 +08:00
if (characterPoint < totalCount)
{
response.Message = "加点总数多于属性点,请重新分配!";
reply();
return;
}
//!力量 智慧 体质 耐力 敏捷 精神
int index = 0;
2021-04-11 19:50:39 +08:00
foreach (int count in request.PointList)
2021-04-08 20:09:59 +08:00
{
AttributeType type = index++
switch
{
0 => AttributeType.,
1 => AttributeType.,
2 => AttributeType.,
3 => AttributeType.,
4 => AttributeType.,
5 => AttributeType.,
2021-04-11 19:50:39 +08:00
_ => throw new Exception($"not exist type : {index-1}"),
2021-04-08 20:09:59 +08:00
};
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;
}
}
}