using System;
using Server;
using Server.Network;
using Server.Mobiles;

namespace Server.Items
{
	public enum GasTrapType
	{
		NorthWall,
		WestWall,
		Floor
	}

	public class GasTrap : BaseTrap
	{
		private Poison m_Poison;

		[CommandProperty( AccessLevel.GameMaster )]
		public Poison Poison
		{
			get{ return m_Poison; }
			set{ m_Poison = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public GasTrapType Type
		{
			get
			{
				if ( ItemID >= 0x138D && ItemID <= 0x1392 )
					return GasTrapType.WestWall;
				else if ( ItemID >= 0x1387 && ItemID <= 0x138C )
					return GasTrapType.NorthWall;

				return GasTrapType.Floor;
			}
			set
			{
				ItemID = GetBaseID( value );
			}
		}

		public static int GetBaseID( GasTrapType type )
		{
			switch ( type )
			{
				case GasTrapType.NorthWall: return 0x1387;
				case GasTrapType.WestWall: return 0x138D;
			}

			return 0x10B2;
		}

		[Constructable]
		public GasTrap() : this( GasTrapType.Floor )
		{
		}

		[Constructable]
		public GasTrap( GasTrapType type ) : this( type, Poison.Lesser )
		{
		}

		[Constructable]
		public GasTrap(  Poison poison ) : this( GasTrapType.Floor, Poison.Lesser )
		{
		}

		[Constructable]
		public GasTrap( GasTrapType type, Poison poison ) : base( GetBaseID( type ) )
		{
			m_Poison = poison;
			Name = "gas trap";
		}

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

		public override void OnTrigger( Mobile from )
		{
			base.OnTrigger( from );

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

			from.ApplyPoison( from, m_Poison );

			from.LocalOverheadMessage( MessageType.Regular, 0x22, 500855 ); // You are enveloped by a noxious gas cloud!
		}

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

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

			writer.Write( (int) 0 ); // version

			Poison.Serialize( m_Poison, writer );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Poison = Poison.Deserialize( reader );
					break;
				}
			}
		}
	}
}