/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\ML Minor Artys\mlmartys.cs
Lines of code: 76
***********************************************************/


using System;
using Server;
using Server.Network;
using System.Collections;
using Server.Items;
using Server.Gumps;
using Server.Misc;
using Server.Mobiles;

namespace Server.Misc
{
	public class MlMartys
	{

		    public static Type[] m_mlmartys = new Type[]
			{
			typeof(BloodwoodSpirit),typeof(AegisOfGrace),
			typeof(BladeDance),typeof(Bonesmasher),typeof(FeyLeggings),
			typeof(FleshRipper),typeof(HelmOfSwiftness),
			typeof(PadsOfTheCuSidhe),typeof(RaedsGlory),
			typeof(RighteousAnger),typeof(RobeOfTheEclipse),typeof(RobeOfTheEquinox),
			typeof(SoulSeeker),typeof(TalonBite),typeof(QuiverOfRage),typeof(QuiverOfTheElements),
			typeof(WildFireBow),typeof(Windsong),typeof(BrightsightLenses),typeof(Boomstick),typeof(TotemOfVoid)
			};			

			
		public static void HandleKill( Mobile victim, Mobile killer )
		{
			PlayerMobile pm = killer as PlayerMobile;
			BaseCreature bc = victim as BaseCreature;

			if( pm == null || bc == null || !killer.InRange( victim, 100 ))
				return;
				
			//check if they are close to the location of last arty, if yes, no arty for them
			int xoffset = pm.X-pm.AoA_lastspot.X;
			int yoffset = pm.Y-pm.AoA_lastspot.Y;
			if(xoffset<0)xoffset*=-1;
			if(yoffset<0)yoffset*=-1;
			
			if(xoffset<5 && yoffset<5 && pm.Map==pm.AoA_lastmap)return;				

			if( bc.Controlled || bc.Owners.Count > 0)
				return; 
				
			double luck= (double)pm.Luck;
			if(luck>1000)luck=1000;
			
			double fame = bc.Fame;			
			
			bool ispeerless=(bc is DreadHorn || bc is ChiefParoxysmus || bc is MonstrousInterredGrizzle || bc is LadyMelisande || bc is Travesty|| bc is ShimmeringEffusion);
			
			double chance = ispeerless ? 0.10 : (1 / ( Math.Max( 10, 100 * ( 0.83 - Math.Round( Math.Log( Math.Round( (fame) / 3000, 3 ) + 0.001, 10 ), 3 ) ) ) * ( 100 - Math.Sqrt( luck ) ) / 100.0 )/2);
			
			if(chance>0.10)chance=0.10; 
			
			if(bc.ArtyChance>0)chance=bc.ArtyChance;
			
			chance+= chance*(luck/3000);
			
					
		
			if(pm.showartychance)pm.SendMessage(52,"ML Minor artifact chance: {0}%" ,Math.Round(chance*100,3)); 

			if(chance>Utility.RandomDouble())
			{
				Item i = null;
				
				try
				{
					i = Activator.CreateInstance( m_mlmartys[Utility.Random( m_mlmartys.Length )] ) as Item;
				}
				catch
				{ }

				if( i != null )
				{
				pm.AoA_lastspot=pm.Location;
				pm.AoA_lastmap=pm.Map;				
						
						pm.SendMessage(200, "For your valor in combating the fallen beast, a special artifact has been bestowed on you." );				
				
					if( !pm.AddToBackpack( i ) )
					{										
						if(pm.BankBox!=null)
						{
						 pm.BankBox.AddItem( i ); //I assume this function does not check if it fits, considering its void, not bool
						 pm.SendMessage("As your backpack is full, your artifact has been placed in your bank box" );
						}
						else
						{
						pm.SendMessage("As your backpack is full and bank is non existant, your artifact has been placed at your feet" );
						i.MoveToWorld(pm.Location,pm.Map);
						}
					}
				 }
				 
			}
		}
	}
}



