/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\mobiles\boses\OggraTheBruiser.cs
Lines of code: 203
***********************************************************/


using System;
using System.Collections;
using Server.Items;
using Server.Targeting;
using Server.Misc;
using Server.Engines.CannedEvil;
using Server.Network;

namespace Server.Mobiles
{
	[CorpseName( "the remains of Oggra The Bruiser" )]
	public class OggraTheBruiser : BaseChampion
	{
		public override ChampionSkullType SkullType{ get{ return ChampionSkullType.Orc; } }
		
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 12 ) )
			{
			default:				
			case 0: return WeaponAbility.Dismount;
			case 1: return WeaponAbility.ConcussionBlow;
			case 2: return WeaponAbility.Dismount;
			case 3: return WeaponAbility.CrushingBlow;
			case 4: return WeaponAbility.Dismount;
			case 5: return WeaponAbility.DoubleStrike;
			case 6: return WeaponAbility.Dismount;
			case 7: return WeaponAbility.ParalyzingBlow;
			case 8: return WeaponAbility.ConcussionBlow;
			case 9: return WeaponAbility.Dismount;
			case 10: return WeaponAbility.CrushingBlow;
			case 11: return WeaponAbility.Dismount;
			}
		}	

		[Constructable]
		public OggraTheBruiser() : base( AIType.AI_Super )
		{
			Body = 189;
			Hue = 1157;

			Name = "Oggra The Bruiser";
			BaseSoundID = 0x45A;

			SetStr( 1067, 1095 );
			SetDex( 366, 375 );
			SetInt( 346, 370 );

			SetHits( 4500 );

			SetDamage( 30, 35 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 65, 75 );
			SetResistance( ResistanceType.Fire, 60, 70 );
			SetResistance( ResistanceType.Cold, 45, 55 );
			SetResistance( ResistanceType.Poison, 45, 55 );
			SetResistance( ResistanceType.Energy, 45, 55 );

			SetSkill( SkillName.Macing, 110.1, 130.0 );
			SetSkill( SkillName.MagicResist, 140.1, 160.0 );
			SetSkill( SkillName.Tactics, 80.1, 112.0 );
			SetSkill( SkillName.Wrestling, 110.1, 130.0 );
			SetSkill( SkillName.DetectHidden, 110.0, 120.0 );

			Fame = 22500;
			Karma = -22500;

			VirtualArmor = 50;

			PackItem( new ShadowIronOre( 100 ) );
			PackItem( new IronIngot( 50 ) );

			if ( 0.05 > Utility.RandomDouble() )
				PackItem( new OrcishKinMask() );

			if ( 0.2 > Utility.RandomDouble() )
				PackItem( new BolaBall() );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.FilthyRich );
			AddLoot( LootPack.UltraRich, 4 );
			
			if(0.05>Utility.RandomDouble())
			{
				switch(Utility.Random(2))
				{
				case 0:PackItem(new OggraSkullCrusher());break;
				case 1:PackItem(new SashOfTheOrcishScourge());break;			
				}
			}	
		}

		public override bool BardImmune{ get{ return !Core.AOS; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override int Meat{ get{ return 2; } }
		public override bool AlwaysMurderer{ get{ return true; } }
		public override bool AutoDispel{ get{ return true; } }
		public override double AutoDispelChance{ get{ return 0.2; } }
		public override bool ShowFameTitle{ get{ return false; } }
		public override bool ClickTitle{ get{ return false; } }
		public override bool CanRummageCorpses{ get{ return true; } }

		public override OppositionGroup OppositionGroup
		{
			get{ return OppositionGroup.SavagesAndOrcs; }
		}

		public override bool IsEnemy( Mobile m )
		{
			if ( m.Player && m.FindItemOnLayer( Layer.Helm ) is OrcishKinMask )
				return false;

			return base.IsEnemy( m );
		}

		public override void AggressiveAction( Mobile aggressor, bool criminal )
		{
			base.AggressiveAction( aggressor, criminal );

			Item item = aggressor.FindItemOnLayer( Layer.Helm );

			if ( item is OrcishKinMask )
			{
				AOS.Damage( aggressor, 50, 0, 100, 0, 0, 0 );
				item.Delete();
				aggressor.FixedParticles( 0x36BD, 20, 10, 5044, EffectLayer.Head );
				aggressor.PlaySound( 0x307 );
			}
		}

		public override void OnDamagedBySpell( Mobile caster )
		{
			if ( caster == this )
				return;


			if(caster!=null && 0.7 >= Utility.RandomDouble() && this.InLOS(caster))
				SpawnOrcLord( caster );
		}

		public void SpawnOrcLord( Mobile target )
		{
			Map map = target.Map;

			if ( map == null )
				return;

			int orcs = 0;

			foreach ( Mobile m in this.GetMobilesInRange( 10 ) )
			{
				if ( m is OrcishLord )
					++orcs;
			}

			if ( orcs < 70 )
			{
				BaseCreature orc = new OggraOrcishLord();

				SetTempSummon(this,orc);

				Point3D loc = target.Location;
				bool validLocation = false;

				for ( int j = 0; !validLocation && j < 10; ++j )
				{
					int x = target.X + Utility.Random( 3 ) - 1;
					int y = target.Y + Utility.Random( 3 ) - 1;
					int z = map.GetAverageZ( x, y );

					if ( validLocation = map.CanFit( x, y, this.Z, 16, false, false ) )
						loc = new Point3D( x, y, Z );
					else if ( validLocation = map.CanFit( x, y, z, 16, false, false ) )
						loc = new Point3D( x, y, z );
				}

				orc.MoveToWorld( loc, map );
				orc.Combatant = target;
			}
		}

		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{
			if(attacker!=null && attacker is BaseCreature && 0.4 >= Utility.RandomDouble())
			{
				if(((BaseCreature)attacker).ControlMaster!=null && this.InLOS(((BaseCreature)attacker).ControlMaster))
				{
					SpawnOrcLord(((BaseCreature)attacker).ControlMaster);
				}
				else if(((BaseCreature)attacker).SummonMaster!=null && this.InLOS(((BaseCreature)attacker).SummonMaster))
				{
					SpawnOrcLord(((BaseCreature)attacker).SummonMaster);
				}
				
				if ((SummonMaster!=null && !this.InLOS(((BaseCreature)attacker).SummonMaster) ) || (ControlMaster!=null && !this.InLOS(((BaseCreature)attacker).ControlMaster)) )
				{
					AOS.Damage( attacker, this, Utility.RandomMinMax( 100, 110 ), true, 100, 0, 0, 0, 0 );
				}
			}	
				
			base.OnDamage(amount, attacker, willKill );			
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
		
			if (attacker.InRange( this, 1 ) && 0.02 >= Utility.RandomDouble())
			{
				SpawnOrcLord( attacker );
			}
		
			if (!attacker.InRange( this, 4 ) && 0.8 >= Utility.RandomDouble())
			{
				Effects.SendPacket( attacker, attacker.Map, new HuedEffect( EffectType.Moving, Serial.Zero, Serial.Zero, 9564, this.Location, attacker.Location, 10, 0, false, false, 0, 0 ) );
				attacker.SendMessage( "Oggra throws a club at you!");
				AOS.Damage( attacker, this, Utility.RandomMinMax( 25, 35 ), true, 100, 0, 0, 0, 0 );
			}
			
			if (!attacker.InRange( this, 3 ) && 0.3 >= Utility.RandomDouble())
			{
				SpawnOrcLord( attacker );
			}
			if (!attacker.InRange( this, 2 ) && 0.05 >= Utility.RandomDouble())
			{
				SpawnOrcLord( attacker );
			}
		base.OnGotMeleeAttack( attacker );
		}

		public OggraTheBruiser( 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();
		}
	}
}
