/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-02-2010 02:32:46pm
Filepath: scripts\_custom\mobiles\ml\Dryad.cs
Lines of code: 250
***********************************************************/


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



////Coded by Bartok for Age of Valor shard////


//Resses high karma people
//Peaces + Reduces cast speed + mutes
//Armor come off (Cept jewelry and helmet) equips if you run away
//


namespace Server.Items
{
	public class ExpireArmor : Item
	{
		public Item m_toreplace;
		public bool ForceExpire;
		
		public ExpireArmor(Layer position,int duration,Item toreplace) : base( 0x1DB9 )
		{
			this.Layer=position;
			this.Visible=false;
			m_toreplace=toreplace;
			Movable=false;
			
			new ExpireTimer(this,duration).Start();
		}

		
			private class ExpireTimer : Timer
			{
				private DateTime m_End;
				private ExpireArmor m_item;

				public ExpireTimer( ExpireArmor item,int delay ) : base( TimeSpan.FromSeconds( 1.0 ), TimeSpan.FromSeconds( 1.0 ) )
				{
					m_item=item;
					m_End=DateTime.Now+TimeSpan.FromSeconds(delay);
					Priority = TimerPriority.TwoFiftyMS;
					
					item.Modify();
				}

				protected override void OnTick()
				{
					if(m_item.Deleted)
					{
						Stop();
					}
					else if ( m_End <DateTime.Now || m_item.ForceExpire)
					{
						Item tmp=null;
						Mobile owner=null;
						m_item.Modify();
						
						//safety checks and reassignments (since we'll be deleting the var containing this info)
						if(m_item.m_toreplace!=null)
						{
							tmp=m_item.m_toreplace;
							
							if(m_item.ParentEntity is Mobile)owner=(Mobile)m_item.ParentEntity;
						}
						
						
						//delete invisable armor
						m_item.Delete();					
						
						
						//equip original armor piece
						if(tmp!=null && owner!=null)
						{
							owner.AddItem(tmp);
						}
						
						
						Stop();
					}
				}
			}
		
		
		
		public ExpireArmor( Serial serial ) : base( serial )
		{
		}
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 );
			writer.Write(m_toreplace);
		}
		
		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			m_toreplace = reader.ReadItem();

			new ExpireTimer(this,10).Start();
		}
	}




}


namespace Server.Mobiles
{
	[CorpseName( "a dryad corpse" )]
	public class Dryad : BaseCreature
	{

		[Constructable]
		public Dryad() : base( AIType.AI_Super, FightMode.Evil, 10, 1, 0.2, 0.4 )
		{
			Name = "a dryad";
			Body = 266;

			SetStr( 132, 147 );
			SetDex( 152, 168 );
			SetInt( 251, 272 );

			SetStam( 152, 168 );
			SetMana( 251, 272 );
			SetHits( 304, 316 );

			SetDamage( 28, 40 );
			
			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 41, 50 );
			SetResistance( ResistanceType.Fire, 17, 25 );
			SetResistance( ResistanceType.Cold, 40, 44 );
			SetResistance( ResistanceType.Poison, 34, 40 );
			SetResistance( ResistanceType.Energy, 25, 35 );

			SetSkill( SkillName.Magery, 70.7, 75.2 );
			SetSkill( SkillName.EvalInt, 70.7, 78.7 );
			SetSkill( SkillName.Meditation, 82.9, 89.9 );
			SetSkill( SkillName.MagicResist, 112.7, 117.1 );
			SetSkill( SkillName.Tactics, 71.7, 76.8 );
			SetSkill( SkillName.Wrestling, 72.5, 77.1 );

			Fame = 8500;
			Karma = 8500;
		}

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

