/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\Event System\items\traps\MortalSpikeTrap.cs
Lines of code: 128
***********************************************************/


using System;
using Server;
using Server.Network;

namespace Server.Items
{
	public enum MortalSpikeTrapType
	{
		WestWall,
		NorthWall,
		WestFloor,
		NorthFloor
	}

	public class MortalSpikeTrap : BaseTrap
	{
		[CommandProperty( AccessLevel.GameMaster )]
		public MortalSpikeTrapType Type
		{
			get
			{
				switch ( ItemID )
				{
					case 4360: case 4361: case 4366: return MortalSpikeTrapType.WestWall;
					case 4379: case 4380: case 4385: return MortalSpikeTrapType.NorthWall;
					case 4506: case 4507: case 4511: return MortalSpikeTrapType.WestFloor;
					case 4512: case 4513: case 4517: return MortalSpikeTrapType.NorthFloor;
				}

				return MortalSpikeTrapType.WestWall;
			}
			set
			{
				bool extended = this.Extended;

				ItemID = ( extended ? GetExtendedID( value ) : GetBaseID( value ) );
			}
		}

		public bool Extended
		{
			get{ return ( ItemID == GetExtendedID( this.Type ) ); }
			set
			{
				if ( value )
					ItemID = GetExtendedID( this.Type );
				else
					ItemID = GetBaseID( this.Type );
			}
		}

		public static int GetBaseID( MortalSpikeTrapType type )
		{
			switch ( type )
			{
				case MortalSpikeTrapType.WestWall: return 4360;
				case MortalSpikeTrapType.NorthWall: return 4379;
				case MortalSpikeTrapType.WestFloor: return 4506;
				case MortalSpikeTrapType.NorthFloor: return 4512;
			}

			return 0;
		}

		public static int GetExtendedID( MortalSpikeTrapType type )
		{
			return GetBaseID( type ) + GetExtendedOffset( type );
		}

		public static int GetExtendedOffset( MortalSpikeTrapType type )
		{
			switch ( type )
			{
				case MortalSpikeTrapType.WestWall: return 6;
				case MortalSpikeTrapType.NorthWall: return 6;

				case MortalSpikeTrapType.WestFloor: return 5;
				case MortalSpikeTrapType.NorthFloor: return 5;
			}

			return 0;
		}

		[Constructable]
		public MortalSpikeTrap() : this( MortalSpikeTrapType.WestFloor )
		{
			Hue = 2213;
		}

		[Constructable]
		public MortalSpikeTrap( MortalSpikeTrapType type ) : base( GetBaseID( type ) )
		{
			Hue = 2213;
		}

		public override bool PassivelyTriggered{ get{ return false; } }
		public override TimeSpan PassiveTriggerDelay{ get{ return TimeSpan.Zero; } }
		public override int PassiveTriggerRange{ get{ return 0; } }
		public override TimeSpan ResetDelay{ get{ return TimeSpan.FromSeconds( 6.0 ); } }

		public override void OnTrigger( Mobile from )
		{
		if (!HarmItem.ShouldHarm(from))return;

			Effects.SendLocationEffect( Location, Map, GetBaseID( this.Type ) + 1, 18, 3, GetEffectHue(), 0 );
			Effects.PlaySound( Location, Map, 0x22C );

			foreach ( Mobile mob in GetMobilesInRange( 0 ) )
			{
				if ( mob.Alive && !mob.IsDeadBondedPet) {
					Spells.SpellHelper.Damage( TimeSpan.FromTicks( 1 ), mob, null, Utility.RandomMinMax( 1, 6 ) * 3 );
					MortalStrike.BeginWound(from, TimeSpan.FromSeconds(6.0));
					from.PlaySound( 0x1E1 );
					from.FixedParticles( 0x37B9, 244, 25, 9944, 31, 0, EffectLayer.Waist );
					from.Say("* Stepping on the spikes has mortally wounded you * ");
				}
			}
			
			Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( OnSpikeExtended ) );
		}

		public virtual void OnSpikeExtended()
		{
			Extended = true;
			Timer.DelayCall( TimeSpan.FromSeconds( 5.0 ), new TimerCallback( OnSpikeRetracted ) );
		}

		public virtual void OnSpikeRetracted()
		{
			Extended = false;
			Effects.SendLocationEffect( Location, Map, GetExtendedID( this.Type ) - 1, 6, 3, GetEffectHue(), 0 );
		}

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

			Extended = false;
		}
	}
}ÿ