///Summary////////////////////////////////////////////////////////////////////////////
///This Script was created by Nacrom Sable////////////////////////////////////////////
///AKA Torin, Shard Owner of Mystial Illusion/////////////////////////////////////////
///Thank you goes out to Xanthos whos Jail System i butchered to help me with this ///
///and thanks also go out to Joeku for help with crash bugs///////////////////////////
///and to Lucid for hleping with other minor bugs/////////////////////////////////////
///End of Summary/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Text;
using Server;
using Server.Items;
using Server.Mobiles;
using System.Collections;
using Server.Gumps;
using Server.Network;

namespace Server.Items
{
	public class ItemBankTile : Item
	{
		[Constructable]
		public ItemBankTile()
			: base(0x51F)
		{
			Visible = true;
			Movable = false;
			Hue = 1487;
			Name = "Poslat vsechny veci do banky";
		}
		
		public override bool OnMoveOver(Mobile from)
		{
			if ( from is PlayerMobile )
			{
				if ( from.AccessLevel > AccessLevel.Player )
					return true;
					
				from.CloseGump( typeof( InternalConfirmGump ) );
            from.SendGump( new InternalConfirmGump( (Item) this ) );
            from.SendMessage( "Opravdu chces poslat veci do banky?" );

				return base.OnMoveOver(from);
			}
			else
				return false;
		}
		
		private class InternalConfirmGump : BaseConfirmGump
		{
			public override int TitleNumber{ get{ return 1075083; } } // <center>Warning!</center>
			public override int LabelNumber{ get{ return 1074975; } } // Are you sure you wish to select this?
			
			private Item m_Item;
			
			public InternalConfirmGump( Item item ) : base()
			{
				m_Item = item;
			}
			
			public override void Confirm( Mobile from )
			{
				if ( m_Item == null || m_Item.Deleted || from == null )
					return;
				
				PlayerMobile player = from as PlayerMobile;

				if ( player.Backpack == null || player.BankBox == null )
					return;
				
				if ( player.Mounted ) //if player is mounted
				{
					player.SendMessage( "Nesmis sedet na zvireti!" );
					return;
				}
				else if ( !player.InRange( m_Item.GetWorldLocation(), 2 ) || !player.InLOS( m_Item ) )
				{
					player.SendLocalizedMessage(500446); // That is too far away.
					return;
				}

				// Move all items to a bag and move that to the bank
				Container backpack = player.Backpack;
				Backpack bag = new Backpack();
				bag.Hue = 1198;

				ArrayList equipedItems = new ArrayList(player.Items);

				foreach (Item item in equipedItems)
				{
					if ( item.Layer == Layer.Invalid || item.Layer == Layer.Hair || item.Layer == Layer.Unused_xF || item.Layer == Layer.FacialHair || item.Layer == Layer.Backpack
					    || item.Layer == Layer.ShopBuy || item.Layer == Layer.ShopResale || item.Layer == Layer.ShopSell || item.Layer == Layer.Bank || item.Layer == Layer.LastValid || item is DeathShroud )
						continue;

					bag.DropItem(item);
				}

				ArrayList backpackItems = new ArrayList( backpack.Items );
				
				foreach ( Item item in backpackItems )
				{
					if ( item.Movable )
					{
						if ( item is Marker1 || item is Marker2 || item is Marker3 || item is AniLargeVioletFlask || item is QuestHolder )
							continue;
						else
							bag.DropItem(item);
					}
				}

				// Bank the bag of belongings
				if ( bag.Items.Count > 0 )
				{
					player.BankBox.DropItem(bag);
					player.SendMessage( "Tve veci byly umisteny do banky." );
               player.FixedParticles( 0x376A, 9, 32, 5007, EffectLayer.Waist );
               player.PlaySound( 569 );
               player.PlaySound( 88 );
				}
				else
					bag.Delete();
			}
		}

		/*public static void StablePet(PlayerMobile player, BaseCreature pet)
        {
            if (null == player || null == pet)
                return;

            pet.Internalize();
            pet.ControlTarget = null;
            pet.ControlOrder = OrderType.Stay;
            pet.SetControlMaster(null);
            pet.SummonMaster = null;
            pet.IsStabled = true;
            player.Stabled.Add(pet);
            player.SendMessage("Your pet has been stabled");
        }*/

		public ItemBankTile(Serial serial) : base(serial)
		{
		}

		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize(reader);

			int version = reader.ReadInt();
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}
	}
}
