/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jul-26-2011 09:17:43pm
Filepath: scripts\_custom\items\misc\testserveronly\TcItemStone.cs
Lines of code: 383

Description: 

***********************************************************/


using System;
using Server;
using Server.Items;
using Server.Gumps;
using Server.Commands;
using Server.Commands.Generic;
using System.Net;
using System.Net.Sockets;
using Server.Network;
using System.Collections;
using System.Collections.Generic;



namespace Server.Items
{
	public class TcItemStone : Item
	{
		private int m_defaultamount;
		
		
		[CommandProperty( AccessLevel.Seer )]
		public int DefaultAmount
		{
			get {return m_defaultamount;}
			set	{m_defaultamount=value; Modify();}
		}
		
		public override string DefaultName
		{
			get { return "Item Stone"; }
		}

		[Constructable]
		public TcItemStone() : base( 0xED4 )
		{
			Movable = false;
			Hue = 1285;
			Weight=0;
			DefaultAmount=10;
		}

		public override void OnDoubleClick( Mobile from )
		{	
			SendGumpToUser(from, DefaultAmount);
		}
		
		public static void SendGumpToUser(Mobile from, int defamt)
		{
			if(!Core.Testcenter && from.AccessLevel<AccessLevel.Seer)
			{
				from.SendMessage("You must be staff or be on test center to call this!");
				return;
			}
			
			
			if (from.HasGump(typeof(TcItemGump)))
				from.CloseGump(typeof(TcItemGump));
			from.SendGump(new TcItemGump(from,defamt));
		}		

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

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

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

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

			int version = reader.ReadInt();
			
			m_defaultamount=reader.ReadInt();
		}
		
			
		protected class GiveItemEntry
		{
			public string m_name;
			private double m_multiplier;
			private List<Type> m_types;
		
			public GiveItemEntry(string name, Type singletype,double multiplier)
			{
				m_name=name;
				
				m_types = new List<Type>();
				m_types.Add(singletype);
				
				m_multiplier=multiplier;
			}
		
			public GiveItemEntry(string name, List<Type> multitypes,double multiplier)
			{
				m_name=name;
				
				m_types = multitypes;
				
				m_multiplier=multiplier;
			}
			
			public GiveItemEntry(string name, Type singletype) : this(name, singletype,1)
			{
			}
		
			public GiveItemEntry(string name, List<Type> multitypes) : this(name, multitypes,1)
			{
			}			
			
			
			public void GiveTo(Mobile mob,int amt)
			{
				amt=(int)(amt*m_multiplier);
				if(amt<1)amt=1;
				
				if(m_types!=null && mob!=null && mob.Backpack!=null)
				{
					string bagname = String.Format("Bag of {0}",m_name);
					
					TcBag bag = new TcBag();	
					bag.Name=bagname;
					
					foreach(Type type in m_types)
					{	
						for(int i=0;i<amt;i++)
						{
							//special case for runic tools:
							if(type == typeof(BaseRunicTool))
							{
								BaseRunicTool.FillWithRunicTools(bag);
								continue;
							}
							
							
							//generate item:
							Item item = Activator.CreateInstance( type ) as Item;
						
							if(item==null)
							{
								break;
							}
							
							// modify certain exceptions:
							
							//----
							if(item is Spellbook)Spellbook.FillSpellBook((Spellbook)item);
							//----
							
							
							//add item to user's bag:
							bag.DropItem(item);	
							
							if(item.Stackable)
							{
								item.Amount=amt;
								break;
							}
							
						}
					}

					mob.Backpack.DropItem(bag);	
					mob.SendMessage("You have been given a bag of {0}",m_name);
				}			
			}
		}
		
		
		
