using FFXIVClassic_Map_Server.actors;
using System;
using System.IO;
using System.Text;

namespace FFXIVClassic_Map_Server.packets.send.actor.events
{
    class SetNoticeEventCondition
    {
        public const ushort OPCODE = 0x016B;
        public const uint PACKET_SIZE = 0x48;

        public static SubPacket BuildPacket(uint playerActorID, uint sourceActorID, EventList.NoticeEventCondition condition)
        {
            byte[] data = new byte[PACKET_SIZE - 0x20];

            using (MemoryStream mem = new MemoryStream(data))
            {
                using (BinaryWriter binWriter = new BinaryWriter(mem))
                {
                    binWriter.Write((Byte)condition.unknown1); //Seen: 0, 1, E
                    binWriter.Write((Byte)condition.unknown2); //Seen: 0, 1
                    binWriter.Write(Encoding.ASCII.GetBytes(condition.conditionName), 0, Encoding.ASCII.GetByteCount(condition.conditionName) >= 0x24 ? 0x24 : Encoding.ASCII.GetByteCount(condition.conditionName));
                }
            }

            return new SubPacket(OPCODE, sourceActorID, playerActorID, data);
        }

    }
}
