using PSO2SERVER.Models;
using PSO2SERVER.Zone;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static PSO2SERVER.Zone.Map;

namespace PSO2SERVER.Protocol.Packets
{
    public class MapTransferPacket : Packet
    {
        public ObjectHeader Map { get; set; }
        public ObjectHeader target { get; set; }
        public ZoneSettings settings { get; set; }

        public MapTransferPacket(Map map, int PlayerId)
        {
            Map = new ObjectHeader((uint)map.MapID, ObjectType.Map);
            target = new ObjectHeader((uint)PlayerId, ObjectType.Player);
            settings = new ZoneSettings
            {
                WorldId = 1,
                Unk1 = 0,
                ZoneId = ~(uint)map.Type,
                MapId = (uint)map.MapID,
                ZoneType = (uint)map.Flags,
                Seed = map.GenerationArgs.seed,
                Args = (uint)map.VariantID,
                SizeX = map.GenerationArgs.xsize,
                SizeY = map.GenerationArgs.ysize,
                Unk2 = 1,
                AreaIndex = 1,
                SubArea = 0xFFFFFFFF,
                Unk3 = 0x301,
            };
        }

        #region implemented abstract members of Packet

        public override byte[] Build()
        {
            PacketWriter pkt = new PacketWriter();
            pkt.WriteStruct(Map);
            pkt.WriteStruct(target);
            pkt.WriteStruct(settings);
            return pkt.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x03, 0x00, PacketFlags.None);
        }

        #endregion
    }
}