/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-24-2011 10:26:27pm
Filepath: scripts\Engines\artifact systems\craftable\RandomRecipe.cs
Lines of code: 87

Description: 

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


using Server;
using System;

namespace Server.Items
{

	public class RandomRecipe
	{

	//======================== PEERLESS / CRAFT============================
	/*
	How this system works:
	There are 3 levels  1: common, 2: rare 3: ultra rare, and also these can drop not only on peerless but craft quests, so these levels also have an effect.
	Each recipe is given a number to indicate which craft system its for, peerless drop does not check this, but craft does.
	*/
	
		public class Drop
		{
		public int crafttype;
		public Type recipe;
		
			public Drop(int pcrafttype,Type precipe)
			{
			crafttype=pcrafttype;
			recipe=precipe;			
			}
		}
			
		//RECIPE LIST
		//-----------------
		
		/*
		0=peerless only
		1=blacksmithy
		2=tailoring
		3=fletching
		4=tinkering
		5=carpentry
		
		add 1000 to make it craft only (ex: 1002 is tailor only)
		*/	
		
		//2D array, first index is level, 2nd index is an arty drop of that level
		public static Drop[][] PeerlessRecipes = new Drop[][]
		{
			new Drop[]  //LEVEL1 - Common
			{			
			new Drop(1,typeof(ColdForgedBladeRecipe)),	
			new Drop(1,typeof(OverseerSunderedBladeRecipe)),	
			new Drop(1,typeof(ShardThrasherRecipe)),	
			new Drop(3,typeof(SilvanisFeywoodBowRecipe)),				
			new Drop(2,typeof(SongWovenMantleRecipe))
			},
			new Drop[]  //LEVEL2 - Uncommon
			{
			new Drop(3,typeof(BlightGrippedLongbowRecipe)),
			new Drop(4,typeof(EssenceOfBattleRecipe)),			
			new Drop(1,typeof(LuminousRuneBladeRecipe)),				
			new Drop(3,typeof(MischiefMakerRecipe)),
			new Drop(5,typeof(PhantomStaffRecipe)),				
			new Drop(1,typeof(RuneCarvingKnifeRecipe)),				
			new Drop(2,typeof(SpellWovenBritchesRecipe)),				
			new Drop(2,typeof(StitchersMittensRecipe)),		
			new Drop(3,typeof(TheNightReaperRecipe)),
			new Drop(4,typeof(EcruCitrineRingRecipe)),			
			},
			new Drop[]  //LEVEL3 - Rare
			{
			new Drop(3,typeof(FaerieFireRecipe)),
			new Drop(5,typeof(BrambleCoatRecipe)),
			new Drop(1,typeof(IronwoodCrownRecipe)),
			new Drop(1,typeof(BladeOfAgonyRecipe)),
			new Drop(4,typeof(PendantOfTheMagiRecipe)),				
			new Drop(4,typeof(ResilientBracerRecipe)),				
			new Drop(0,typeof(ScrappersCompendiumRecipe))
			}
		};
		
		
		
		
		//RANDOMIZER
		//--------------------
		public static Item Peerless(int level, int crafttype)
		{
			if(level<1)level=1;
			else if(level>3)level=3;
			
			level--; //arrays are 0 based! so we need to do this.
		
			Drop drop=null;
			
			//try to find an appropriate arty but only give limited tries to avoid infinite loop if none can be found - if it finishes then it will default to an invalid item
			for (int tries=0;tries<100;tries++)
			{
			drop = PeerlessRecipes[level][Utility.Random(PeerlessRecipes[level].Length)];
			
			//crafttype 0 was specified, this means this is for a peerless boss and craft type does not matter, unless its a craft only:
			if(crafttype==0 && drop.crafttype<1000)break;
			
			//crafttype is set so we check craftonly ones as welll (deduct 1000)
			if(crafttype>0 && (drop.crafttype==crafttype || ((drop.crafttype-1000)==crafttype)))break;
			}
			
			if(drop==null)
			{
			Console.WriteLine("Warning: RandomRecipe.Recipe() Generated null drop (Drop)");
			return new randomartydeed(); //default to random arty deed
			}
			
			Item i = null;
			
			try
			{
				i = Activator.CreateInstance( drop.recipe ) as BaseRecipe;
			}
			catch
			{ }
			
			if(i==null)
			{
			Console.WriteLine("Warning: RandomRecipe.Recipe() Generated null i (Item)");
			i = new randomartydeed(); //we just default to a arty deed to avoid a crash...  but this should never happen as long as the arraylist is properly populated
			}

		return i;
		}
		
		//no params overload (any arty, fixed level randomization) : used for peerless boss only
		public static Item Peerless()
		{
			return Peerless(0.01>Utility.RandomDouble() ? 3 : 0.1>Utility.RandomDouble() ? 2 : 1,0);
		}
		

	
	
	//================ END PEERLESS / CRAFT ==================
	
	
	
	


	}	
}

