using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FiestaBot.Instances.Networking;
using FiestaBot.Utilities;
using FiestaBot.Zone.Networking;

namespace FiestaBot.Zone.ClientPacket
{
    internal class ZonePacket
    {
        public static void SendSHNHashes(ZoneClient Socket)
        {
            //TODO: calculate SHN hashes
            Packet p = new Packet(6, 1);
            p.WriteUShort(Socket.Manager.ZoneKey);
            p.WriteString(Socket.Manager.Character.Name, 16);
            p.WriteString(Program.Config.SHNHashes, 832);
            Socket.SendPacket(p);
        }

        public static void SendIngame(ZoneClient Socket)
        {
            Packet Ready = new Packet(6, 3); //zone ig
            Packet Ingame = new Packet(22, 27); //wm ig
            Socket.SendPacket(Ready);
            Socket.Manager.SendPacket(Ingame);
        }

        public static void SendRun(ZoneClient Socket, int NewX, int NewY)
        {
            Packet p = new Packet(8, 25);
            p.WriteInt(Socket.Manager.Character.Position.X);
            p.WriteInt(Socket.Manager.Character.Position.Y);
            p.WriteInt(NewX);
            p.WriteInt(NewY);

            Socket.SendPacket(p);

            Socket.Manager.Character.Position.X = NewX;
            Socket.Manager.Character.Position.Y = NewY;
        }

        public static void SendTradeRequest(ZoneClient Socket, string Receiver)
        {
            ushort ObjectID = Socket.ObjectList.Find(x => x.Name == Receiver).ObjectID;

            Packet p = new Packet(19, 1);
            p.WriteUShort(ObjectID);

            Socket.SendPacket(p);
        }

        public static void SendTradeAccept(ZoneClient Socket)
        {
            //TODO
        }

        public static void SendTradeReject(ZoneClient Socket)
        {
            //TODO
        }

        public static void SendTradeMoney(ZoneClient Socket, long Amount)
        {
            //TODO
        }

	/* moved to @assembly://D:\_Visual Studio\Fiesta\ServerCrasher
        public static void SendZoneBreak(ZoneClient Socket)
        {
            while(true)
            {
                Packet p = new Packet(12, 32);

                p.WriteByte(0);

                Socket.SendPacket(p);
            }
        }
	*/
    }
}
