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

namespace Server.Mobiles
{
	[CorpseName( "a sphinx corpse" )]
	public class Sphinx : BaseCreature
	{
		[Constructable]
		public Sphinx () : base( AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a sphinx";
			Body = 77;
			BaseSoundID = 0x668;

			SetStr( 176, 205 );
			SetDex( 46, 65 );
			SetInt( 110, 175 );

			SetHits( 106, 123 );

			SetDamage( 8, 14 );

			SetSkill( SkillName.Concentration, 65.1, 80.0 );
			SetSkill( SkillName.Magery, 65.1, 80.0 );
			SetSkill( SkillName.MagicResist, 60.2, 90.0 );
			SetSkill( SkillName.Tactics, 40.1, 60.0 );
			SetSkill( SkillName.HandToHand, 30.1, 40.0 );

			Fame = 3500;
			Karma = -3500;

			VirtualArmor = 40;
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Average );
			AddLoot( LootPack.Meager );
			AddLoot( LootPack.Gems );
			AddLoot( LootPack.LowPotions );
		}

		public static void TurnStone( Mobile from )
		{
			ArrayList list = new ArrayList();

			foreach ( Mobile m in from.GetMobilesInRange( 2 ) )
			{
				if ( m == from || !from.CanBeHarmful( m ) )
					continue;

				if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != ((BaseCreature)from).Team) )
					list.Add( m );
				else if ( m.Player )
					list.Add( m );
			}

			foreach ( Mobile m in list )
			{
				if ( !m.CheckSkill( SkillName.MagicResist, 0, 100 ) )
				{
					from.DoHarmful( m );

					m.PlaySound(0x16B);

					int duration = Utility.RandomMinMax(4, 8);
					m.Paralyze(TimeSpan.FromSeconds(duration));

					m.SendMessage( "You are petrified with fear from the mighty roar!" );
				}
			}
		}

		public override void OnGaveMeleeAttack( Mobile m )
		{
			base.OnGaveMeleeAttack( m );

			if ( 0.1 >= Utility.RandomDouble() )
				TurnStone( this );
		}

		public override void OnGotMeleeAttack( Mobile m )
		{
			base.OnGotMeleeAttack( m );

			if ( 0.1 >= Utility.RandomDouble() )
				TurnStone( this );
		}

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