using System;
using System.Collections.Generic;
using Server.Commands;
using Server.Network;
using Server.Targeting;
using Server.Mobiles;

namespace Server.Items
{
	public class ThruDoor : BaseDoor
	{
		[Constructable]
		public ThruDoor() : this( DoorFacing.WestCW )
		{
		}

		[Constructable]
		public ThruDoor( DoorFacing WestCW ) : base( 1661, 1661, 0xEC, 0xEC, BaseDoor.GetOffset( WestCW ) )
		{
		}

		public bool isMetal( Item door )
		{
			if ( 	door.ItemID == 1661 ||
					door.ItemID == 1663 ||
					door.ItemID == 1741 ||
					door.ItemID == 1743 ||
					door.ItemID == 1677 ||
					door.ItemID == 1679 ||
					door.ItemID == 8181 ||
					door.ItemID == 8183 ||
					door.ItemID == 2092 ||
					door.ItemID == 2094 ||
					door.ItemID == 2132 ||
					door.ItemID == 2134 || 
					door.ItemID == 1653 ||
					door.ItemID == 1655 ||
					door.ItemID == 1733 ||
					door.ItemID == 1735 ||
					door.ItemID == 1669 ||
					door.ItemID == 1671 ||
					door.ItemID == 8173 ||
					door.ItemID == 8175 ||
					door.ItemID == 2084 ||
					door.ItemID == 2086 ||
					door.ItemID == 2124 ||
					door.ItemID == 2126 
				)
				return true;

			return false;
		}

		public bool isWood( Item door )
		{
			if ( 	door.ItemID == 1717 ||
					door.ItemID == 1719 ||
					door.ItemID == 1749 ||
					door.ItemID == 1751 ||
					door.ItemID == 1703 ||
					door.ItemID == 1701 ||
					door.ItemID == 1765 ||
					door.ItemID == 1767 || 
					door.ItemID == 1709 ||
					door.ItemID == 1711 ||
					door.ItemID == 1773 ||
					door.ItemID == 1775 ||
					door.ItemID == 1725 ||
					door.ItemID == 1727 ||
					door.ItemID == 1757 ||
					door.ItemID == 1759
				)
				return true;

			return false;
		}

		public bool isCloth( Item door )
		{
			if ( 	door.ItemID == 0x0DED ||
					door.ItemID == 0x0DEE
				)
				return true;

			return false;
		}

		public bool isFence( Item door )
		{
			if ( 	door.ItemID == 2158 ||
					door.ItemID == 2160 ||
					door.ItemID == 2150 ||
					door.ItemID == 2152 ||
					door.ItemID == 2105 ||
					door.ItemID == 2107 ||
					door.ItemID == 2113 ||
					door.ItemID == 2115
				)
				return true;

			return false;
		}

		public bool isEW( Item door )
		{
			if ( 	door.ItemID == 1661 ||
					door.ItemID == 1663 ||
					door.ItemID == 1741 ||
					door.ItemID == 1743 ||
					door.ItemID == 1677 ||
					door.ItemID == 1679 ||
					door.ItemID == 8181 ||
					door.ItemID == 8183 ||
					door.ItemID == 2092 ||
					door.ItemID == 2094 ||
					door.ItemID == 2132 ||
					door.ItemID == 2134 || 
					door.ItemID == 1709 ||
					door.ItemID == 1711 ||
					door.ItemID == 1773 ||
					door.ItemID == 1775 ||
					door.ItemID == 1725 ||
					door.ItemID == 1727 ||
					door.ItemID == 1757 ||
					door.ItemID == 1759 ||
					door.ItemID == 0x0DEE || 
					door.ItemID == 2158 || 
					door.ItemID == 2160 || 
					door.ItemID == 2113 || 
					door.ItemID == 2115 
				)
				return true;

			return false;
		}

		public bool isNS( Item door )
		{
			if ( 	door.ItemID == 1717 ||
					door.ItemID == 1719 ||
					door.ItemID == 1749 ||
					door.ItemID == 1751 ||
					door.ItemID == 1703 ||
					door.ItemID == 1701 ||
					door.ItemID == 1765 ||
					door.ItemID == 1767 || 
					door.ItemID == 1653 ||
					door.ItemID == 1655 ||
					door.ItemID == 1733 ||
					door.ItemID == 1735 ||
					door.ItemID == 1669 ||
					door.ItemID == 1671 ||
					door.ItemID == 8173 ||
					door.ItemID == 8175 ||
					door.ItemID == 2084 ||
					door.ItemID == 2086 ||
					door.ItemID == 2124 ||
					door.ItemID == 2126 ||
					door.ItemID == 0x0DED ||
					door.ItemID == 2150 ||
					door.ItemID == 2152 ||
					door.ItemID == 2105 ||
					door.ItemID == 2107
				)
				return true;

			return false;
		}

		public Point3D loc( Item door, Mobile from )
		{
			Point3D d = door.Location;
			Point3D p = d;

			if ( isNS( door ) && from.Y > door.Y )
				d = new Point3D( p.X, p.Y-1, p.Z );
			else if ( isNS( door ) && from.Y < door.Y )
				d = new Point3D( p.X, p.Y+1, p.Z );
			else if ( isEW( door ) && from.X < door.X )
				d = new Point3D( p.X+1, p.Y, p.Z );
			else if ( isEW( door ) && from.X > door.X )
				d = new Point3D( p.X-1, p.Y, p.Z );

			return d;
		}

		public override void Use( Mobile from )
		{
			if ( from is PlayerMobile )
			{
				BeginDoor( from );

				int sound = 0;

				if ( isMetal( this ) )
					sound = 0xEC;
				else if ( isWood( this ) )
					sound = 0xEA;
				else if ( isCloth( this ) )
					sound = 0x48;
				else if ( isFence( this ) )
					sound = 0xEB;

				Point3D d = loc( this, from );

				Server.Mobiles.BaseCreature.TeleportPets( from, d, from.Map );
				if ( ItemID != 8611 ){ from.PlaySound( sound ); }
				from.MoveToWorld( d, from.Map );
			}
		}

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

		public override void Serialize( GenericWriter writer ) // Default Serialize method
		{
			base.Serialize( writer );
			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader ) // Default Deserialize method
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
		}
	}
}