/**********************************************************
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:34pm
Filepath: scripts\_custom\items\10th Anniversary artifacts\AnkhPendantArtifact.cs
Lines of code: 184
***********************************************************/


using Server;
using System;
using Server.Mobiles;
using Server.Regions;

namespace Server.Items
{
	
	public class AnkhPendantArtifact : AnkhPendant
	{
		public override int LabelNumber{ get{ return 1079525; } } 
		
		private DateTime NextAbility;
		private DateTime ExpireDate;

		[Constructable]
		public AnkhPendantArtifact() : base()
		{
			switch(Utility.Random(10))
			{
			case 0: Hue=2425; break;				
			case 1: Hue=1150; break;
			case 2: Hue=2219; break;
			case 3: Hue=2419; break;
			case 4: Hue=2406; break;
			case 5: Hue=2418; break;
			case 6: Hue=2413; break;	
			case 7: Hue=2213; break;	
			case 8: Hue=2207; break;	
			}
		
		}
		
		public void ResetAtts()
		{
			Attributes.RegenMana=0;
			Attributes.RegenStam=0;
			Attributes.RegenHits=0;
			InvalidateProperties();
		}
		
		
		public override void OnDoubleClick(Mobile from)
		{
		if(from==null)return;
		
			if(ParentEntity!=from)
			{
			from.SendMessage("You must equip this to use its special ability");
			return;
			}
			
			if(NextAbility>DateTime.Now)
			{
			from.SendMessage("You must wait about a day to use this ability again.");
			return;			
			}
			
			bool validregion=false;
			
			if(from.Region.IsPartOf("honesty shrine"))
			{
			validregion=true;
			ResetAtts();	
			from.SendMessage("You gain the power of honesty and receive extra mana regeneration");
			Attributes.RegenMana=2;			
			}
			else if(from.Region.IsPartOf("compassion shrine"))
			{
			validregion=true;
			ResetAtts();	
			from.SendMessage("You gain the power of compassion and receive extra hit point regeneration");
			Attributes.RegenHits=2;			
			}
			else if(from.Region.IsPartOf("valor shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of valor and receive extra stamina regeneration");			
			Attributes.RegenStam=2;			
			}
			else if(from.Region.IsPartOf("justice shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of justice and receive extra mana and hit point regeneration");			
			Attributes.RegenMana=1;			
			Attributes.RegenHits=1;				
			if(0.25>Utility.RandomDouble() && 0.5>Utility.RandomDouble())Attributes.RegenMana+=1;
			else if(0.25>Utility.RandomDouble())Attributes.RegenHits+=1;			
			}
			else if(from.Region.IsPartOf("sacrifice shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of sacrifice and receive extra stamina and hit point regeneration");			
			Attributes.RegenStam=1;			
			Attributes.RegenHits=1;				
			if(0.25>Utility.RandomDouble() && 0.5>Utility.RandomDouble())Attributes.RegenStam+=1;
			else if(0.25>Utility.RandomDouble())Attributes.RegenHits+=1;		
			}
			else if(from.Region.IsPartOf("honor shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of honor and receive extra mana and stamina regeneration");
			
			Attributes.RegenStam=1;			
			Attributes.RegenMana=1;				
			if(0.25>Utility.RandomDouble() && 0.5>Utility.RandomDouble())Attributes.RegenStam+=1;
			else if(0.25>Utility.RandomDouble())Attributes.RegenMana+=1;		
			}
			else if(from.Region.IsPartOf("spirituality shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of spirituality and receive extra regenerations");
			
			Attributes.RegenStam=1;			
			Attributes.RegenMana=1;			
			Attributes.RegenHits=1;			
			
			if(0.08>Utility.RandomDouble() && 0.3>Utility.RandomDouble())Attributes.RegenStam+=1;
			else if(0.08>Utility.RandomDouble() && 0.3>Utility.RandomDouble())Attributes.RegenMana+=1;	
			else if(0.08>Utility.RandomDouble())Attributes.RegenHits+=1;	
			}	
			else if(from.Region.IsPartOf("humility shrine"))
			{
			validregion=true;			
			ResetAtts();	
			from.SendMessage("You gain the power of humility and receive an extra regeneration");
			
				switch(Utility.Random(3))
				{
				case 0: Attributes.RegenStam=3;			break;
				case 1: Attributes.RegenMana=3;			break;
				case 2: Attributes.RegenHits=3;				break;
				}			
			}
			else	from.SendMessage("You must be near a shrine to use this ability.");


		if(validregion)
		{
			NextAbility=DateTime.Now+TimeSpan.FromDays(1);
			ExpireDate=DateTime.Now+TimeSpan.FromHours(1);
			
			from.PlaySound( 0xF6 );
			from.PlaySound( 0x1F7 );
			from.FixedParticles( 0x37C4, 1, 8, 9916, 1151, 3, EffectLayer.Head );
			from.FixedParticles( 0x37C4, 1, 8, 9502, 1151, 4, EffectLayer.Head );		

			new ExpireTimer(this).Start();	
			Modify();
		}
		
		
		InvalidateProperties();
		}

		

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 1 );
			
			writer.Write(NextAbility);
			writer.Write(ExpireDate);						
		}
		
		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			
			if(version>=1)
			{
			NextAbility=reader.ReadDateTime();
			ExpireDate=reader.ReadDateTime();	

			if(ExpireDate>DateTime.Now)new ExpireTimer(this).Start();
			else ResetAtts();
			}
		}
		
		
		
		
		private class ExpireTimer : Timer
		{
			AnkhPendantArtifact m_toexpire;

			public ExpireTimer( AnkhPendantArtifact toexpire ) : base( TimeSpan.FromSeconds( 30 ), TimeSpan.FromMinutes( 1.0 ) )
			{
				m_toexpire=toexpire;

				Priority = TimerPriority.OneMinute;
			}

			protected override void OnTick()
			{
			if(m_toexpire==null || m_toexpire.Deleted)Stop();
			
			if(m_toexpire.ExpireDate<DateTime.Now)
			{
			m_toexpire.ResetAtts();
			
				if(m_toexpire.ParentEntity!=null && m_toexpire.ParentEntity is PlayerMobile)
				{
				PlayerMobile pm = m_toexpire.ParentEntity as PlayerMobile;
				pm.SendMessage("The bonus of your pendant have expired");
				}
			
			Stop();
			}
			


			}
		}		
		
		
		
		
		
	}
	
}