/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-25-2011 07:40:03pm
Filepath: scripts\Mobiles\Monsters\AOS\DemonKnight.cs
Lines of code: 220

Description: 

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


using System;
using System.Collections;
using Server;
using Server.Items;
using System.Collections.Generic;

namespace Server.Mobiles
{
	[CorpseName( "a daemon knight corpse" )]
	public class DemonKnight : BaseCreature
	{
		public override bool IgnoreYoungProtection { get { return Core.ML; } }

		public static Type[] ArtifactRarity11 { get { return m_ArtifactRarity11; } }


		public static Type[] m_ArtifactRarity11 = new Type[]
			{
				typeof( LegacyOfTheDreadLord ),
				typeof( TheDragonSlayer ),
				typeof( ArmorOfFortune ),
				typeof( GauntletsOfNobility ),
				typeof( HelmOfInsight ),
				typeof( HolyKnightsBreastplate ),
				typeof( JackalsCollar ),
				typeof( LeggingsOfBane ),
				typeof( MidnightBracers ),
				typeof( OrnateCrownOfTheHarrower ),
				typeof( ShadowDancerLeggings ),
				typeof( TunicOfFire ),
				typeof( VoiceOfTheFallenKing ),
				typeof( BraceletOfHealth ),
				typeof( OrnamentOfTheMagician ),
				typeof( RingOfTheElements ),
				typeof( RingOfTheVile ),
				typeof( Aegis ),
				typeof( ArcaneShield ),
				typeof( AxeOfTheHeavens ),
				typeof( BladeOfInsanity ),
				typeof( BoneCrusher ),
				typeof( BreathOfTheDead ),
				typeof( Frostbringer ),
				typeof( SerpentsFang ),
				typeof( StaffOfTheMagi ),
				typeof( TheBeserkersMaul ),
				typeof( TheDryadBow ),
				typeof( TheTaskmaster ),
				typeof( DivineCountenance ),
				typeof( HatOfTheMagi ),
				typeof( HuntersHeaddress ),
				typeof( SpiritOfTheTotem ),
				typeof( HolyKnightsCloak),
				typeof( RedDevilsDominion),
				typeof( TheAngelicRestitution),
				typeof( MagesLexicon),
				typeof( LifelessWhisper),
				typeof( TheGodsWrath),
				typeof( TheRevelationOfVirtue)
			};

		public static Item CreateRandomArtifact()
		{
			if ( !Core.AOS )
				return null;

			return Loot.Construct( m_ArtifactRarity11[Utility.Random(m_ArtifactRarity11.Length)] );
		}

