PSO2SERVER/Server/Models/PSOPalette.cs
2024-12-10 13:33:57 +08:00

234 lines
6.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using PSO2SERVER.Json;
using PSO2SERVER.Protocol;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static PSO2SERVER.Models.PSOPalette;
namespace PSO2SERVER.Models
{
public class SubPalette
{
[JsonProperty("items")]
[JsonConverter(typeof(FixedListConverter<PalettePA>))]
// Items in the subpalette.
public FixedList<PalettePA> Items { get; set; } = new FixedList<PalettePA>(0x0C);
// 从字节流中读取数据
public void ReadFromStream(PacketReader reader)
{
// 假设 Items 长度固定为 12
for (int i = 0; i < Items.Length; i++)
{
// 读取每个 PalettePA
var palettePA = new PalettePA();
palettePA.ReadFromStream(reader);
Items.Add(palettePA); // 将读取的数据存储到 FixedList 中
}
}
// 写入数据到字节流
public void WriteToStream(PacketWriter writer)
{
// 遍历 FixedList将每个 PalettePA 写入字节流
foreach (var item in Items)
{
item.WriteToStream(writer);
}
}
}
public class PalettePA
{
[JsonProperty("id")]
/// PA ID.
public byte ID { get; set; } = 0;
[JsonProperty("category")]
/// PA category.
public byte Category { get; set; } = 0;
[JsonProperty("unk")]
public byte Unk { get; set; } = 0;
[JsonProperty("level")]
/// PA level.
public byte Level { get; set; } = 0;
public PalettePA()
{
}
public PalettePA(byte id, byte category, byte unk, byte level)
{
ID = id;
Category = category;
Unk = unk;
Level = level;
}
public void ReadFromStream(PacketReader reader)
{
ID = reader.ReadByte();
Category = reader.ReadByte();
Unk = reader.ReadByte();
Level = reader.ReadByte();
}
public void WriteToStream(PacketWriter writer)
{
writer.Write(ID);
writer.Write(Category);
writer.Write(Unk);
writer.Write(Level);
}
}
public class WeaponPalette
{
public ulong Uuid { get; set; }
public uint Unk1 { get; set; }
public PalettePA Unk2 { get; set; }
public PalettePA Unk3 { get; set; }
public PalettePA Unk4 { get; set; }
public uint[] Unk { get; set; } = new uint[3];
public uint PetId { get; set; }
public PalettePA[] Skills { get; set; } = new PalettePA[6];
public WeaponPalette()
{
}
public void ReadFromStream(PacketReader reader)
{
Uuid = reader.ReadUInt64();
Unk1 = reader.ReadUInt32();
Unk2 = new PalettePA();
Unk2.ReadFromStream(reader);
Unk3 = new PalettePA();
Unk3.ReadFromStream(reader);
Unk4 = new PalettePA();
Unk4.ReadFromStream(reader);
for (int i = 0; i < Unk.Length; i++)
{
Unk[i] = reader.ReadUInt32();
}
PetId = reader.ReadUInt32();
for (int i = 0; i < Skills.Length; i++)
{
Skills[i] = new PalettePA();
Skills[i].ReadFromStream(reader);
}
}
public void WriteToStream(PacketWriter writer)
{
writer.Write(Uuid);
writer.Write(Unk1);
Unk2.WriteToStream(writer);
Unk3.WriteToStream(writer);
Unk4.WriteToStream(writer);
foreach (var value in Unk)
{
writer.Write(value);
}
writer.Write(PetId);
foreach (var skill in Skills)
{
skill.WriteToStream(writer);
}
}
}
public class PSOPalette
{
public struct Palette
{
public uint CurPalette;
public uint CurSubpalette;
public uint CurBook;
public WeaponPalette[] Palettes;
public SubPalette[] Subpalettes;
public List<uint> DefaultPas;
// 构造函数
public static Palette Create()
{
Palette palette = new Palette
{
CurPalette = 0,
CurSubpalette = 0,
CurBook = 0,
Palettes = new WeaponPalette[6],
Subpalettes = new SubPalette[6],
DefaultPas = new List<uint>()
};
// 初始化 Palettes
for (int i = 0; i < palette.Palettes.Length; i++)
{
palette.Palettes[i] = new WeaponPalette();
}
// 初始化 Subpalettes根据需要可以进行自定义初始化
for (int i = 0; i < palette.Subpalettes.Length; i++)
{
palette.Subpalettes[i] = new SubPalette(); // 这里可以根据需要进行初始化
}
return palette;
}
public void ReadFromStream(PacketReader reader)
{
CurPalette = reader.ReadUInt32();
CurSubpalette = reader.ReadUInt32();
CurBook = reader.ReadUInt32();
for (int i = 0; i < Palettes.Length; i++)
{
Palettes[i].ReadFromStream(reader);
}
for (int i = 0; i < Subpalettes.Length; i++)
{
Subpalettes[i].ReadFromStream(reader);
}
int defaultPasCount = reader.ReadInt32(); // 假设先读入数量
DefaultPas.Clear();
for (int i = 0; i < defaultPasCount; i++)
{
DefaultPas.Add(reader.ReadUInt32());
}
}
public void WriteToStream(PacketWriter writer)
{
writer.Write(CurPalette);
writer.Write(CurSubpalette);
writer.Write(CurBook);
for (int i = 0; i < Palettes.Length; i++)
{
Palettes[i].WriteToStream(writer);
}
for (int i = 0; i < Subpalettes.Length; i++)
{
Subpalettes[i].WriteToStream(writer);
}
writer.Write(DefaultPas.Count);
foreach (var value in DefaultPas)
{
writer.Write(value);
}
}
}
}
}