You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.9 KiB
173 lines
6.9 KiB
using Game;
|
|
using ProtoCSStruct;
|
|
using Sog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Google.Protobuf.WellKnownTypes.Field.Types;
|
|
|
|
namespace Game
|
|
{
|
|
public class LevelHandler : BasePacketHandler
|
|
{
|
|
public override void Dispose()
|
|
{
|
|
|
|
}
|
|
|
|
public override int GetServiceType()
|
|
{
|
|
return GameServiceType.LevelHandler;
|
|
}
|
|
|
|
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
|
|
{
|
|
|
|
PlayerOnGame player = playerSession.Player;
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("LevelHandler.HandlerClientPacket can not find PlayerOnGame sessionid {0}", playerSession.SessionID);
|
|
return;
|
|
}
|
|
switch (packet.MsgID)
|
|
{
|
|
|
|
case (int)CSGameMsgID.PeaklevelAddpoint:
|
|
PeaklevelAddpoint(player, packet);
|
|
break;
|
|
case (int)CSGameMsgID.PeaklevelResetpoint:
|
|
PeaklevelResetpoint(player, packet);
|
|
break;
|
|
case (int)CSGameMsgID.BuyPowerReq:
|
|
PlayerDataSvc.OnBuyPower(player);
|
|
break;
|
|
default:
|
|
TraceLog.Error("LevelHandler.HandlerClientPacket playerUID {0} , message is a invalid id {1} "
|
|
, playerSession.UserID, packet.MsgID);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void HandlerServerPacket(uint serverID, StructPacket packet)
|
|
{
|
|
|
|
}
|
|
|
|
private static void PeaklevelAddpoint(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSPeakLevelAddPoint>();
|
|
var res = new CSPeakLevelAddPointRes();
|
|
res.Points.CopyFrom(ref req.Points);
|
|
res.Ret = CSErrCode.None;
|
|
var needPoint = 0;
|
|
for (int ii = 0; ii < req.Points.Count; ii++)
|
|
{
|
|
int keyId = req.Points[ii].Id;
|
|
int point = req.Points[ii].Value;
|
|
needPoint += point;
|
|
|
|
var desc = PeakLevelDescMgr.Instance.GetConfig(keyId);
|
|
bool find = false;
|
|
for (var i = 0; i < player.RoleData.Knight.DbHero.LevelData.AddPoint.Count; i++)
|
|
{
|
|
if (player.RoleData.Knight.DbHero.LevelData.AddPoint[i].Id == keyId)
|
|
{
|
|
ref var p = ref player.RoleData.Knight.DbHero.LevelData.AddPoint[i];
|
|
if (desc.pointLimit > 0 && p.Value + point > desc.pointLimit)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!find)
|
|
{
|
|
if (desc.pointLimit > 0 && point > desc.pointLimit)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if(needPoint > player.RoleData.Knight.DbHero.LevelData.FreePoint)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
for (int ii = 0; ii < req.Points.Count; ii++)
|
|
{
|
|
int keyId = req.Points[ii].Id;
|
|
int point = req.Points[ii].Value;
|
|
|
|
var desc = PeakLevelDescMgr.Instance.GetConfig(keyId);
|
|
if (desc == null || point > player.RoleData.Knight.DbHero.LevelData.FreePoint)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
player.RoleData.Knight.DbHero.LevelData.FreePoint -= point;
|
|
bool find = false;
|
|
for (var i = 0; i < player.RoleData.Knight.DbHero.LevelData.AddPoint.Count; i++)
|
|
{
|
|
if (player.RoleData.Knight.DbHero.LevelData.AddPoint[i].Id == keyId)
|
|
{
|
|
ref var p = ref player.RoleData.Knight.DbHero.LevelData.AddPoint[i];
|
|
if (desc.pointLimit > 0 && p.Value + point > desc.pointLimit)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
p.Value += point;
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!find)
|
|
{
|
|
if (desc.pointLimit > 0 && point > desc.pointLimit)
|
|
{
|
|
res.Ret = CSErrCode.Fail;
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
return;
|
|
}
|
|
IDValue32 id = new IDValue32();
|
|
id.Id = keyId;
|
|
id.Value = point;
|
|
player.RoleData.Knight.DbHero.LevelData.AddPoint.Add(ref id);
|
|
}
|
|
|
|
}
|
|
|
|
res.Data.CopyFrom(ref player.RoleData.Knight.DbHero.LevelData);
|
|
player.MakeDirty();
|
|
RolePropUtil.RecalRoleProp(player);
|
|
PlayerDataSvc.SendHeroInfoSync(player);
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelAddpointRes, ref res);
|
|
}
|
|
|
|
private static void PeaklevelResetpoint(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSPeakLevelResetPoint>();
|
|
var res = new CSPeakLevelResetPointRes();
|
|
for (var i = 0; i < player.RoleData.Knight.DbHero.LevelData.AddPoint.Count; i++)
|
|
{
|
|
ref var p = ref player.RoleData.Knight.DbHero.LevelData.AddPoint[i];
|
|
player.RoleData.Knight.DbHero.LevelData.FreePoint += (int)p.Value;
|
|
}
|
|
player.RoleData.Knight.DbHero.LevelData.AddPoint.Clear();
|
|
res.Data.CopyFrom(ref player.RoleData.Knight.DbHero.LevelData);
|
|
RolePropUtil.RecalRoleProp(player);
|
|
PlayerDataSvc.SendHeroInfoSync(player);
|
|
player.SendToClient((int)CSGameMsgID.PeaklevelResetpointRes, ref res);
|
|
}
|
|
}
|
|
}
|
|
|