2024-02-07 15:40:36 +00:00
|
|
|
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
|
2023-11-20 18:58:30 +00:00
|
|
|
|
2023-11-15 19:00:08 +00:00
|
|
|
using System.Buffers.Binary;
|
|
|
|
using System.Text;
|
2024-04-04 14:57:42 +00:00
|
|
|
using RaiNote.PacketMediator;
|
2023-11-15 19:00:08 +00:00
|
|
|
using Wonderking.Packets.Outgoing.Data;
|
|
|
|
|
|
|
|
namespace Wonderking.Packets.Outgoing;
|
|
|
|
|
2024-02-04 18:52:45 +00:00
|
|
|
[WonderkingPacketId(OperationCode.CharacterCreationResponse)]
|
2025-01-16 13:30:40 +00:00
|
|
|
public class CharacterCreationResponsePacket : IOutgoingPacket {
|
2023-11-15 19:00:08 +00:00
|
|
|
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; }
|
2023-11-15 19:00:08 +00:00
|
|
|
|
2025-01-16 13:30:40 +00:00
|
|
|
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;
|
2023-11-17 10:14:42 +00:00
|
|
|
|
|
|
|
// 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));
|
2023-11-15 19:00:08 +00:00
|
|
|
|
|
|
|
// 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-15 19:00:08 +00:00
|
|
|
|
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;
|
2023-11-15 19:00:08 +00:00
|
|
|
|
|
|
|
// 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-15 19:00:08 +00:00
|
|
|
|
2023-11-16 11:49:28 +00:00
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(45, 4), Character.Health);
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(49, 4), Character.Mana);
|
2023-11-15 19:00:08 +00:00
|
|
|
|
2025-01-16 13:30:40 +00:00
|
|
|
for (var i = 0; i < 20; i++) {
|
2023-11-15 19:00:08 +00:00
|
|
|
// Equipped Items
|
2023-11-16 11:49:28 +00:00
|
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(53 + i * 2, 2),
|
2023-11-15 19:00:08 +00:00
|
|
|
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),
|
2023-11-15 19:00:08 +00:00
|
|
|
Character.EquippedCashItems.Length > i ? Character.EquippedCashItems[i] : (ushort)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.ToArray();
|
|
|
|
}
|
|
|
|
}
|