/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-25-2011 07:39:59pm
Filepath: scripts\Engines\artifact systems\Artifacts of Assimilation\artifactsofassimilation.cs
Lines of code: 136

Description: 

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


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 TreasuresOfFelucca
	{
		private static bool m_Enabled = true; 
		public static bool Enabled = true; 


		    public static Type[] m_LesserArtifacts = new Type[]
			{				
				typeof(PyrolisksFuror),
				typeof(SearingPain),
				typeof(KnightsCourage),
				typeof(theblizzard), 
				typeof(ShadowStalker),
				typeof(BootsOfDexterity),
				typeof(TheBetrayer),
				typeof(Infection),
				typeof(DevilsGrasp),
				typeof(tentaclestalon),
				typeof(ArcaneDaemonsHorn),
				typeof(GodOfTheSky),
				typeof(FortunesFavor),
				typeof(DarkAura),
				typeof(Devastation),
				typeof(JungleWalkersBow),
				typeof(TheLongShot),
				typeof(magiciansedge),
				typeof(RedDragonsGrapple),
				typeof(staffofmoses),
				typeof(thevanquisher),				
				typeof(Elegance)
			};			

		  public static Type[] m_GreaterArtifacts = new Type[]
		  {
				typeof(ShroudOfTheDead),
				typeof(ringofthedead),
				typeof(CrystalLadenTome),
				typeof(UnbridledFrenzy),
				typeof(grimreapersstrike),
				typeof(WyvernsBarb),
				typeof(arcaneearrings),
				typeof(charmofthedomesticator),
				typeof(RobeOfAFallenGypsy),
				typeof(HellBlade),
				typeof(PeregrinesDive),
				typeof(CastersBracelet),
				typeof(GazersEye),
				typeof(LifesBarricade),
				typeof(lightningshoes),
				typeof(MagiCollar),
				typeof(OdinsSpear),
				typeof(robeofregen),
				typeof(StitchedLichSkin),
				typeof(tigerteethearrings),
				typeof(YomotsuEldersSleeves),	
				typeof(deathspell)	
		  };			
			

		private static bool CheckLocation( Mobile m )
		{
			return (m.Map == Map.Felucca);
		}

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

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

			if( bc.Controlled || bc.Owners.Count > 0 || bc.Fame < 5000 || pm.Fame<10000)
				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;
				
			double luck= (double)pm.Luck;
			if(luck>1500)luck=1500;
			
			double fame = bc.Fame;			
			
			double chance = 1.1 / ( Math.Max( 10, 100 * ( 0.83 - Math.Round( Math.Log( Math.Round( (fame*1.50) / 6000, 3 ) + 0.001, 10 ), 3 ) ) ) * ( 100 - Math.Sqrt( luck ) ) / 100.0 )/2;
			
			DateTime lastdrop = pm.AoA_Last;
			
			double chancemodifyer=1;
			if(DateTime.Now<(lastdrop + TimeSpan.FromMinutes(5)))	chancemodifyer=0.01; 
			else if(DateTime.Now<(lastdrop + TimeSpan.FromMinutes(30)))	chancemodifyer=0.05;
			else if(DateTime.Now<(lastdrop + TimeSpan.FromHours(5)))	chancemodifyer=0.5;
			else if(DateTime.Now<(lastdrop + TimeSpan.FromDays(2)))	chancemodifyer=0.75;	
			
			chancemodifyer+=0.000003*pm.AoACredits;

			int creditstogive=(int)(fame/7000);
			if(creditstogive>5)creditstogive=5;
			pm.AoACredits+=creditstogive;
			
			if(bc.champmob)chance*=0.25; //lower chance on champ mobs

			if(chance>0.05)chance=0.05; //no more than 5% chance
			
			chance*=chancemodifyer;		//yes I am evil, I put this AFTER the other check. 	
			
			if(chance>0.05)chance=0.05; //check again in case chancemodifyer made it go higher instead of lower		
		
			if(pm.showartychance)pm.SendMessage(52,"AoA chance: {0}%   Modifier: {1}" ,Math.Round(chance*100,3),chancemodifyer); 

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

				if( i != null )
				{
						pm.AoA_Last=DateTime.Now;
						pm.AoA_lastspot=pm.Location;
						pm.AoA_lastmap=pm.Map;
						
						pm.AoACredits=0;
						
						pm.SendMessage(200, "You have been rewarded an artifact of assimilation!" );				
				
					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);
						}
					}
				 }
				 
			}
		}
	}
}



