Timothy Schenk
46649adfd8
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 23s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 32s
Build, Package and Push Images / container-build (push) Successful in 3m16s
Build, Package and Push Images / container-sbom-scan (push) Successful in 32s
requires base stats and parsing of values provided by user
58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
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];
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(0 + 132, 4), 0);
|
|
Encoding.ASCII.GetBytes(Character.Name, data.Slice(4 + 132, 20));
|
|
|
|
// Job Data
|
|
data[24 + 132] = Character.Job.FirstJob;
|
|
data[25 + 132] = Character.Job.SecondJob;
|
|
data[26 + 132] = Character.Job.ThirdJob;
|
|
data[27 + 132] = Character.Job.FourthJob;
|
|
|
|
data[28 + 132] = (byte)Character.Gender;
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(49 + 132, 2), Character.Level);
|
|
data[31 + 132] = (byte)Character.Experience;
|
|
|
|
// Stats
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(32 + 132, 2), Character.Stats.Strength);
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(34 + 132, 2), Character.Stats.Dexterity);
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(36 + 132, 2), Character.Stats.Intelligence);
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(38 + 132, 2), Character.Stats.Vitality);
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(40 + 132, 2), Character.Stats.Luck);
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(42 + 132, 2), Character.Stats.Wisdom);
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(44 + 132, 4), Character.Health);
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(48 + 132, 4), Character.Mana);
|
|
|
|
for (var i = 0; i < 20; i++)
|
|
{
|
|
// Equipped Items
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(52 + 132 + i * 2, 2),
|
|
Character.EquippedItems.Length > i ? Character.EquippedItems[i] : (ushort)0);
|
|
|
|
// Equipped Cash Items
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(92 + 132 + i * 2, 2),
|
|
Character.EquippedCashItems.Length > i ? Character.EquippedCashItems[i] : (ushort)0);
|
|
}
|
|
|
|
return data.ToArray();
|
|
}
|
|
}
|