		public override bool CanRummageCorpses{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override int TreasureMapLevel{ get{ return 4; } }
		public override bool InitialInnocent{ get{ return true; } }
		
		
		
		public override void OnDamage( int amount, Mobile attacker, bool willKill )
		{
			if(attacker==null)
			{
			base.OnDamage(amount,attacker,willKill);
			return;
			}
		
			if(0.05>Utility.RandomDouble())
			{
			attacker.SendLocalizedMessage(1072066);//You gaze upon the dryad's beauty and are momentarily distracted.
			Server.Spells.Spell.Mute(attacker,6);
			}
			else if(0.05>Utility.RandomDouble())
			{
			attacker.SendLocalizedMessage(1072066);//You gaze upon the dryad's beauty and are momentarily distracted.
			Server.Spells.Spell.Mute(attacker,6,1.7);			
			}
			else if(0.02>Utility.RandomDouble())
			{
			attacker.SendLocalizedMessage(1072197);//The dryad's beauty makes your blood race. Your clothing is too confining.
			DoClothesRemoval(attacker);
			attacker.Pacify( this, DateTime.Now+TimeSpan.FromSeconds(1+Utility.Random(1)) );
			}	
			

		}
		
		
		
		public static void RemoveLayer(Mobile from,Layer layer)
		{
		Item fi = from.FindItemOnLayer(layer);	
		
		if(fi==null)return;
		
		if(fi is ExpireArmor)return;
		
		ExpireArmor ea = new ExpireArmor(layer,30,fi);
		
		from.GiveItem(fi);
		
		from.AddItem(ea);	
		}
		
		public static void ExpireLayer(Mobile from, Layer layer)
		{
		Item ea = from.FindItemOnLayer(layer);	
		
		if(ea==null)return;		
		
		if(ea is ExpireArmor)((ExpireArmor)ea).ForceExpire=true;		
		}
		
		
		
		//both removal and removalexpire should have same layers:
		
		public static void DoClothesRemoval(Mobile from)
		{
		RemoveLayer(from,Layer.Helm);
		RemoveLayer(from,Layer.Neck);		
		RemoveLayer(from,Layer.Arms);
		RemoveLayer(from,Layer.Gloves);	
		RemoveLayer(from,Layer.InnerTorso);
		RemoveLayer(from,Layer.OuterTorso);
		RemoveLayer(from,Layer.Pants);
		RemoveLayer(from,Layer.MiddleTorso);		
		RemoveLayer(from,Layer.Cloak);		
		RemoveLayer(from,Layer.Shoes);		
		RemoveLayer(from,Layer.OuterLegs);		
		RemoveLayer(from,Layer.InnerLegs);		
		RemoveLayer(from,Layer.Waist);	
		}
		
		public static void DoClothesRemovalExpire(Mobile from)
		{
		ExpireLayer(from,Layer.Helm);
		ExpireLayer(from,Layer.Neck);		
		ExpireLayer(from,Layer.Arms);		
		ExpireLayer(from,Layer.Gloves);	
		ExpireLayer(from,Layer.InnerTorso);		
		ExpireLayer(from,Layer.OuterTorso);
		ExpireLayer(from,Layer.Pants);	
		ExpireLayer(from,Layer.MiddleTorso);		
		ExpireLayer(from,Layer.Cloak);		
		ExpireLayer(from,Layer.Shoes);		
		ExpireLayer(from,Layer.OuterLegs);		
		ExpireLayer(from,Layer.InnerLegs);		
		ExpireLayer(from,Layer.Waist);		
		}		
		
		
		
		public override void OnMovement( Mobile m, Point3D oldLocation )
		{
			if(m.AccessLevel>AccessLevel.Player)return;
			
			if(m.Alive && this.ShouldHarm(m) && 0.05>Utility.RandomDouble() && !InRange( oldLocation, 3 ) && InRange( m, 4 ) && InLOS( m ))
			{
			m.SendLocalizedMessage(1072197);//The dryad's beauty makes your blood race. Your clothing is too confining.
			DoClothesRemoval(m);
			m.Pacify( this, DateTime.Now+TimeSpan.FromSeconds(3+Utility.Random(3)) );
			}		
			else if(m.Alive && this.ShouldHarm(m) && InRange( oldLocation, 11 ) && !InRange( m, 10 ) )
			{
			DoClothesRemovalExpire(m);
			}		
		

			if ( InRange( m, 2 ) && !InRange( oldLocation, 2 ) && !InRange( m, 1 ) && InLOS( m ) && m.Player)
			{

				if(!m.Alive && m.Karma<0)
				{
				Say("I do not help evil scum like thee!");
				return;
				}
				else if(!m.Alive && m.Karma>=0)
				{
				m.CloseGump( typeof( ResurrectGump ) );
				m.SendGump( new ResurrectGump( m, ResurrectMessage.Healer ) );
				return;
				}
				
			}
		}
		 
		public override int GetAngerSound()
		{
			return 1405;
		}

		public override int GetIdleSound()
		{
			return 1404;
		}

		public override int GetAttackSound()
		{
			return 1403;
		}

		public override int GetHurtSound()
		{
			return 1406; 
		}

		public override int GetDeathSound()
		{
			return 1402; 
		}

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

	}
}
