/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-25-2011 07:40:10pm
Filepath: scripts\Items\Misc\roulette.cs
Lines of code: 550

Description: 

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


using System;
using Server;
using Server.Spells;
using Server.Items;
using Server.Network;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
using System.Collections;


namespace Server.Items
{
	public class artyroulette : Item
	{

		public override string DefaultName
		{
			get { return "Artifact Roulette"; }
		}


		[Constructable]
		public artyroulette() :  base(7026)
		{
		Hue=51;
		}

		
		public override void OnDoubleClick( Mobile from )
		{
			if(!from.InRange( this, 1 ))
			{
			from.SendMessage("This is too far away");
			return;
			}		
		
		from.SendMessage(57,"Select an artifact or token to give up for a gamble!  Your reward can be anything from a greater artifact, or a trip to the world of the undead...");
		
		from.Target = new RouletteTarget( from );
		}
		


		private class RouletteTarget : Target
		{
		Point3D m_position;
			
			public RouletteTarget(Mobile mob) : base( 12, false, TargetFlags.None )
			{
			m_position=mob.Location;			
			}

			protected override void OnTarget( Mobile from, object o )
			{
				if(m_position!=from.Location)
				{
				from.SendMessage("You cannot move away from the roulette while using it.");
				return;
				}			
			
				if(o is Item)
				{
				Item item = o as Item;
				
				 if(!item.IsChildOf( from.Backpack ))
				 {
				 from.SendMessage("The item must be in your backpack");
				 return;
				 }
				 
				 Type gambletype = item.GetType();
				 
				 //we made it here, all is good now, start checking to make sure the item is exeptable
				 
				 int artypoints=0; //higher the number, lower the chance
				 //======================================
				 //======================================
				 
				if(item is PowerScroll)
				{
				PowerScroll scroll = item as PowerScroll;
				
				if(scroll.Value>115)artypoints=40;
				else if(scroll.Value>110)artypoints=70;
				else if(scroll.Value>105)artypoints=80;	
				else artypoints=200;

				Gamble(from,item,artypoints);				
				return;
				}
				
				 
				if(item is StatCapScroll)
				{
				StatCapScroll scroll = item as StatCapScroll;
				
				if(scroll.Value>250)artypoints=5;
				else if(scroll.Value>245)artypoints=15;
				else if(scroll.Value>240)artypoints=25;	
				else if(scroll.Value>230)artypoints=40;	
				else artypoints=100;

				Gamble(from,item,artypoints);				
				return;
				}
				 	
				
				//check if its a bankcheck
				
				if(item is BankCheck)
				{
				BankCheck check = item as BankCheck;
				
					if(check.Worth>=1000000)
					{
					check.Worth-=1000000;
					Gamble(from,item,15,true);					
					if(check.Worth==0)check.Delete();
					}
					else from.SendMessage("You may only gamble checks larger then 1,000,000!");
				
				return;
				}
				 
				 //check if it's a roulette token ------------------------------------------------
				 
				 if(item is BronzeToken)
					artypoints=20;
				 else if (item is SilverToken)
					artypoints=15;
				 else if (item is GoldToken)
					artypoints=10;
				 else if (item is PlatinumToken)
					artypoints=2;
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 item.Delete();	
				 return;
				 }
				 
				 //check if it's a lesser AoA ------------------------------------------------
				 
				 for(int i=0;i<Server.Misc.TreasuresOfFelucca.m_LesserArtifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.TreasuresOfFelucca.m_LesserArtifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=10;
					 tempitem.Delete();	
					 break;
					 }
					 
				  tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }
				 
				 
				 //check if it's a greater AoA ------------------------------------
				
				  for(int i=0;i<Server.Misc.TreasuresOfFelucca.m_GreaterArtifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.TreasuresOfFelucca.m_GreaterArtifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=2;
					 tempitem.Delete();	
					 break;
					 }
					 
			     tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }
				 
				 
				 
				 //check if it's a minor artifact --------------------------------------------
				 
				 for(int i=0;i<Server.Mobiles.Paragon.Artifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Mobiles.Paragon.Artifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=25;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }	