		public class TcItemGump : Gump
		{
			Mobile m_caller;
			int m_defaultamt;			
			private static int EntryAddIndex=0;
			private static Dictionary<int,GiveItemEntry> m_giveentries = new Dictionary<int,GiveItemEntry>();
			
			
			private static void InitItemEntries()
			{				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Gold",typeof(Gold),10000));		
				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Silver",typeof(Server.Factions.Silver),10000));	
				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Random Arty Deeds",typeof(randomartydeed)));
				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Skill Deeds",typeof(skilldeed)));				
				
					
				List<Type> spellbooklist = new List<Type>();				
				spellbooklist.Add(typeof(Spellbook));
				spellbooklist.Add(typeof(NecromancerSpellbook));				
				spellbooklist.Add(typeof(BookOfChivalry));				
				spellbooklist.Add(typeof(BookOfNinjitsu));				
				spellbooklist.Add(typeof(BookOfBushido));				
				spellbooklist.Add(typeof(SpellweavingBook));				
				spellbooklist.Add(typeof(Runebook));			
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Spellbooks",spellbooklist,0.1));
				
				
				List<Type> reglist = new List<Type>();
				reglist.Add(typeof(BlackPearl));
				reglist.Add(typeof(Bloodmoss));
				reglist.Add(typeof(Garlic));
				reglist.Add(typeof(Ginseng));
				reglist.Add(typeof(MandrakeRoot));
				reglist.Add(typeof(Nightshade));
				reglist.Add(typeof(SulfurousAsh));
				reglist.Add(typeof(SpidersSilk));
				reglist.Add(typeof(BatWing));
				reglist.Add(typeof(GraveDust));
				reglist.Add(typeof(DaemonBlood));
				reglist.Add(typeof(NoxCrystal));
				reglist.Add(typeof(PigIron));
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Reagents",reglist,1000));
				
				
				List<Type> resourcelist1 = new List<Type>();
				resourcelist1.Add(typeof(Hides));
				resourcelist1.Add(typeof(SpinedHides));
				resourcelist1.Add(typeof(HornedHides));
				resourcelist1.Add(typeof(BarbedHides));			
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Hides",resourcelist1,1000));
				
				
				List<Type> resourcelist2 = new List<Type>();
				resourcelist2.Add(typeof(Log));			
				resourcelist2.Add(typeof(OakLog));			
				resourcelist2.Add(typeof(AshLog));			
				resourcelist2.Add(typeof(YewLog));			
				resourcelist2.Add(typeof(BloodwoodLog));			
				resourcelist2.Add(typeof(HeartwoodLog));			
				resourcelist2.Add(typeof(FrostwoodLog));			
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Logs",resourcelist2,1000));		
				
				
				List<Type> resourcelist3 = new List<Type>();
				resourcelist3.Add(typeof(IronOre));			
				resourcelist3.Add(typeof(DullCopperOre));			
				resourcelist3.Add(typeof(ShadowIronOre));			
				resourcelist3.Add(typeof(CopperOre));			
				resourcelist3.Add(typeof(BronzeOre));			
				resourcelist3.Add(typeof(GoldOre));			
				resourcelist3.Add(typeof(AgapiteOre));			
				resourcelist3.Add(typeof(VeriteOre));				
				resourcelist3.Add(typeof(ValoriteOre));				
				resourcelist3.Add(typeof(CoalOre));				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Ore",resourcelist3,1000));	
				
				
				List<Type> resourcelist4 = new List<Type>();
				resourcelist4.Add(typeof(RedScales));					
				resourcelist4.Add(typeof(YellowScales));					
				resourcelist4.Add(typeof(BlackScales));					
				resourcelist4.Add(typeof(GreenScales));					
				resourcelist4.Add(typeof(WhiteScales));					
				resourcelist4.Add(typeof(BlueScales));			
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Scales",resourcelist4,1000));		
				

				List<Type> resourcelist5 = new List<Type>();
				resourcelist5.Add(typeof(Granite));					
				resourcelist5.Add(typeof(DullCopperGranite));					
				resourcelist5.Add(typeof(ShadowIronGranite));					
				resourcelist5.Add(typeof(CopperGranite));					
				resourcelist5.Add(typeof(BronzeGranite));					
				resourcelist5.Add(typeof(GoldGranite));					
				resourcelist5.Add(typeof(AgapiteGranite));					
				resourcelist5.Add(typeof(VeriteGranite));					
				resourcelist5.Add(typeof(ValoriteGranite));						
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Granite",resourcelist5,1000));	
				

				List<Type> resourcelist6 = new List<Type>();
				resourcelist6.Add(typeof(Blight));  
				resourcelist6.Add(typeof(LuminescentFungi));  
				resourcelist6.Add(typeof(Corruption));  
				resourcelist6.Add(typeof(ParasiticPlant));  
				resourcelist6.Add(typeof(Muculent));  
				resourcelist6.Add(typeof(DiseasedBark));  
				resourcelist6.Add(typeof(BarkFragment));  
				resourcelist6.Add(typeof(PerfectEmerald));  
				resourcelist6.Add(typeof(DarkSapphire));  
				resourcelist6.Add(typeof(Turquoise));  
				resourcelist6.Add(typeof(EcruCitrine));  
				resourcelist6.Add(typeof(WhitePearl));  
				resourcelist6.Add(typeof(FireRuby));  
				resourcelist6.Add(typeof(BlueDiamond));  
				resourcelist6.Add(typeof(BrilliantAmber));  
				resourcelist6.Add(typeof(Scourge));  
				resourcelist6.Add(typeof(Putrefaction));  
				resourcelist6.Add(typeof(Taint)); 			
				resourcelist6.Add(typeof(CapturedEssence));  
				resourcelist6.Add(typeof(EyeOfTheTravesty));  
				resourcelist6.Add(typeof(DreadHornMane));  
				resourcelist6.Add(typeof(JormundgandBile));  
				resourcelist6.Add(typeof(GrizzledBones));  
				resourcelist6.Add(typeof(LardOfParoxysmus));  
				resourcelist6.Add(typeof(PristineDreadHorn));  
				resourcelist6.Add(typeof(Citrine)); 					
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("ML Resources",resourcelist6,1000));	
				

				List<Type> resourcelist7 = new List<Type>();
				resourcelist7.Add(typeof(PowderOfTranslocation));				
				resourcelist7.Add(typeof(Cloth));				
				resourcelist7.Add(typeof(BlankScroll));								
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Misc Resources",resourcelist7,1000));	
				

