/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on [date]
Filepath: scripts\_custom\events and scenarios\misc\christmas\ElfAssassinGate.cs
Lines of code: 82
***********************************************************/


using System;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{

		public class ElfAssassinGate : Static
		{
			[Constructable]
			public ElfAssassinGate() : base(8148)
			{
				Hue=37;
				InternalTimer t = new InternalTimer( this );
				t.Start();
			}
			
			public override bool DisplayWeight { get { return false; } }
			
			
			public void SpawnEvil()
			{
				Mobile spawn=null;
				
				for(int i=Utility.Random(9)+1;i>0;i--)
				{
					switch(Utility.Random(5))
					{
						case 0:spawn= new DarkAssassinElfArcher();break;
						case 1:spawn= new DarkElfTrooper();break;
						case 2:
						case 3:
						case 4: spawn= new DarkAssassinElfFencer();break;
					}
					
					if(spawn==null)continue;
					
					spawn.Hidden=true;
					spawn.MoveToWorld(this.Location,this.Map);						
				}
				Effects.PlaySound( spawn.Location, spawn.Map, 0x1FE );			
			}

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

			public override void Serialize( GenericWriter writer )
			{
				base.Serialize( writer );
			}

			public override void Deserialize( GenericReader reader )
			{
				base.Deserialize( reader );

				Delete();
			}

			private class InternalTimer : Timer
			{
				private ElfAssassinGate m_Item;
				int stage;
				
				DateTime expire;

				public InternalTimer( ElfAssassinGate item ) : base(TimeSpan.FromSeconds(0.1),  TimeSpan.FromSeconds( 1 ) )
				{
					Priority = TimerPriority.TwentyFiveMS;
					m_Item = item;
					expire=DateTime.Now+TimeSpan.FromSeconds(30);
					stage=0;
				}

				protected override void OnTick()
				{					
					if(stage==0)Effects.PlaySound( m_Item.Location, m_Item.Map, 0x20E );
					
					stage++;
										
					if((stage>3 && stage<5 && 0.78>Utility.RandomDouble()) || stage==5)
					{
						m_Item.SpawnEvil();
						stage=6;
					}
					else if(0.08>Utility.RandomDouble() && (stage>40))
					{
						m_Item.SpawnEvil();					
						stage=1;
					}					
					
					if(DateTime.Now>expire)
					{
						m_Item.Delete();
						Stop();
					}
				}
			}
		}
}