/**********************************************************
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\Regular\WaterFiend.cs
Lines of code: 205
***********************************************************/


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

namespace Server.Mobiles
{
	[CorpseName( "a water fiend corpse" )]
	public class WaterFiend : BaseCreature
	{
	
		private ArrayList spawns = new ArrayList();
		
		[Constructable]
		public WaterFiend() : base( AIType.AI_Melee, FightMode.Closest, 18, 1, 0.2, 0.4  )
		{
			Name = "a water fiend";
			Hue = 286;
			Body = 74;
			BaseSoundID = 422;

			SetStr( 169, 175 );
			SetDex( 140, 145 );
			SetInt( 60, 76 );

			SetHits( 145, 200 );
			SetMana( 76 );

			SetDamage( 22, 28 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 60, 66 );
			SetResistance( ResistanceType.Fire, 50, 57 );
			SetResistance( ResistanceType.Cold, 26, 33 );
			SetResistance( ResistanceType.Poison, 29, 34 );
			SetResistance( ResistanceType.Energy, 23, 35 );

			SetSkill( SkillName.MagicResist, 112.8, 119.6 );
			SetSkill( SkillName.Tactics, 108.1, 112.5 );
			SetSkill( SkillName.Wrestling, 118.3, 120.0 );

			Fame = 2500;
			Karma = -2500;

			VirtualArmor = 50;
		}
		
		public override void OnDeath( Container c )
		{
			if ( Utility.Random( 20 ) == 0 )
			{		
				Item item;

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

				c.DropItem( item );
			}

			base.OnDeath( c );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich );
			AddLoot( LootPack.Average, 2 );
		}
		public override int Meat{ get{ return 1; } }
		public override int Hides{ get{ return 4; } }
		public override HideType HideType{ get{ return HideType.Spined; } }
		public override bool CantbeSupreme { get { return true;} }
		public override bool IsMLCreature { get { return true;} } 
		
		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() < 4 && 0.25 > Utility.RandomDouble())
			{
				Mobile spawn;
			
				if (GetLiveSpawns()==3)
				{
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);				
					caster.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = caster;
				}
				else if (GetLiveSpawns()==2)
				{
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);			
					caster.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = caster;
				}
				else if (GetLiveSpawns()==1)
				{
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					caster.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = caster;
				}
				else if (GetLiveSpawns()==0)
				{
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new FiendEnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					caster.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = caster;
				}
			}

			base.OnDamagedBySpell( caster );
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
		
			if ( attacker != this && GetLiveSpawns() < 4 && 0.25 > Utility.RandomDouble())
			{
				Mobile spawn;
			
				if (GetLiveSpawns()==3)
				{
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);			
					attacker.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = attacker;
				}
				else if (GetLiveSpawns()==2)
				{
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);				
					attacker.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = attacker;
				}
				else if (GetLiveSpawns()==1)
				{
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);				
					attacker.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = attacker;
				}
				else if (GetLiveSpawns()==0)
				{
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new EnchantedBubble();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);				
					attacker.SendMessage( "The fiend enchants the water around him" );
					spawn.Combatant = attacker;
				}
			}
			base.OnGotMeleeAttack( attacker );
		}

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