using System;

using FilterAPI.Networking;

using FilterZone.ZoneNetworking;

namespace FilterZone.ZoneHandlers
{
    internal class Zone15Handle
    {
        [ZonePacketHandler(15, 1)]
        public static void HandleQuestion(ZoneClient ClientSocket, Packet ServerPacket)
        {
            ClientSocket.SendPacketClient(ServerPacket);
            ClientSocket.MP = null;
        }

        [ZonePacketHandler(15, 2)]
        public static void HandleResponse(ZoneClient ClientSocket, Packet ClientPacket)
        {
            if (ClientSocket.MP == null) { ClientSocket.SendPacketServer(ClientPacket); }
            else
            {
                UInt16 ResponseID = UInt16.MaxValue;

                if ((ResponseID = ClientPacket.PacketReader.ReadByte()) != UInt16.MaxValue)
                {
                    switch (ResponseID)
                    {
                        case 0:
                            {
                                Command.Linkto(ClientSocket, ClientSocket.MP.Map1Index, ClientSocket.MP.Map1X, ClientSocket.MP.Map1Y);

                                break;
                            }
                        case 1:
                            {
                                Command.Linkto(ClientSocket, ClientSocket.MP.Map2Index, ClientSocket.MP.Map2X, ClientSocket.MP.Map2Y);

                                break;
                            }
                        case 2:
                            {
                                Command.Linkto(ClientSocket, ClientSocket.MP.Map3Index, ClientSocket.MP.Map3X, ClientSocket.MP.Map3Y);

                                break;
                            }
                    }
                }
            }
        }

        [ZonePacketHandler(15, 8)]
        public static void HandleStorageOpened(ZoneClient ClientSocket, Packet ServerPacket)
        {
            if (!Program.SQL.HasPermission(ClientSocket.nCharNo, "CanStorage"))
            {
                GlobalPacket.SendCloseNPCWindow(ClientSocket);
                GlobalPacket.SendShoutMessageServer(ClientSocket, "Server", "Sorry \"{0}\", you are not allowed to open your storage.", ClientSocket.sID);
            }
            else { ClientSocket.SendPacketClient(ServerPacket); }
        }
    }
}
