/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\10th Anniversary artifacts\_10thanniversarydropsystem.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 OSI10Anniversary
	{

		    public static Type[] artifacts = new Type[]
			{
				typeof( AnkhPendantArtifact ), typeof( DragonsEnd ), typeof( JaanasStaff ), typeof( KatrinasCrook ),
				typeof( LordBlackthornsExemplar ), typeof( mapoftheknownworld ), typeof( SentinelsGuard ),typeof(TenthAnniversarySculpture),
				typeof(ArmsOfCompassion),typeof(BreastplateOfJustice),typeof(GauntletsOfValor),typeof(GorgetOfHonesty),typeof(HelmOfSpirituality),
				typeof(LegsOfHonor),typeof(SolleretsOfSacrifice),typeof(CloakOfHumility)
			};		
			

		private static bool CheckLocation( Mobile m )
		{
			return (m.Map == Map.Trammel) && (m.Region.IsPartOf("Covetous") || m.Region.IsPartOf("Deceit") || m.Region.IsPartOf("Despise") ||m.Region.IsPartOf("Destard") ||m.Region.IsPartOf("Hythloth") ||m.Region.IsPartOf("Shame") ||m.Region.IsPartOf("Wrong"));
		}

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

			if(pm == null || bc == null || !CheckLocation( bc ) || !CheckLocation( pm )|| !killer.InRange( victim, 100 ) || bc.champmob || pm.Hidden)
				return;

			if( bc.Controlled || bc.Owners.Count > 0)
				return; 
				
			if(killer.Region!=null && !killer.Region.CanSpawnArtifacts())
				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;
				

			//This is the Exponentional regression with only 2 datapoints.
			//A log. func would also work, but it didn't make as much sense.
			//This function isn't OSI exact beign that I don't know OSI's func they used ;p
			int x = pm.TAATotalMonsterFame;

			//const double A = 8.63316841 * Math.Pow( 10, -4 );
			const double A = 0.000023316841;
			//const double B = 4.25531915 * Math.Pow( 10, -6 );
			const double B = 0.00000225531915;

			double chance = A * Math.Pow( 10, B * x );
		
			if(chance>5)chance=5;
		
			if(pm.showartychance)pm.SendMessage(52,"10th anniversary arty chance: {0}%" ,Math.Round(chance*100,3)); 
			
			
			pm.TAATotalMonsterFame += (int)(bc.Fame * (1 + Math.Sqrt( pm.Luck ) / 100));		
			

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

				if( i != null )
				{						
						pm.TAATotalMonsterFame=0;
						
						pm.SendMessage(200, "Happy 10th Anniversary! We have placed a gift for you in your backpack." );
				
					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("Happy 10th Anniversary! We have placed a gift for you 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);
						}
					}
				 }
				 
			}
		}
	}
}