		//main arty stuff ---------------------------------------
		public static void GiveArtifact(Mobile boss)
		{
			if(boss.Region!=null && !boss.Region.CanSpawnArtifacts())
				return;		
		
			ArrayList toGive = new ArrayList();
			List<DamageStore> rights = BaseCreature.GetLootingRights( boss.DamageEntries, boss.HitsMax );

			for ( int i = rights.Count - 1; i >= 0; --i )
			{
				DamageStore ds = rights[i];
				if ( ds.m_HasRight )	toGive.Add( ds.m_Mobile );
			}
			if ( rights.Count == 0 )return;	

			int given=0;
			
			for(int i=0;i<rights.Count;i++)
			{
				Mobile m = rights[i].m_Mobile;			
				PlayerMobile pm = m as PlayerMobile;
				
				int luck=m.Luck;
				if(luck>1500)luck=1500;			
				
				int chance=0;
				
				if ( boss is DemonKnight )
					chance = 3500 + (luck / 5); 
				else
					chance = 750 + (luck / 10);
				
				pm.GauntKills++;
				
				chance+=(pm.GauntKills*30);
				
				if(chance>10000)chance=10000;
			
     			if(pm.showartychance)pm.SendMessage(52,"Gaunt artifact chance: {0}% ({1} kills since last arty)" ,Math.Round((double)((double)chance/1000),2),pm.GauntKills); 
						
				if((chance/((given+1)*5))>Utility.Random(100000)) 
				{
					given++;
					Item artifact =  CreateRandomArtifact();			
					m.SendMessage(200,"For your valor in combating the fallen beast, a special artifact has been bestowed on you.");
					pm.GauntKills=0;
					Container pack = m.Backpack;
					if ( pack == null || !pack.TryDropItem( m, artifact, false ) )
					m.BankBox.DropItem( artifact );			
				}
			}
			
		}//end main arty stuff------------------------------------------		
		
		

		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 3 ) )
			{
				default:
				case 0: return WeaponAbility.DoubleStrike;
				case 1: return WeaponAbility.WhirlwindAttack;
				case 2: return WeaponAbility.CrushingBlow;
			}
		}

		public override void OnDeath( Container c )
		{
			base.OnDeath( c );

/*			if ( !Summoned && !NoKillAwards && DemonKnight.CheckArtifactChance( this ) )
				DemonKnight.DistributeArtifact( this );*/
				
		GiveArtifact(this);	
		}

		[Constructable]
		public DemonKnight() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = NameList.RandomName( "demon knight" );
			Title = "the Dark Father";
			Body = 318;
			BaseSoundID = 0x165;

			SetStr( 500 );
			SetDex( 100 );
			SetInt( 1000 );

			SetHits( 30000 );
			SetMana( 5000 );

			SetDamage( 17, 21 );

			SetDamageType( ResistanceType.Physical, 20 );
			SetDamageType( ResistanceType.Fire, 20 );
			SetDamageType( ResistanceType.Cold, 20 );
			SetDamageType( ResistanceType.Poison, 20 );
			SetDamageType( ResistanceType.Energy, 20 );

			SetResistance( ResistanceType.Physical, 30 );
			SetResistance( ResistanceType.Fire, 30 );
			SetResistance( ResistanceType.Cold, 30 );
			SetResistance( ResistanceType.Poison, 30 );
			SetResistance( ResistanceType.Energy, 30 );

			SetSkill( SkillName.DetectHidden, 80.0 );
			SetSkill( SkillName.EvalInt, 100.0 );
			SetSkill( SkillName.Magery, 100.0 );
			SetSkill( SkillName.Meditation, 120.0 );
			SetSkill( SkillName.MagicResist, 150.0 );
			SetSkill( SkillName.Tactics, 100.0 );
			SetSkill( SkillName.Wrestling, 120.0 );
			
			SetSkill( SkillName.Necromancy, 100, 120.0 );
			SetSkill( SkillName.SpiritSpeak,100, 120.0 );

			Fame = 28000;
			Karma = -28000;

			VirtualArmor = 64;
			
			FollowersMax=20;			
			
			if(0.2>Utility.RandomDouble())	PackItem(new RandomTalisman());
		}

		public override void GenerateLoot()
		{		    
			AddLoot( LootPack.SuperBoss, 7 );
			AddLoot( LootPack.HighScrolls, Utility.RandomMinMax( 6, 60 ) );
		}

		public override bool BardImmune{ get{ return !Core.SE; } }
		public override bool Unprovokable{ get{ return Core.SE; } }
		public override bool Uncalmable{ get{ return Core.SE; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override int SuperAI_DelayMax{ get{ return 0; } }	
		public override double TargetTamerChance { get { return 0.02; }}		

		public override int TreasureMapLevel{ get{ return 1; } }

		private static bool m_InHere;

		public override void OnDamage( int amount, Mobile from, bool willKill )
		{
			if ( from != null && from != this && !m_InHere )
			{
				m_InHere = true;
				AOS.Damage( from, this, Utility.RandomMinMax( 8, 20 ), 100, 0, 0, 0, 0 );

				MovingEffect( from, 0xECA, 10, 0, false, false, 0, 0 );
				PlaySound( 0x491 );

				if ( 0.05 > Utility.RandomDouble() )
					Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerStateCallback( CreateBones_Callback ), from );

				m_InHere = false;
			}
		}

		public virtual void CreateBones_Callback( object state )
		{
			Mobile from = (Mobile)state;
			Map map = from.Map;

			if ( map == null )
				return;

			int count = Utility.RandomMinMax( 1, 3 );

			for ( int i = 0; i < count; ++i )
			{
				int x = from.X + Utility.RandomMinMax( -1, 1 );
				int y = from.Y + Utility.RandomMinMax( -1, 1 );
				int z = from.Z;

				if ( !map.CanFit( x, y, z, 16, false, true ) )
				{
					z = map.GetAverageZ( x, y );

					if ( z == from.Z || !map.CanFit( x, y, z, 16, false, true ) )
						continue;
				}

				UnholyBone bone = new UnholyBone();

				bone.Hue = 0;
				bone.Name = "unholy bones";
				bone.ItemID = Utility.Random( 0xECA, 9 );

				bone.MoveToWorld( new Point3D( x, y, z ), map );
			}
		}

		public DemonKnight( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
		}
	}
}