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

namespace Server.Mobiles
{
	[CorpseName( "a satyr's corpse" )]
	public class Satyr : BaseCreature
	{
		private DateTime m_NextPickup;

		[Constructable]
		public Satyr() : base( AIType.AI_Animal, FightMode.Evil, 10, 1, 0.2, 0.4 )
		{
			Name = "a satyr";
			Body = 118;
			BaseSoundID = 0x585;

			SetStr( 177, 195 );
			SetDex( 251, 269 );
			SetInt( 153, 170 );

			SetHits( 150, 200 );

			SetDamage( 13, 24 );

			SetSkill( SkillName.MagicResist, 55.0, 65.0 );
			SetSkill( SkillName.Tactics, 80.0, 100.0 );
			SetSkill( SkillName.HandToHand, 80.0, 100.0 );

			Fame = 5000;
			Karma = 5000;

			VirtualArmor = 28;

			Pipes pipe = new Pipes();
			pipe.Name = "satyr pipes";
			PackItem( pipe );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich );
		}

		public override void OnThink()
		{
			if ( DateTime.Now >= m_NextPickup )
			{
				m_NextPickup = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 10, 20 ) );
				Peace( Combatant );
			}
			base.OnThink();
		}

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

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

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

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

		// ------------------------------------------------------------------------------------------------------------------------------------------

		private DateTime m_NextPeace;
		public void Peace( Mobile target )
		{
			if ( target == null || Deleted || !Alive || m_NextPeace > DateTime.Now )
				return;

			PlayerMobile p = target as PlayerMobile;

			if ( p != null && p.PeacedUntil < DateTime.Now && !p.Hidden && CanBeHarmful( p ) )
			{
				p.PeacedUntil = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 45 ) );
				p.SendLocalizedMessage( 500616 ); // You hear lovely music, and forget to continue battling!
				p.FixedParticles( 0x376A, 1, 32, 0x15BD, EffectLayer.Waist );
				p.Combatant = null;
				target.Warmode = false;
				UndressItem( target, Layer.OneHanded );
				UndressItem( target, Layer.TwoHanded );

				PlaySound( Utility.RandomMinMax( 0x58A, 0x58C ) );
			}

			m_NextPeace = DateTime.Now + TimeSpan.FromSeconds( 50 );
		}

		public void UndressItem( Mobile m, Layer layer )
		{
			Item item = m.FindItemOnLayer( layer );

			if ( item != null && item.Movable )
				m.PlaceInBackpack( item );
		}
	}
}