/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\ML Peerless + misc areas\Jormundgand\Mobiles\Named\Dolphinus.cs
Lines of code: 178
***********************************************************/


using System;
using Server.Mobiles;
using Server.Items;
using System.Collections;
using Server.Network;
using Server.Targeting;

namespace Server.Mobiles
{
	[CorpseName( "a dolphinus corpse" )]
	public class Dolphinus : BaseCreature
	{
	
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 6 ) )
			{
				default:
				case 0: return WeaponAbility.Dismount;
				case 1: return WeaponAbility.ArmorIgnore;
				case 2: return WeaponAbility.DoubleStrike;
				case 3: return WeaponAbility.ArmorIgnore;
				case 4: return WeaponAbility.Dismount;
				case 5: return WeaponAbility.DoubleStrike;
			}
		}
		
		private ArrayList spawns = new ArrayList();
		
		[Constructable]
		public Dolphinus()
			: base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "Dolphinus";
			Body = 0x97;
			Hue = 132;
			
			SetStr( 321, 349 );
			SetDex( 300, 385 );
			SetInt( 396, 410 );

			SetHits( 687, 786 );

			SetDamage( 10, 12 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 70, 80 );
			SetResistance( ResistanceType.Fire, 70, 80 );
			SetResistance( ResistanceType.Cold, 70, 80 );
			SetResistance( ResistanceType.Poison, 10, 15 );
			SetResistance( ResistanceType.Energy, 10, 15 );

			SetSkill( SkillName.MagicResist, 15.1, 20.0 );
			SetSkill( SkillName.Tactics, 110 );
			SetSkill( SkillName.Wrestling, 120 );
			SetSkill( SkillName.Healing, 90.0, 100.0 );
			SetSkill( SkillName.Anatomy, 90.0, 120.0 );

			Fame = 8000;
			Karma = -8000;

			VirtualArmor = 16;
			CanSwim = true;
			CantWalk = false;
		}
		
		public override void GenerateLoot()
		{
			AddLoot( LootPack.FilthyRich, 1 );
			AddLoot( LootPack.Rich, 2 );
		}
		
		public override void OnDeath( Container c )
		{
			if ( Utility.Random( 3 ) == 0 )
			{		
				Item item;

				switch ( Utility.Random( 1 ))
				{
								default:
					case 1: item = new DolphinusKey(); break;
							}

				c.DropItem( item );
			}

			base.OnDeath( c );
		}

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

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

		public override void OnDoubleClick( Mobile from )
		{
			if( from.AccessLevel >= AccessLevel.GameMaster )
				Jump();
		}

		public virtual void Jump()
		{
			if( Utility.RandomBool() )
				Animate( 3, 16, 1, true, false, 0 );
			else
				Animate( 4, 20, 1, true, false, 0 );
		}

		public override void OnThink()
		{
			if( Utility.RandomDouble() < .005 ) // slim chance to jump
				Jump();

			base.OnThink();
		}
		
		private int GetLiveSpawns()
		{
		int live=0;
				for( int i = 0; i < spawns.Count; ++i )
                {
                Mobile m = spawns[i] as Mobile;

                if( m == null || m.Deleted || !m.Alive)continue;
				live++;							
                }
				
		return live;
		}
		
		public override void OnDamagedBySpell( Mobile caster )
		{
	
			if ( caster != this && GetLiveSpawns()<3)
			{
				Mobile spawn;
			
				if (GetLiveSpawns()==2)
				{
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					caster.SendMessage( "Dolphinus calls for help" );
					spawn.Combatant = caster;
				}
				else if (GetLiveSpawns()==1)
				{
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					caster.SendMessage( "Dolphinus calls for help" );
					spawn.Combatant = caster;
				}
				else if (GetLiveSpawns()==0)
				{
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new DolphinusRenegadeDolphin();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					caster.SendMessage( "Dolphinus calls for help" );
					spawn.Combatant = caster;
				}
			}

			base.OnDamagedBySpell( caster );
		}
		
		public override bool Unprovokable{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }
		public override double BonusPetDamageScalar{ get{ return 1.5; } }
		public override bool AutoDispel{ get{ return true; } }
		public override double AutoDispelChance{ get{ return 1.0; } }
		public override bool CantbeSupreme{ get{ return true; } }
		public override bool IsMLCreature { get { return true;} } 
		public override bool IsMLBoss { get { return true;} }			
		
		public override bool OnBeforeDeath()
		{
			BaseSoundID = 0x8A;
			
			return base.OnBeforeDeath();
		}	
		
		public override void CheckReflect( Mobile caster, ref bool reflect )
		{
			caster.SendMessage( "Your spell reflects off Dolphinus' skin" );
			reflect = true; 
		}

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