continuity/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs

61 lines
2.4 KiB
C#
Raw Normal View History

2023-11-21 20:37:50 +00:00
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
2023-11-20 18:58:30 +00:00
using System.Buffers.Binary;
using System.Text;
using Rai.PacketMediator;
using Wonderking.Packets.Outgoing.Data;
namespace Wonderking.Packets.Outgoing;
[WonderkingPacketId(OperationCode.CharacterCreationResponse)]
public class CharacterCreationResponsePacket : IOutgoingPacket
{
public required CharacterData Character { get; set; }
2023-11-16 11:49:28 +00:00
public required int Slot { get; set; }
public required bool isDuplicate { get; set; }
public byte[] Serialize()
{
2023-11-16 11:49:28 +00:00
Span<byte> data = stackalloc byte[1 + 132];
data[0] = isDuplicate ? (byte)1 : (byte)0;
// Character Data
2023-11-16 11:49:28 +00:00
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(1, 4), Slot);
Encoding.ASCII.GetBytes(Character.Name, data.Slice(5, 20));
// Job Data
2023-11-16 11:49:28 +00:00
data[25] = Character.Job.FirstJob;
data[26] = Character.Job.SecondJob;
data[27] = Character.Job.ThirdJob;
data[28] = Character.Job.FourthJob;
2023-11-16 11:49:28 +00:00
data[29] = (byte)Character.Gender;
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(30, 2), Character.Level);
data[32] = (byte)Character.Experience;
// Stats
2023-11-16 11:49:28 +00:00
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(33, 2), Character.Stats.Strength);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(35, 2), Character.Stats.Dexterity);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(37, 2), Character.Stats.Intelligence);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(39, 2), Character.Stats.Vitality);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(41, 2), Character.Stats.Luck);
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(43, 2), Character.Stats.Wisdom);
2023-11-16 11:49:28 +00:00
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(45, 4), Character.Health);
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(49, 4), Character.Mana);
for (var i = 0; i < 20; i++)
{
// Equipped Items
2023-11-16 11:49:28 +00:00
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(53 + i * 2, 2),
Character.EquippedItems.Length > i ? Character.EquippedItems[i] : (ushort)0);
// Equipped Cash Items
2023-11-16 11:49:28 +00:00
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(93 + i * 2, 2),
Character.EquippedCashItems.Length > i ? Character.EquippedCashItems[i] : (ushort)0);
}
return data.ToArray();
}
}