PSO2SERVER/Server/Protocol/Packets/08-SpawnPacket/08-0B-ObjectSpawnPacket.cs

70 lines
2.0 KiB
C#

using Newtonsoft.Json;
using Org.BouncyCastle.Utilities;
using PSO2SERVER.Models;
using PSO2SERVER.Zone;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using static PSO2SERVER.Models.PSOObject;
namespace PSO2SERVER.Protocol.Packets
{
public class ObjectSpawnPacket : Packet
{
public readonly PSOObject _obj;
[JsonProperty("object")]
public ObjectHeader objHeader { get; set; } = new ObjectHeader();
[JsonProperty("position")]
public PSOLocation objPosition { get; set; } = new PSOLocation();
public ushort unk1 { get; set; } = 0;
/// Enemy name.
[JsonProperty("name")]
public string objName { get; set; } = string.Empty;//0x20
public uint[] unk2 { get; set; } = new uint[0x05];
public uint flags { get; set; } = 0;
public List<uint> data { get; set; } = new List<uint>();
public ObjectSpawnPacket(PSOObject obj)
{
objHeader = obj.Header;
objPosition = obj.Position;
objName = obj.Name;
flags = 4;
_obj = obj;
}
public ObjectSpawnPacket()
{
}
#region implemented abstract members of Packet
public override byte[] Build()
{
PacketWriter pkt = new PacketWriter();
pkt.WriteStruct(objHeader);
pkt.WritePosition(objPosition);
pkt.Write(unk1); // Padding?
pkt.WriteFixedLengthASCII(objName, 0x20);
pkt.WriteUintArray(unk2);
pkt.Write(flags);
pkt.Write(_obj.Things.Length);
foreach (PSOObjectThing thing in _obj.Things)
{
pkt.WriteStruct(thing);
}
return pkt.ToArray();
}
public override PacketHeader GetHeader()
{
return new PacketHeader(0x08, 0x0B, PacketFlags.None);
}
#endregion
}
}