continuity/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs

59 lines
2.2 KiB
C#
Raw Normal View History

using System.Buffers.Binary;
using System.Text;
using Wonderking.Packets.Outgoing.Data;
namespace Wonderking.Packets.Outgoing;
[PacketId(OperationCode.CharacterCreationResponse)]
public class CharacterCreationResponsePacket : IPacket
{
public required CharacterData Character { get; set; }
public void Deserialize(byte[] data)
{
throw new NotSupportedException();
}
public byte[] Serialize()
{
Span<byte> data = stackalloc byte[132];
2023-11-16 11:22:18 +00:00
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(0, 4), 0);
Encoding.ASCII.GetBytes(Character.Name, data.Slice(4, 20));
// Job Data
2023-11-16 11:22:18 +00:00
data[24] = Character.Job.FirstJob;
data[25] = Character.Job.SecondJob;
data[26] = Character.Job.ThirdJob;
data[27] = Character.Job.FourthJob;
2023-11-16 11:22:18 +00:00
data[28] = (byte)Character.Gender;
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(49, 2), Character.Level);
data[31] = (byte)Character.Experience;
// Stats
2023-11-16 11:22:18 +00:00
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(32, 2), Character.Stats.Strength);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(34, 2), Character.Stats.Dexterity);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(36, 2), Character.Stats.Intelligence);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(38, 2), Character.Stats.Vitality);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(40, 2), Character.Stats.Luck);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(42, 2), Character.Stats.Wisdom);
2023-11-16 11:22:18 +00:00
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(44, 4), Character.Health);
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(48, 4), Character.Mana);
for (var i = 0; i < 20; i++)
{
// Equipped Items
2023-11-16 11:22:18 +00:00
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(52 + i * 2, 2),
Character.EquippedItems.Length > i ? Character.EquippedItems[i] : (ushort)0);
// Equipped Cash Items
2023-11-16 11:22:18 +00:00
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(92 + i * 2, 2),
Character.EquippedCashItems.Length > i ? Character.EquippedCashItems[i] : (ushort)0);
}
return data.ToArray();
}
}