forked from PGR/ascnet
1
0
Fork 0

equip command + put on

This commit is contained in:
rfi 2023-12-03 21:44:33 +07:00
parent e5aa565eb2
commit f3468a908a
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,54 @@
using AscNet.Common.Util;
using AscNet.Common;
using AscNet.Table.V2.share.equip;
using AscNet.Common.MsgPack;
namespace AscNet.GameServer.Commands
{
[CommandName("equip")]
internal class EquipCommand : Command
{
public EquipCommand(Session session, string[] args, bool validate = true) : base(session, args, validate)
{
}
public override string Help => "Command to interact with your equips";
[Argument(0, @"^add$", "The operation selected (add)", ArgumentFlags.IgnoreCase)]
string Op { get; set; } = string.Empty;
[Argument(1, @"^[0-9]+$|^all$", "The target character, value is character id or 'all'")]
string Target { get; set; } = string.Empty;
public override void Execute()
{
NotifyEquipDataList notifyEquipData = new();
switch (Op)
{
case "add":
if (Target == "all")
{
foreach (var equip in TableReaderV2.Parse<EquipTable>())
{
var newEquip = session.character.AddEquip((uint)equip.Id);
if (newEquip is not null)
notifyEquipData.EquipDataList.Add(newEquip);
}
}
else
{
var equip = TableReaderV2.Parse<EquipTable>().Find(x => x.Id == Miscs.ParseIntOr(Target)) ?? throw new ServerCodeException("Equip by id not found", 20021001);
var newEquip = session.character.AddEquip((uint)equip.Id);
if (newEquip is not null)
notifyEquipData.EquipDataList.Add(newEquip);
}
break;
default:
throw new InvalidOperationException("Invalid operation!");
}
session.SendPush(notifyEquipData);
}
}
}

View File

@ -22,6 +22,20 @@ namespace AscNet.GameServer.Handlers
public int Code;
}
[MessagePackObject(true)]
public class EquipPutOnRequest
{
public int CharacterId;
public int EquipId;
public int Site;
}
[MessagePackObject(true)]
public class EquipPutOnResponse
{
public int Code;
}
[MessagePackObject(true)]
public class EquipLevelUpRequest
{
@ -102,5 +116,32 @@ namespace AscNet.GameServer.Handlers
session.SendResponse(response, packet.Id);
}
[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);
}
}
}