PSO2SERVER/Server/Protocol/Packets/11-ClientPacket/11-03-CharacterListPacket.cs

86 lines
2.8 KiB
C#

using PSO2SERVER.Database;
using PSO2SERVER.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Contexts;
using System.Text;
namespace PSO2SERVER.Protocol.Packets
{
public class CharacterListPacket : Packet
{
// Ninji note: This packet may be followed by extra data,
// after a fixed-length array of character data structures.
// Needs more investigation at some point.
// ---
// CK note: Extra data is likely current equipment, playtime, etc.
// All of that data is currently unaccounted for at the moment.
//忍者注意:这个包后面可能有额外的数据,
//在固定长度的字符数据结构数组之后。
//需要更多的调查。
// ---
// CK注:额外的数据可能是当前设备,游戏时间等。
//所有这些数据目前都是未知的。
private int AccountId;
public CharacterListPacket(int AccountId)
{
this.AccountId = AccountId;
}
#region implemented abstract members of Packet
public override byte[] Build()
{
var writer = new PacketWriter();
using (var db = new ServerEf())
{
var chars = db.Characters
.Where(w => w.Account.AccountId == AccountId)
.OrderBy(o => o.CharacterID) // TODO: 按照最后游玩的角色排序
.Select(s => s);
writer.Write((uint)chars.Count()); // 写入玩家数量
writer.Write((uint)AccountId);
foreach (var ch in chars)
{
writer.Write((uint)ch.AccountID);//4
writer.Write((uint)ch.CharacterID);//4
writer.Write(ch.Unk1);//4
writer.Write(ch.VoiceType);//4
writer.Write(ch.Unk2);//2
writer.Write(ch.VoicePitch);//2
writer.Write((uint)0);//4
writer.WriteFixedLengthUtf16(ch.Name, 16);
//Logger.WriteInternal("[CHR] 新增名为 {0} 的新角色.", ch.Name);
writer.Write((uint)0); // 修改这个值 可能会触发角色不可用或变为联动角色
writer.WriteStruct(ch.Looks);
writer.WriteStruct(ch.Jobs);
writer.WriteFixedLengthUtf16(ch.NickName, 16);
for (var i = 0; i < 116; i++)
writer.Write((byte)0);
}
}
return writer.ToArray();
}
public override PacketHeader GetHeader()
{
return new PacketHeader(0x11, 0x03, PacketFlags.None);
}
#endregion
}
}