ascnet/AscNet.GameServer/Handlers/EquipModule.cs

148 lines
4.8 KiB
C#
Raw Normal View History

2023-11-29 14:01:00 +00:00
using AscNet.Common;
using AscNet.Common.Database;
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
using AscNet.Table.V2.share.item;
using MessagePack;
namespace AscNet.GameServer.Handlers
{
#region MsgPackScheme
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2023-12-03 10:44:40 +00:00
[MessagePackObject(true)]
public class EquipUpdateLockRequest
{
public int EquipId;
public bool IsLock;
}
[MessagePackObject(true)]
public class EquipUpdateLockResponse
{
public int Code;
}
2023-12-03 14:44:33 +00:00
[MessagePackObject(true)]
public class EquipPutOnRequest
{
public int CharacterId;
public int EquipId;
public int Site;
}
[MessagePackObject(true)]
public class EquipPutOnResponse
{
public int Code;
}
2023-11-29 14:01:00 +00:00
[MessagePackObject(true)]
public class EquipLevelUpRequest
{
public int EquipId;
public Dictionary<int, int> UseItems;
public List<int> UseEquipIdList;
}
[MessagePackObject(true)]
public class EquipLevelUpResponse
{
public int Code;
public int Level;
public int Exp;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class EquipModule
{
[RequestPacketHandler("EquipLevelUpRequest")]
public static void EquipLevelUpRequestHandler(Session session, Packet.Request packet)
{
EquipLevelUpRequest request = packet.Deserialize<EquipLevelUpRequest>();
NotifyItemDataList notifyItemData = new();
int totalExp = 0;
int totalCost = 0;
foreach (var item in request.UseItems)
{
ItemTable? itemTable = TableReaderV2.Parse<ItemTable>().FirstOrDefault(x => x.Id == item.Key);
if (itemTable is not null)
{
var upgradeInfo = itemTable.GetEquipUpgradeInfo() * item.Value;
totalExp += upgradeInfo.Exp;
totalCost += upgradeInfo.Cost;
notifyItemData.ItemDataList.Add(session.inventory.Do(item.Key, item.Value * -1));
}
}
notifyItemData.ItemDataList.Add(session.inventory.Do(Inventory.Coin, totalCost * -1));
session.SendPush(notifyItemData);
EquipLevelUpResponse rsp = new()
{
Code = 0
};
var upEquip = session.character.AddEquipExp(request.EquipId, totalExp);
if (upEquip != null)
{
rsp.Level = upEquip.Level;
rsp.Exp = upEquip.Exp;
NotifyEquipDataList notifyEquipDataList = new();
notifyEquipDataList.EquipDataList.Add(upEquip);
session.SendPush(notifyEquipDataList);
}
session.SendResponse(rsp, packet.Id);
}
2023-12-03 10:44:40 +00:00
[RequestPacketHandler("EquipUpdateLockRequest")]
public static void EquipUpdateLockRequestHandler(Session session, Packet.Request packet)
{
EquipUpdateLockRequest request = packet.Deserialize<EquipUpdateLockRequest>();
var response = new EquipUpdateLockResponse();
var equip = session.character.Equips.Find(x => x.Id == request.EquipId);
if (equip is null)
{
// EquipManagerGetCharEquipBySiteNotFound
response.Code = 20021012;
}
else
{
equip.IsLock = request.IsLock;
}
session.SendResponse(response, packet.Id);
}
2023-12-03 14:44:33 +00:00
[RequestPacketHandler("EquipPutOnRequest")]
public static void EquipPutOnRequestHandler(Session session, Packet.Request packet)
{
EquipPutOnRequest request = packet.Deserialize<EquipPutOnRequest>();
var prevEquip = session.character.Equips.Find(x => x.CharacterId == request.CharacterId);
var toEquip = session.character.Equips.Find(x => x.Id == request.EquipId);
if (prevEquip is not null && toEquip is not null)
{
prevEquip.CharacterId = 0;
toEquip.CharacterId = request.CharacterId;
}
else
{
// EquipManagerGetCharEquipBySiteNotFound
session.SendResponse(new EquipPutOnResponse() { Code = 20021012 }, packet.Id);
return;
}
NotifyEquipDataList notifyEquipData = new()
{
EquipDataList = { prevEquip, toEquip }
};
session.SendPush(notifyEquipData);
session.SendResponse(new EquipPutOnResponse(), packet.Id);
}
2023-11-29 14:01:00 +00:00
}
}