				List<Type> resourcelist8 = new List<Type>();
				resourcelist8.Add(typeof(Tongs));					
				resourcelist8.Add(typeof(DovetailSaw));					
				resourcelist8.Add(typeof(FletcherTools));					
				resourcelist8.Add(typeof(MalletAndChisel));					
				resourcelist8.Add(typeof(MapmakersPen));					
				resourcelist8.Add(typeof(MortarPestle));					
				resourcelist8.Add(typeof(RollingPin));					
				resourcelist8.Add(typeof(ScribesPen));					
				resourcelist8.Add(typeof(SewingKit));					
				resourcelist8.Add(typeof(TinkerTools));					
				resourcelist8.Add(typeof(Blowpipe));					
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Tools",resourcelist8));					
				
				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Runic Tools",typeof(BaseRunicTool)));					

				
				List<Type> resourcelist9 = new List<Type>();
				resourcelist9.Add(typeof(ChiefParoxysmusKeyBag));					
				resourcelist9.Add(typeof(DreadhornKey));					
				resourcelist9.Add(typeof(MonstrousInterredGrizzleKey));					
				resourcelist9.Add(typeof(JormundgandKey));					
				resourcelist9.Add(typeof(MelisandeKey));					
				resourcelist9.Add(typeof(ShimmeringEffusionKey));					
				resourcelist9.Add(typeof(TravestyKey));				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Peerless keys",resourcelist9,0.1));	
				
				
				
				
				
				
				
				
				
				
				List<Type> miscitems = new List<Type>();				
				miscitems.Add(typeof(BagOfSending));				
				miscitems.Add(typeof(BraceletOfBinding));				
				m_giveentries.Add(EntryAddIndex++,new GiveItemEntry("Misc Items",miscitems,0));	
			}			
			

			public static void Initialize()
			{	
				if(Core.Testcenter)
				{
					CommandSystem.Register( "tcitemgump", AccessLevel.Seer, new CommandEventHandler( TcItemGump_OnCommand ),true );
				}
				
				
				InitItemEntries();
			}
			
			
			private static GiveItemEntry GetEntry(int i)
			{
				GiveItemEntry entry; 
				m_giveentries.TryGetValue(i,out entry);
				return entry;
			}
			
			
			
			

			[Usage("tcitemgump")]
			[Description("Calls TC Item Gump")]
			public static void TcItemGump_OnCommand(CommandEventArgs e)
			{
				Mobile caller = e.Mobile;
				
				SendGumpToUser(caller,10);
			}
			
			

			public TcItemGump(Mobile from,int defaultamt) : this()
			{
				m_caller = from;
				m_defaultamt=defaultamt;
			}

			public TcItemGump() : base( 0, 0 )
			{
				this.Closable=true;
				this.Disposable=true;
				this.Dragable=true;
				this.Resizable=false;
				
				int heightmod = 20*(int)Math.Ceiling((double)m_giveentries.Count/3);
				

				AddPage(0);
				AddBackground(2, 0, 529, 90+heightmod, 9200);
				AddLabel(200, 17, 0, @"Test Center Items");
				AddImage(216, -3, 30076);
				

				bool breakout=false;
				int entrynum=0;
				int ii=0;
				while(!breakout)
				{
					for(int i=0;i<3;i++)
					{
						GiveItemEntry entry = GetEntry(entrynum);
						if(entry==null)
						{
							breakout=true;
							break;
						}
				
						AddButton(17+(i*180), 60+(ii*20), 1209, 1210, entrynum+1, GumpButtonType.Reply, 0);
						AddLabel(41+(i*180), 60+(ii*20), 0, entry.m_name);
						
						entrynum++;				
					}
					ii++;
				}

			}

			

			public override void OnResponse(NetState sender, RelayInfo info)
			{
				Mobile from = sender.Mobile;
				
				if(info.ButtonID==0)return;
				
				
				GiveItemEntry entry = GetEntry(info.ButtonID-1);
				
				if(entry!=null)
				{
					entry.GiveTo(from,m_defaultamt);
					SendGumpToUser(from,m_defaultamt);
				}
			}
		}		
	}
	
	
	
	
	
	
	
	
	public class TcBag : BaseContainer, IDyable
	{
		
		
		[Constructable]
		public TcBag() : base( 0xE76 )
		{
			Hue=1285;
			LootType=LootType.Blessed;
		}
		
		public override void OnDoubleClick( Mobile from )
		{
			if(!Core.Testcenter)
			{
				from.SendMessage("This item can only be used on test center and has been deleted");
				this.Delete();
			}
			
			base.OnDoubleClick( from );
		}
		
		public override int GetTotal( TotalType type )
		{

		return 0;
		}	
		
		public override void UpdateTotal( Item sender, TotalType type, int delta )
		{
		
		}
		

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

		public bool Dye( Mobile from, DyeTub sender )
		{
			if ( Deleted ) return false;

			Hue = sender.DyedHue;

			return true;
		}

		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();
		}
	}	
	
	
	

	
	
	
	
}