forked from PGR/ascnet
1
0
Fork 0

coating implementation

This commit is contained in:
rfi 2024-01-17 11:31:34 +07:00
parent 0e36d06214
commit d94f60c09e
3 changed files with 107 additions and 1 deletions

View File

@ -0,0 +1,63 @@
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
using AscNet.GameServer.Handlers;
using AscNet.Table.V2.share.fashion;
namespace AscNet.GameServer.Commands
{
[CommandName("coating")]
internal class CoatingCommand : Command
{
public CoatingCommand(Session session, string[] args, bool validate = true) : base(session, args, validate) { }
public override string Help => "Command to unlock all coatings of characters.";
[Argument(0, @"^unlock$", "The operation selected (unlock)")]
string Op { get; set; } = string.Empty;
[Argument(1, @"^[0-9]+$|^all$", "The target character, value is character id or 'all' for all owned character")]
string Target { get; set; } = string.Empty;
public override void Execute()
{
int characterId = Miscs.ParseIntOr(Target);
switch (Op)
{
case "unlock":
if (Target == "all")
{
List<FashionList> newFashions = new();
foreach (var fashion in TableReaderV2.Parse<FashionTable>().Where(x => session.character.Characters.Any(y => y.Id == x.CharacterId)))
{
if (session.character.Fashions.Any(x => x.Id == fashion.Id))
continue;
newFashions.Add(new() { Id = fashion.Id });
}
session.SendPush(new FashionSyncNotify() { FashionList = newFashions });
session.character.Fashions.AddRange(newFashions);
}
else
{
List<FashionList> newFashions = new();
foreach (var fashion in TableReaderV2.Parse<FashionTable>().Where(x => x.CharacterId == characterId))
{
if (session.character.Fashions.Any(x => x.Id == fashion.Id))
continue;
newFashions.Add(new() { Id = fashion.Id });
}
session.SendPush(new FashionSyncNotify() { FashionList = newFashions });
session.character.Fashions.AddRange(newFashions);
}
break;
default:
throw new InvalidOperationException("Invalid operation!");
}
}
}
}

View File

@ -0,0 +1,44 @@
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
using AscNet.Table.V2.share.fashion;
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.
[MessagePackObject(true)]
public class FashionUseRequest
{
public uint FashionId { get; set; }
}
[MessagePackObject(true)]
public class FashionUseResponse
{
public int Code { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class FashionModule
{
[RequestPacketHandler("FashionUseRequest")]
public static void HandleFashionUseRequestHandler(Session session, Packet.Request packet)
{
FashionUseRequest req = packet.Deserialize<FashionUseRequest>();
var character = session.character.Characters.Find(x => x.Id == TableReaderV2.Parse<FashionTable>().Find(x => x.Id == req.FashionId)?.CharacterId);
if (character is not null)
{
character.FashionId = req.FashionId;
NotifyCharacterDataList notifyCharacterData = new();
notifyCharacterData.CharacterDataList.Add(character);
session.SendPush(notifyCharacterData);
}
session.SendResponse(new FashionUseResponse(), packet.Id);
}
}
}

View File

@ -2,7 +2,6 @@
using AscNet.GameServer.Handlers;
using AscNet.GameServer.Commands;
using AscNet.Logging;
using Newtonsoft.Json;
namespace AscNet
{