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


using System;
using Server;
using Server.Mobiles;
using Server.Items;

namespace Server.Items
{
	public class RandomTalisman : BaseTalisman
	{
	
			private static SkillName[] m_PossibleBonusSkills = new SkillName[]
			{
				SkillName.Swords,
				SkillName.Fencing,
				SkillName.Macing,
				SkillName.Archery,
				SkillName.Wrestling,
				SkillName.Parry,
				SkillName.Tactics,
				SkillName.Anatomy,
				SkillName.Healing,
				SkillName.Magery,
				SkillName.Meditation,
				SkillName.EvalInt,
				SkillName.MagicResist,
				SkillName.AnimalTaming,
				SkillName.AnimalLore,
				SkillName.Veterinary,
				SkillName.Musicianship,
				SkillName.Provocation,
				SkillName.Discordance,
				SkillName.Peacemaking,
				SkillName.Chivalry,
				SkillName.Focus,
				SkillName.Necromancy,
				SkillName.Stealing,
				SkillName.Stealth,
				SkillName.SpiritSpeak,
			};
	
	
		[Constructable]
		public RandomTalisman() : base( GetRandomID() )
		{
			MaxCharges = GetRandomCharges();		
			Summoner = GetRandomSummoner();
			
			if ( Summoner == null )
			{
				Removal = GetRandomRemoval();
				
				if ( Removal != TalismanRemoval.None )
					MaxChargeTime = 1200;
			}
			else if ( MaxCharges > 0 )
			{
				if (Summoner.Type == typeof( IronIngot ) ||
					Summoner.Type == typeof( Board ) ||
					Summoner.Type == typeof( Bandage ) 
				)
					MaxChargeTime = 60;
				else
					MaxChargeTime = 1800;
			}	
			else
				MaxChargeTime = 1800;
				
			Blessed = GetRandomBlessed();
			Slayer = GetRandomSlayer();
			Protection = GetRandomProtection();
			Killer = GetRandomKiller();
			Skill = GetRandomSkill(); 
			ExceptionalBonus = GetRandomExceptional();	
			SuccessBonus = GetRandomSuccessful();	
		
			if(ExceptionalBonus>SuccessBonus)ExceptionalBonus=Utility.Random(SuccessBonus);
			
			if ( Summoner == null && Removal == TalismanRemoval.None )
			{
				MaxCharges = 0;
				MaxChargeTime = 0;
			}
			else
				Charges = MaxCharges;
				
			



			//randomize attributes -unlike most loot this is not luck based at all
			
			//first determine how many attributes we want
			int attribcount=0;
			
			if(0.001>Utility.RandomDouble())attribcount=4+Utility.Random(1);
			else if(0.005>Utility.RandomDouble())attribcount=3;
			else if(0.05>Utility.RandomDouble())attribcount=2;
			else if(0.4>Utility.RandomDouble())attribcount=1;

			
			for(;attribcount>0;attribcount--)
			{
				switch(Utility.Random(27))
				{
				//attributes
				case 0:Attributes.AttackChance=1+Utility.Random(15); break;
				case 1:Attributes.BonusDex=1+Utility.Random(10); break;
				case 2:Attributes.BonusHits=1+Utility.Random(10); break;	
				case 3:Attributes.BonusInt=1+Utility.Random(10); break;	
				case 4:Attributes.BonusMana=1+Utility.Random(10); break;	
				case 5:Attributes.BonusStam=1+Utility.Random(10); break;	
				case 6:Attributes.BonusStr=1+Utility.Random(10); break;	
				case 7:Attributes.CastRecovery=Utility.Random(3); break;	
				case 8:Attributes.CastSpeed=Utility.Random(1); break;	
				case 9:Attributes.DefendChance=1+Utility.Random(15); break;	
				case 10:Attributes.EnhancePotions=1+Utility.Random(25); break;	
				case 11:Attributes.LowerManaCost=1+Utility.Random(15); break;	
				case 12:Attributes.LowerRegCost=1+Utility.Random(30); break;	
				case 13:Attributes.Luck=1+Utility.Random(100); break;	
				case 14:Attributes.ReflectPhysical=1+Utility.Random(10); break;	
				case 15:Attributes.RegenHits=1+Utility.Random(3); break;	
				case 16:Attributes.RegenMana=1+Utility.Random(3); break;	
				case 17:Attributes.RegenStam=1+Utility.Random(3); break;			
				case 18:Attributes.SpellDamage=1+Utility.Random(10); break;	
				case 19:Attributes.WeaponDamage=1+Utility.Random(15); break;	
				case 20:Attributes.WeaponSpeed=1+Utility.Random(10); break;	
				case 21:Attributes.LowerAmmoCost=1+Utility.Random(15);break;
				
				//skillbonus
				case 22:SkillBonuses.SetValues( 0, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)], Utility.Random(16) ); break;
				case 23:SkillBonuses.SetValues( 1, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)], Utility.Random(16) ); break;
				case 24:SkillBonuses.SetValues( 2, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)], Utility.Random(16) ); break;
				case 25:SkillBonuses.SetValues( 3, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)], Utility.Random(16) ); break;
				case 26:SkillBonuses.SetValues( 4, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)], Utility.Random(16) ); break;
				}
			}
			

			//end randomize attributes
				
		}
		
		public RandomTalisman( 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();
		}
		
		#region randomize
		private static int[] m_ItemID = new int[] { 0x2F58, 0x2F59, 0x2F5A, 0x2F5B };
		
		public static int GetRandomID()
		{
			return m_ItemID[ Utility.Random( m_ItemID.Length ) ];
		} 
		
		private static Type[] m_Summons = new Type[]
		{
			typeof( SummonedAntLion ),
			typeof( SummonedCow ),
			typeof( SummonedLavaSerpent ),
			typeof( SummonedOrcBrute ),
			typeof( SummonedFrostSpider ), 
			typeof( SummonedPanther ),
			typeof( SummonedDoppleganger ), 
			typeof( SummonedGreatHart ),
			typeof( SummonedBullFrog ),
			typeof( SummonedArcticOgreLord ),
			typeof( SummonedBogling ),
			typeof( SummonedBakeKitsune ),
			typeof( SummonedSheep ),
			typeof( SummonedSkeletalKnight ),
			typeof( SummonedWailingBanshee ),
			typeof( SummonedChicken ),
			typeof( SummonedVorpalBunny ),
			
			typeof( Board ),
			typeof( IronIngot ),
			typeof( Bandage ),
		};
		
		private static int[] m_SummonLabels = new int[]
		{
			1075211, // Ant Lion
			1072494, // Cow
			1072434, // Lava Serpent
			1072414, // Orc Brute
			1072476, // Frost Spider
			1029653, // Panther 
			1029741, // Doppleganger
			1018292, // great hart
			1028496, // bullfrog
			1018227, // arctic ogre lord
			1029735, // Bogling
			1030083, // bake-kitsune
			1018285, // sheep
			1018239, // skeletal knight
			1072399, // Wailing Banshee
			1072459, // Chicken
			1072401, // Vorpal Bunny
			
			1015101, // Boards
			1044036, // Ingots
			1023817, // clean bandage
		};
		
		public static Type GetRandomSummonType()
		{
			return m_Summons[ Utility.Random( m_Summons.Length ) ]; 
		}
		
		public static TalismanAttribute GetRandomSummoner()
		{
			if ( 0.025 > Utility.RandomDouble() )
			{
				int num = Utility.Random( m_Summons.Length );
				
				if ( num > 14 )
					return new TalismanAttribute( m_Summons[ num ], 10, m_SummonLabels[ num ] );
				else
					return new TalismanAttribute( m_Summons[ num ], 0, m_SummonLabels[ num ] );
			}
			
			return null;
		}
		
		public static TalismanRemoval GetRandomRemoval()
		{
			if ( 0.65 > Utility.RandomDouble() )
				return (TalismanRemoval) Utility.RandomList( 390, 404, 407 ); 
			
			return TalismanRemoval.None;
		}
		
		private static Type[] m_Killers = new Type[]
		{
			typeof( OrcBomber ), 	typeof( OrcBrute ), 				typeof( Sewerrat ), 		typeof( Rat ), 				typeof( GiantRat ), 
			typeof( Ratman ), 		typeof( RatmanArcher ), 			typeof( GiantSpider ), 		typeof( FrostSpider ), 		typeof( GiantBlackWidow ), 
			typeof( DreadSpider ), 	typeof( SilverSerpent ), 			typeof( DeepSeaSerpent ), 	typeof( GiantSerpent ), 	typeof( Snake ), 
			typeof( IceSnake ), 	typeof( IceSerpent ), 				typeof( LavaSerpent ), 		typeof( LavaSnake ),		typeof( Yamandon ),		
			typeof( StrongMongbat ),typeof( Mongbat ), 					typeof( VampireBat ), 		typeof( Lich ),				typeof( EvilMage ), 	
			typeof( LichLord ),		typeof( EvilMageLord ), 			typeof( SkeletalMage ), 	typeof( KhaldunZealot ), 	typeof( AncientLich ), 	
			typeof( JukaMage ), 	typeof( MeerMage ), 				typeof( Beetle ), 			typeof( DeathwatchBeetle ), typeof( RuneBeetle ),	
			typeof( FireBeetle ),	typeof( DeathwatchBeetleHatchling), typeof( Bird ), 			typeof( Chicken ), 			typeof( Eagle ), 		
			typeof( TropicalBird ), typeof( Phoenix ), 					typeof( DesertOstard ), 	typeof( FrenziedOstard ), 	typeof( ForestOstard ), 	
			typeof( Crane ),		typeof( SnowLeopard ), 				typeof( IceFiend ), 		typeof( FrostOoze ), 		typeof( FrostTroll ), 		
			typeof( IceElemental ),	typeof( SnowElemental ), 			typeof( GiantIceWorm ), 	typeof( LadyOfTheSnow ), 	typeof( FireElemental ), 	
			typeof( FireSteed ), 	typeof( HellHound ), 				typeof( HellCat ), 			typeof( PredatorHellCat ), 	typeof( LavaLizard ), 		
			typeof( FireBeetle ), 	typeof( Cow ), 						typeof( Bull ), 			typeof( Gaman ) ,
			
			typeof(vorpalchicken),typeof(jediknight),typeof(darkjediknight),typeof(sithlord),typeof(DemonKnight),
			typeof(Harrower),typeof(rabidsquirrel),typeof(Hiryu)
		};
		
		private static string[] m_KillerLabels = new string[]
		{
			"Orc Bomber","Orc Brute","Sewer Rat","Rat","Giant Rat",
			"Rat Man","Ratman Archer","Giant Spider","Frost Spider","Giant Black Widow",
			"Dread Spider","Silver Serpent","Deep Sea Serpent","Giant Serpent","Snake",
			"Ice Snake","Ice Serpent","Lava Serpent","Lava Snake","Yamandon",
			"Strong Mongbat","Mongbat","Vampire Bat","Lich","Evil Mage",
			"Lich Lord","Evil Mage Lord","Skeletal Mage","Khaldun Zealot","Ancient Lich",
			"Juka Mage","Meer Mage","Beetle","Deathwatch Beetle","Rune Beetle",
			"Fire Beetle","Deathwatch Beetle Hatchling","Bird","Chicken","Eagle",
			"Tropical Bird","Phoenix","Desert Ostard","Frenzied Ostard","Forest Ostard",
			"Crane","Snow Leopard","Ice Fiend","Frost Ooze","Frost Troll",
			"Ice Elemental","Snow Elemental","Giant Ice Worm","Lady of the Snow","Fire Elemental",
			"Fire Steed","Hell Hound","Hell Cat","Predator Hell Cat","Lava Lizard",
			"Fire Beetle","Cow","Bull","Gaman",
			
			"Vorpal Chicken","Jedi Knight","Dark Jedi Knight","Sith Lord","Dark Father",
			"Harrower","Rabid Squirrel","Hiryu"
		};
		
		public static TalismanAttribute GetRandomKiller()
		{
			if ( 0.5 > Utility.RandomDouble() )
			{	
				int num = Utility.Random( m_Killers.Length );
				
				return new TalismanAttribute( m_Killers[ num ], Utility.RandomMinMax( 10, 100 ), m_KillerLabels[ num ] );
			}
			
			return null;
		}
		
		public static TalismanAttribute GetRandomProtection()
		{
			if ( 0.5 > Utility.RandomDouble() )
			{	
				int num = Utility.Random( m_Killers.Length );
				
				return new TalismanAttribute( m_Killers[ num ], Utility.RandomMinMax( 5, 100 ),  m_KillerLabels[ num ] );
			}
			
			return null;
		}
		
		private static SkillName[] m_Skills = new SkillName[]
		{
			SkillName.Alchemy, 
			SkillName.Blacksmith, 
			SkillName.Carpentry,
			SkillName.Cartography, 
			SkillName.Cooking, 
			SkillName.Fletching, 
			SkillName.Inscribe, 
			SkillName.Tailoring, 
			SkillName.Tinkering,
		};
		
		public static SkillName GetRandomSkill()
		{
			return m_Skills[ Utility.Random( m_Skills.Length ) ];
		}
		
		public static int GetRandomExceptional()
		{
			if ( 0.3 > Utility.RandomDouble() )
			{
				double num = 40 - Math.Log( Utility.RandomMinMax( 5, 149 ) ) * 6;
				
				return (int) Math.Round( num );
			}			
			
			return 0;
		}
		
		public static int GetRandomSuccessful()
		{
			if ( 0.75 > Utility.RandomDouble() )
			{
				double num = 40 - Math.Log( Utility.RandomMinMax( 5, 149 ) ) * 6;
				
				return (int) Math.Round( num );
			}			
			
			return 0;
		}
		
		public static bool GetRandomBlessed()
		{
			if ( 0.02 > Utility.RandomDouble() )
				return true;
				
			return false;
		}		
		
		public static SlayerName GetRandomSlayer()
		{
			if ( 0.1 > Utility.RandomDouble() )
			{			
			return BaseRunicTool.GetRandomSlayer();
			}
			
			return SlayerName.None;
		}
		
		public static int GetRandomCharges()
		{
			if ( 0.5 > Utility.RandomDouble() )
				return Utility.RandomMinMax( 10, 50 );
				
			return -1;
		}
		#endregion
	}
}