/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\misc\staff\advancedcleanupstone.cs
Lines of code: 88
***********************************************************/


using System;
using Server.Items;
using System.Collections;
using Server.Mobiles;
using Server.Targeting;

namespace Server.Items
{
	public class advcleanupstone : Item
	{
		
		
	
		public override string DefaultName
		{
			get { return "Advanced Cleanup Stone"; }
		}

		[Constructable]
		public advcleanupstone() : base( 0xED4 )
		{
			Movable = false;
			Hue = 256;
		}	
		

		public override void OnDoubleClick( Mobile from )
		{	
		if(from.AccessLevel<AccessLevel.Owner)
		{
		from.SendMessage("Only owner can invoke this");
		return;
		}
		
		
		from.Target = new InternalTarget( from );

		}
		
		
		

		public class InternalTarget : Target
		{
		

			public InternalTarget(Mobile mob) : base( 12, false, TargetFlags.None )
			{
			mob.SendMessage("Select an item with matching properties to global delete\n(checks type, hue, itemid, loottype, name and visibility.)\nThis operation may take a while.");
			}

			protected override void OnTarget( Mobile from, object o )
			{
					if(from.AccessLevel<AccessLevel.Owner)
					{
					from.SendMessage("Only owner can invoke this");
					return;
					}
			
			
			Map map = from.Map;
			
			
				if ( o is Item )
				{
				Item todelete = o as Item;
			
				Type t = todelete.GetType();
				
				if(t==null || todelete==null)return;
			
					int count=0;
					int countmod=0;
					
					ArrayList items = new ArrayList();
					
					foreach ( Item i in World.Items.Values )
					{
					
					Type t2 = i.GetType();
					
					//null checks (should never hit, but w/e better safe than sorry
					if(t2==null || i==null)continue;

					
						//delete if all properties match
						if(t==t2 && i.Hue==todelete.Hue && i.ItemID==todelete.ItemID && i.LootType==todelete.LootType && i.Name==todelete.Name && i.Visible==todelete.Visible)
						{
						items.Add(i);
						countmod++;
						}
						count++;
					}
					
					for(int i=0;i<items.Count;i++)
					{
					Item del = items[i] as Item;
					del.Delete();	
					}					
					

				
				from.SendMessage("{0} Objects out of {1} of that type have been deleted.",countmod,count);
				}
				
			}

			protected override void OnTargetFinish( Mobile from )
			{
				
			}
		}		
		
		
		
		

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 ); // version			
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
		}
	}
}