				 //check if it's a ML minor artifact --------------------------------------------
				 
				 for(int i=0;i<Server.Misc.MlMartys.m_mlmartys.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.MlMartys.m_mlmartys[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=20;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }				 
				 
				 //check if it's a leviathan artifact --------------------------------------------
				 
				 for(int i=0;i<Server.Mobiles.Leviathan.Artifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance(Server.Mobiles.Leviathan.m_LeviathanArtifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=10;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }	 
				 
				 
				 //check if it's a lesser tot --------------------------------------------
				 
				  for(int i=0;i<Server.Misc.TreasuresOfTokuno.m_LesserArtifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.TreasuresOfTokuno.m_LesserArtifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=65;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }		 				 


				 //check if it's a greater tot --------------------------------------------
				 
				  for(int i=0;i<Server.Misc.TreasuresOfTokuno.GreaterArtifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.TreasuresOfTokuno.GreaterArtifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=15;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }	
				 
				



				//check if it's a rarity 11 doom arty --------------------------------------------
				 
				  for(int i=0;i<Server.Mobiles.DemonKnight.ArtifactRarity11.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Mobiles.DemonKnight.ArtifactRarity11[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=2;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }			
				 
				 
				//check if it's 10th anniversary arty --------------------------------------------
				 
				  for(int i=0;i<Server.Misc.OSI10Anniversary.artifacts.Length;i++)
				 {
				 Item tempitem = Activator.CreateInstance( Server.Misc.OSI10Anniversary.artifacts[i]) as Item;
				 Type temptype = tempitem.GetType();
				 
					 if(gambletype==tempitem.GetType())
					 {
					 artypoints=8;
					 tempitem.Delete();	
					 break;
					 }
					 
				 tempitem.Delete();				 
				 }
				 
				 
				 if(artypoints>0)
				 {
				 Gamble(from,item,artypoints);
				 return;
				 }						 
				
				 

				
				from.SendMessage("The roulette cannot not accept this item, please try another item.");
				}
				else
				{
				from.SendMessage("You may only select items!");
				}
			}

			protected override void OnTargetFinish( Mobile from )
			{
			}
		
		private void Loose(Mobile from,Item arty,bool dontdelete)
		{
		if(from==null || arty==null)return;
		
		Effects.PlaySound( from.Location, from.Map, 479 );
		
		
		string message = String.Concat(from.Name," has lost! ");
		from.PublicOverheadMessage( MessageType.Regular, 37, false, message );		
		if(!dontdelete)arty.Delete();
		
			//random bad stuff can happen
			switch(Utility.Random(20))
			{
			case 2:
			from.Kill();
			break;
			
			case 4:
			from.BoltEffect( 0 );
			AOS.Damage( from,from, 60+Utility.Random(50) , 0, 0, 0, 0, 100 );
			break;
			
			case 6:
			AOS.Damage( from,from, 60+Utility.Random(50) , 20, 20, 20, 20, 20 );
			break;
			
			case 8:
			from.Poison=Poison.Lethal;
			break;		
			}
			
		
		}
		
		private void Win(Mobile from,Item artytowin,Item gamblearty,bool dontdelete)
		{
		if(from==null || artytowin==null || gamblearty==null)return;
		

			Effects.PlaySound( from.Location, from.Map, 503 ); 	
			Effects.SendTargetParticles( from, 0x375A, 35, 90, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 );		
		
		
			Container pack = from.Backpack;
			if ( pack == null || !pack.TryDropItem( from, artytowin, false ) )
			{
			from.BankBox.DropItem( artytowin );			
			from.SendMessage("As your backpack is full, your prize was sent to your bank box.");
			}
		
		
		
		string message = String.Concat(String.Concat(from.Name,String.Concat(" has won ",artytowin.Name),"!"));
		from.PublicOverheadMessage( MessageType.Regular, 92, false, message);		
		if(!dontdelete)gamblearty.Delete();
		}
		
		
		
		private void Gamble(Mobile from,Item item,int chancefactor,bool dontdelete)
		{
		if(from==null || item==null)return;
		
			//greater AOA
			if((chancefactor/3)==Utility.Random(chancefactor))
			{
			Item winartifact;
			
				//chance of getting screwed over and getting a lesser
				if(0.15>Utility.RandomDouble())winartifact = Activator.CreateInstance( Server.Misc.TreasuresOfFelucca.m_LesserArtifacts[Utility.Random(Server.Misc.TreasuresOfFelucca.m_LesserArtifacts.Length)]) as Item;
				else winartifact = Activator.CreateInstance( Server.Misc.TreasuresOfFelucca.m_GreaterArtifacts[Utility.Random(Server.Misc.TreasuresOfFelucca.m_GreaterArtifacts.Length)]) as Item;
			
			Win(from,winartifact,item,dontdelete);
			return;
			}
			
			
			if(10>Utility.Random((chancefactor/2)+14))
			{
			Item winitem=null;
				switch(Utility.Random(Utility.Random(14)))
				{
					case 13:
					{
						switch(Utility.Random(2))
						{
							case 0:
							winitem = new BankCheck(5000000);
							winitem.Name="the 5 mil Jackpot";
							break;
							
							case 1:
							winitem = new BankCheck(3000000);
							winitem.Name="the 3 mil Jackpot";
							break;
						}
					}
					break;
					
					case 12:
					switch ( Utility.Random( 4 ))
					{                                   
						case 0: 
							winitem = new RunicSewingKit(CraftResource.BarbedLeather);
							winitem.Name = "Barbed Runic Sewing Kit";
							break;   
						case 1: 
							winitem = new RunicHammer(CraftResource.Agapite);
							winitem.Name = "Agapite Runic Hammer";
							break;   
						case 2: 
							winitem = new RunicSaw(CraftResource.Bloodwood);
							winitem.Name= "Bloodwood Runic Saw";
							break;   
						case 3: 
							winitem = new RunicFletchingKit(CraftResource.Bloodwood);
							winitem.Name = "Bloodwood Runic Fletchin Kit";
							break;   
					}	
					break;
					
					
					case 11:
					winitem = new BankCheck(1000000);
					winitem.Name="the 1 mil Jackpot";
					break;	
					
					case 10:
					switch ( Utility.Random( 4 ))
					{                                   
						case 0: 
							winitem = new ClothingBlessDeed();
							winitem.Name="Clothing Bless Deed";
							break;   
						case 1: 
							winitem = new PetBondingDeed();
							winitem.Name="a Pet Bonding Deed";
							break;   
						case 2: 
							winitem = new FabledFishingNet();
							winitem.Name="Fabled Fishing Net";
							break;   
						case 3: 
							winitem = new BagOfUncommonMPResources(Utility.Random(5,6));
							winitem.Name="a Bag of Uncommon Masterpiece Resources";
							break;   
					}	
					break;
				
					case 9:
					switch ( Utility.Random( 5 ))
					{                                   
						case 0: 
							winitem = new BagOfRareGems( Utility.Random(5,8));
							winitem.Name="a Bag of rare gemstones";
							break;   
						case 1: 
							winitem = new BagOfBoards( Utility.Random(2,4));
							winitem.Name="a Bag of colored boards";
							break;   
						case 2: 
							winitem = new BagOfRareGems( Utility.Random(6,10));
							winitem.Name="a Bag of rare gemstones";
							break;   
						case 3: 
							winitem = new BagOfBoards( Utility.Random(3,5));
							winitem.Name="a Bag of colored boards";
							break;   
						case 4: 
							winitem = new BagOfUncommonMPResources(Utility.Random(2,4));
							winitem.Name="a Bag of Uncommon Masterpiece Resources";
							break;  
					}	
					break;
					
					case 8:
					switch ( Utility.Random( 4 ))
					{                                   
						case 0: 
							winitem = new RunicSewingKit(CraftResource.HornedLeather);
							winitem.Name = "Horned Runic Sewing Kit";
							break;   
						case 1: 
							winitem = new RunicHammer(CraftResource.ShadowIron);
							winitem.Name = "Shadow Iron Runic Hammer";
							break;   
						case 2: 
							winitem = new RunicSaw(CraftResource.Oakwood);
							winitem.Name= "Oak Runic Saw";
							break;   
						case 3: 
							winitem = new RunicFletchingKit(CraftResource.Oakwood);
							winitem.Name = "Oak Runic Fletching Kit";
							break;   
					}	
					break;

					case 7:  
					winitem = new BagOfCommonMPResources( Utility.Random(4,7));
					winitem.Name="a Bag of Common Masterpiece Resources";
					break;
					
					case 6:
					winitem = new PowderOfTemperament(Utility.Random(1,3)*5);
					winitem.Name = "Powder of Fortification";
					break;
					
					case 5:
					switch ( Utility.Random( 7 ))
					{                                   
						case 0: 
							winitem = new PetParrotStatue();
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 1: 
							winitem = new PetParrotStatue(Utility.RandomList(3, 23, 38, 43, 53, 68, 88, 667)); //Roulette only hues
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 2: 
							winitem = new PetParrotStatue();
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 3: 
							winitem = new PetParrotStatue();
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 4: 
							winitem = new PetParrotStatue(Utility.RandomList(3, 23, 38, 43, 53, 68, 88, 667)); //Roulette only hues
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 5: 
							winitem = new PetParrotStatue(Utility.RandomList(3, 23, 38, 43, 53, 68, 88, 667)); //Roulette only hues
							winitem.Name = "a Pet Parrot Statue";
							break;   
						case 6: 
							winitem = new PetParrotStatue();
							winitem.Name = "a Pet Parrot Statue";
							break;   
					}	
					break;
					
					case 4:
					switch ( Utility.Random( 4 ))
					{                                   
						case 0: 
							winitem = new BagOfNecroReagents(200*Utility.Random(1,5));
							winitem.Name="a Bag of Necromancer Reagents";
							break;   
						case 1: 
							winitem = new BagOfReagents(200*Utility.Random(1,5));
							winitem.Name="a Bag of Mage Reagents";
							break;   
						case 2: 
							winitem = new BagOfReagents(120*Utility.Random(1,5));
							winitem.Name="a Bag of Mage Reagents";
							break;   
						case 3: 
							winitem = new BagOfCommonMPResources( Utility.Random(3,5));
							winitem.Name="a Bag of Common Masterpiece Resources";
							break;   
					}	
					break;

					case 3:
					switch ( Utility.Random( 4 ))
					{                                   
						case 0: 
							winitem = new BagOfReagents( 90*Utility.Random(1,5));
							winitem.Name="a Bag of Mage Reagents";
							break;   
						case 1: 
							winitem = new BagOfNecroReagents(40*Utility.Random(1,5));
							winitem.Name="a Bag of Necromancer Reagents";
							break;   
						case 2: 
							winitem = new BagOfReagents(110*Utility.Random(1,5));
							winitem.Name="a Bag of Mage Reagents";
							break;   
						case 3: 
							winitem = new BagOfCommonMPResources( Utility.Random(1,3));
							winitem.Name="a Bag of Common Masterpiece Resources";
							break;   
					}	
					break;	

					case 2:
					winitem = new skilldeed();
					break;	

					case 1:
					winitem = new PowderOfTranslocation(100);
					winitem.Name="Powder of Translocation";
					break;	
					
					case 0:
					winitem = new BagOfSending();
					if(Utility.Random(10)==5)winitem.LootType=LootType.Blessed;
					winitem.Name="a Bag of Sending";
					break;
				}
			if(winitem==null)winitem=new BankCheck(100);  //default crappy prize :P (should not hit that)
			
			Win(from,winitem,item,dontdelete);
			return;
			}
			
			
			
		//we lost!
		Loose(from,item,dontdelete);		
		}
		
		private void Gamble(Mobile from,Item item,int chancefactor)
		{
			Gamble(from,item, chancefactor,false);
		}
			
			
			
		}			
		
		
		


		public artyroulette( 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();

		}
	}
	


	
	
}
