2023-11-13 17:23:29 +00:00
|
|
|
using System.Buffers.Binary;
|
|
|
|
using System.Text;
|
2023-11-14 20:11:25 +00:00
|
|
|
using Wonderking.Packets.Outgoing.Data;
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
namespace Wonderking.Packets.Outgoing;
|
|
|
|
|
|
|
|
[PacketId(OperationCode.ChannelSelectionResponse)]
|
|
|
|
public class ChannelSelectionResponsePacket : IPacket
|
|
|
|
{
|
2023-11-13 20:12:12 +00:00
|
|
|
public required byte ChannelIsFullFlag { get; set; }
|
2023-11-13 17:23:29 +00:00
|
|
|
public required string Endpoint { get; set; }
|
|
|
|
public required ushort Port { get; set; }
|
|
|
|
public required CharacterData[] Characters { get; set; }
|
|
|
|
|
|
|
|
public void Deserialize(byte[] data)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public byte[] Serialize()
|
|
|
|
{
|
2023-11-13 21:43:37 +00:00
|
|
|
Span<byte> data = stackalloc byte[1 + 16 + 2 + 1 + 132 * this.Characters.Length];
|
2023-11-13 17:23:29 +00:00
|
|
|
data.Clear();
|
2023-11-13 20:12:12 +00:00
|
|
|
data[0] = this.ChannelIsFullFlag;
|
2023-11-13 17:23:29 +00:00
|
|
|
Encoding.ASCII.GetBytes(this.Endpoint, data.Slice(1, 16));
|
|
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(17, 2), this.Port);
|
2023-11-13 20:12:12 +00:00
|
|
|
data[19] = (byte)this.Characters.Length;
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
// Character Data
|
|
|
|
for (var i = 0; i < Characters.Length; i++)
|
|
|
|
{
|
|
|
|
var character = Characters[i];
|
2023-11-13 21:43:37 +00:00
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(20 + (i * 132), 4), i);
|
2023-11-13 20:12:12 +00:00
|
|
|
Encoding.ASCII.GetBytes(character.Name, data.Slice(24 + (i * 132), 20));
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
// Job Data
|
2023-11-13 20:12:12 +00:00
|
|
|
data[44 + (i * 132)] = character.Job.FirstJob;
|
|
|
|
data[45 + (i * 132)] = character.Job.SecondJob;
|
|
|
|
data[46 + (i * 132)] = character.Job.ThirdJob;
|
|
|
|
data[47 + (i * 132)] = character.Job.FourthJob;
|
2023-11-13 17:23:29 +00:00
|
|
|
|
2023-11-13 20:12:12 +00:00
|
|
|
data[48 + (i * 132)] = (byte)character.Gender;
|
|
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(49 + (i * 132), 2), character.Level);
|
|
|
|
data[51 + (i * 132)] = (byte)character.Experience;
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
// Stats
|
2023-11-13 20:12:12 +00:00
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(52 + (i * 132), 2), character.Stats.Strength);
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(54 + (i * 132), 2), character.Stats.Dexterity);
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(56 + (i * 132), 2), character.Stats.Intelligence);
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(58 + (i * 132), 2), character.Stats.Vitality);
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(60 + (i * 132), 2), character.Stats.Luck);
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(62 + (i * 132), 2), character.Stats.Wisdom);
|
2023-11-13 17:23:29 +00:00
|
|
|
|
2023-11-13 20:12:12 +00:00
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(64 + (i * 132), 4), character.Health);
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(68 + (i * 132), 4), character.Mana);
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
for (var j = 0; j < 20; j++)
|
|
|
|
{
|
|
|
|
// Equipped Items
|
2023-11-13 20:12:12 +00:00
|
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(72 + (i * 132) + (j * 2), 2),
|
|
|
|
character.EquippedItems.Length > j ? character.EquippedItems[j] : (ushort)0);
|
2023-11-13 17:23:29 +00:00
|
|
|
|
|
|
|
// Equipped Cash Items
|
2023-11-13 20:12:12 +00:00
|
|
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(112 + (i * 132) + (j * 2), 2),
|
|
|
|
character.EquippedCashItems.Length > j ? character.EquippedCashItems[j] : (ushort)0);
|
2023-11-13 17:23:29 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-13 21:43:37 +00:00
|
|
|
|
2023-11-13 17:23:29 +00:00
|
|
|
return data.ToArray();
|
|
|
|
}
|
|
|
|
}
|