﻿#region

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using wServer.cliPackets;
using wServer.svrPackets;

#endregion

namespace wServer.realm.entities.player
{
    partial class Player
    {
        bool SelectedItems;
        string Killer;
        public void SelectItems(string killer, RealmTime time, RequestTradePacket pkt)
        {
            trade = new bool[12];
            tradeAccepted = false;
            Killer = killer;
            var selected = new TradeItem[Inventory.Length];
            var my = new TradeItem[Inventory.Length];
            for (var i = 0; i < Inventory.Length; i++)
                my[i] = new TradeItem
                {
                    Item = Inventory[i] == null ? -1 : Inventory[i].ObjectType,
                    SlotType = SlotTypes[i],
                    Included = false,
                    Tradeable = (Inventory[i] != null)
                };
            var your = new TradeItem[Inventory.Length];
            for (var i = 0; i < Inventory.Length; i++)
                your[i] = new TradeItem
                {
                    Item = -1,
                    SlotType = SlotTypes[i],
                    Included = false,
                    Tradeable = false
                };
            psr.SendPacket(new TradeStartPacket
            {
                MyItems = my,
                YourName = "Select Items",
                YourItems = your
            });
        }

        private void CheckSelected(RealmTime time)
        {
            if (trade != null)
                        if (tradeAccepted)
                            if (Owner != null)
                            {
                                var ItemsChosen = new List<Item>();
                                for (var i = 0; i < trade.Length; i++)
                                if (trade[i])
                                {
                                    if (tradeTarget.Inventory[i] != null)
                                    {
                                        ItemsChosen.Add(Inventory[i]);
                                    }
                                }
                                if (3 <= ItemsChosen.Count)
                                {
                                    GenerateGravestone(ItemsChosen);
                                    SelectedItems = true;
                                    FinishDeath(Killer);
                                }
                                else
                                {
                                    this.Client.SendPacket(new TextBoxPacket()
                                    {
                                        Title = "Sorry",
                                        Message = "You may only select 3 items",
                                        Button1 = "Ok"
                                    });
                                    tradeAccepted = false;
                                }
                            }
                            else
                            {
                                trade = null;
                                tradeAccepted = false;
                                return;
                            }

        }
        
        
    }
}