context: using System;
  using System.Collections.Generic;
  using Server;
  using Server.Commands;
  using Server.Gumps;
  using Server.Mobiles;
  using Server.Network;
  using Server.Spells;
  
  namespace Server.Items
  {
  	public class PublicMoongate : Item
  	{
  		public override bool ForceShowProperties{ get{ return ObjectPropertyList.Enabled; } }
  
  		[Constructable]
  		public PublicMoongate() : base( 0xF6C )
  		{
  			Movable = false;
  			Light = LightType.Circle300;
  		}
  
  		public PublicMoongate( Serial serial ) : base( serial )
  		{
  		}
  
  		public override void OnDoubleClick( Mobile from )
  		{
  			if ( !from.Player )
  				return;
  
  			if ( from.InRange( GetWorldLocation(), 1 ) )
  				UseGate( from );
  			else
  				from.SendLocalizedMessage( 500446 ); // That is too far away.
  		}
  
  		public override bool OnMoveOver( Mobile m )
  		{
  	
  			if ( m.Player )
  			{
  			UseGate( m );
  			}
  
  			return true;
  		
  		}
  
  		public override bool HandlesOnMovement{ get{ return true; } }
  
  		public override void OnMovement( Mobile m, Point3D oldLocation )
  		{
  			if ( m is PlayerMobile )
  			{
  				if ( !Utility.InRange( m.Location, this.Location, 1 ) && Utility.InRange( oldLocation, this.Location, 1 ) )
  					m.CloseGump( typeof( MoongateGump ) );
  			}
  		}
  
  		public bool UseGate( Mobile m )
  		{
  			if ( m.Criminal )
  			{
  				m.SendLocalizedMessage( 1005561, "", 0x22 ); // Thou'rt a criminal and cannot escape so easily.
  				return false;
  			}
  			else if ( SpellHelper.CheckCombat( m ) )
  			{
  				m.SendLocalizedMessage( 1005564, "", 0x22 ); // Wouldst thou flee during the heat of battle??
  				return false;
  			}
  			else if ( m.Spell != null )
  			{
  				m.SendLocalizedMessage( 1049616 ); // You are too busy to do that at the moment.
  				return false;
  			}
  			else
  			{
  				m.CloseGump( typeof( MoongateGump ) );
  				m.SendGump( new MoongateGump( m, this ) );
  
  				if ( !m.Hidden || m.AccessLevel == AccessLevel.Player )
  					Effects.PlaySound( m.Location, m.Map, 0x20E );
  
  				return true;
  			}
  		}
  
  		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();
  		}
  
  		public static void Initialize()
  		{
  			CommandSystem.Register( "MoonGen", AccessLevel.Administrator, new CommandEventHandler( MoonGen_OnCommand ) );
  		}
  
  		[Usage( "MoonGen" )]
  		[Description( "Generates public moongates. Removes all old moongates." )]
  		public static void MoonGen_OnCommand( CommandEventArgs e )
  		{
  			DeleteAll();
  
  			int count = 0;
  
  			count += MoonGen( PMList.Towns ); //Towns
  			count += MoonGen( PMList.Dungeons ); //Dungeons
  			//count += MoonGen( PMList.Ilshenar ); //Ice Island
  			//count += MoonGen( PMList.Malas );
  			//count += MoonGen( PMList.Tokuno );
  
  			World.Broadcast( 0x35, true, "{0} moongates generated.", count );
  		}
  
  		private static void DeleteAll()
  		{
  			List<Item> list = new List<Item>();
  
  			foreach ( Item item in World.Items.Values )
  			{
  				if ( item is PublicMoongate )
  					list.Add( item );
  			}
  
  			foreach ( Item item in list )
  				item.Delete();
  
  			if ( list.Count > 0 )
  				World.Broadcast( 0x35, true, "{0} moongates removed.", list.Count );
  		}
  
  		private static int MoonGen( PMList list )
  		{
  			foreach ( PMEntry entry in list.Entries )
  			{
  				Item item = new PublicMoongate();
  
  				item.MoveToWorld( entry.Location, list.Map );
  
  				
  			}
  
  			return list.Entries.Length;
  		}
  	}
  
  	public class PMEntry
  	{
  		private Point3D m_Location;
  		private string m_DestName;
  
  		public Point3D Location
  		{
  			get
  			{
  				return m_Location;
  			}
  		}
  
  		public string DestName
  		{
  			get
  			{
  				return m_DestName;
  			}
  		}
  
  		public PMEntry( Point3D loc, string name )
  		{
  			m_Location = loc;
  			m_DestName = name;
  		}
  	}
  
  	public class PMList 
  	{
  		private string m_Name;
  		private string m_DestName;
  		
  		private int m_NameHue, m_DestHue;
  		
  		private Map m_Map;
  		
  		private PMEntry[] m_Entries;
  
  		public string DestName
  		{
  			get
  			{
  				return m_DestName;
  			}
  		}
  		public string Name
  		{
  			get
  			{
  				return m_Name;
  			}
  		}
  		
  		public int NameHue
  		{
  			get
  			{
  				return m_NameHue;
  			}
  		}
  
  		public int DestHue
  		{
  			get
  			{
  				return m_DestHue;
  			}
  		}
  
  
  		public Map Map
  		{
  			get
  			{
  				return m_Map;
  			}
  		}
  
  		public PMEntry[] Entries
  		{
  			get
  			{
  				return m_Entries;
  			}
  		}
  
  		public PMList( string name, int namehue, int desthue, Map map, PMEntry[] entries )
  		{
  			m_Map = map;
  			m_Entries = entries;
  			m_Name = name;
  			m_NameHue = namehue;
  			m_DestHue = desthue;
  
  		}
  
  		
  		
  		
  		/*
  		     ** Maximum of: 15 characters(Including Spaces) per PMEntry, 12 PMEntrys  per PMList, 9 PMLists. **
  		     
  		     
  		     
  		   public static readonly PmList CATAGORY NAME =
  		   		new PMList( "CATAGORY NAME AGAIN", CATAGORY NAME Hue, Destinations Hue, Map.DESTINATION MAP, new PMEntry[]
  		   			{
  		   				new PMEntry( new Point3D( X, Y, Z, ), "DESTINATION NAME" ), << After each PMEntry you put a , 
  		   				new PMEntry( new Point3D( X, Y, Z, ), "DESTINATION NAME" )  << Except for the final entry.
  		   			} );
  	 
  		 
  		 
  		*/
  		
  		
  		
  		public static readonly PMList Towns =
  			new PMList( "Towns", 3, 3, Map.Trammel, new PMEntry[]
  				{
  					
  					new PMEntry( new Point3D( 3003, 1031, 0 ), "Britain" ),
  					new PMEntry( new Point3D( 806, 728, 0 ), "Moon" ),
  					new PMEntry( new Point3D( 2429, 874, 3 ), "Yew" ),
  					new PMEntry( new Point3D( 2119, 276, 0 ), "Fawn" ),
  					new PMEntry( new Point3D( 5919, 2881, 0 ), "Dawn" ),
  					new PMEntry( new Point3D( 3313, 2610, 0 ), "Montor East" ),
  					new PMEntry( new Point3D( 3122, 2610, 0 ), "Montor West" ),
  					new PMEntry( new Point3D( 1818, 2232, 0 ), "Pirate Isle" ),
  					new PMEntry( new Point3D( 1656, 1484, 2 ), "Devil Guard" ),
  					new PMEntry( new Point3D( 1449, 3787, 0 ), "Renika" ),
  					new PMEntry( new Point3D( 4514, 1276, 2 ), "Mountain Crest" ),
  					new PMEntry( new Point3D( 902, 2063, 0 ), "Grey" ),
  					new PMEntry( new Point3D( 3717, 1540, 0 ), "Death Gulch" )
  					
  				} );
  
  		public static readonly PMList Dungeons =
  			new PMList( "Dungeons", 38, 38, Map.Trammel, new PMEntry[]
  				{
  					new PMEntry( new Point3D( 1168, 474, 2 ), "Ancient Pyramid" ),
  					new PMEntry( new Point3D( 1022, 1372, 2 ), "Mines of Mornina" ),
  					new PMEntry( new Point3D( 876, 2702, 1 ), "Exodus Dungeon" ),
  					new PMEntry( new Point3D( 1628, 2561, 0 ), "Doom" ),
  					new PMEntry( new Point3D( 3006, 448, 0 ), "Dardins Pit" ),
  					new PMEntry( new Point3D( 3619, 460, 0 ), "Perins Dephts" ),
  					new PMEntry( new Point3D( 3345, 1650, 0 ), "Fires of Hell" ),
  					new PMEntry( new Point3D( 3760, 2041, 0 ), "Clues" ),
  					new PMEntry( new Point3D( 3831, 1502, 0 ), "Time Awaits" ),
  					//new PMEntry( new Point3D( 3016, 1130, 3 ), "Ice Caverns" ),
  					new PMEntry( new Point3D( 1531, 3599, 0 ), "Catacoms" )//,
  					//new PMEntry( new Point3D( 3016, 1130, 3 ), "Britain" )
  					
  					
  					
  				} );
  
  		
  		
  
  		
  		// Put the name of your catagory in one or more of the following lists dependant on who you wish access to your catagory.
  		// For example if your catagory's name was SantaClaus and you wanted it accesable to red players
  		// you would put SantaClaus into the RedList Like so:
  		// public static readonly PMList[] RedLists		= new PMList[] { Felucca, SantaClaus };
  		
  		
  		
  		public static readonly PMList[] UORLists		= new PMList[] { Towns, Dungeons };
  	
  		public static readonly PMList[] RedLists		= new PMList[] { Towns };
  		
  	}
  
  	public class MoongateGump : Gump
  	{
  		private Mobile m_Mobile;
  		private Item m_Moongate;
  		private PMList[] m_Lists;
  
  		public MoongateGump( Mobile mobile, Item moongate ) : base( 100, 100 )
  		{
  			m_Mobile = mobile;
  			m_Moongate = moongate;
  
  			PMList[] checkLists;
  
  			if ( mobile.Player && mobile.Kills >= 5)
  			{
  				checkLists = PMList.RedLists;	
  			}
  			else
  			{ 
  			 checkLists = PMList.UORLists;
  			}
  			
  			
  			// *********** Advanced Programmers Only Past This Point --- EDIT AT OWN RISK!! *************
  
  			
  			
  			
  			m_Lists = new PMList[checkLists.Length];
  
  			for ( int i = 0; i < m_Lists.Length; ++i )
  				m_Lists[i] = checkLists[i];
  
  			for ( int i = 0; i < m_Lists.Length; ++i )
  			{
  				if ( m_Lists[i].Map == mobile.Map )
  				{
  					PMList temp = m_Lists[i];
  
  					m_Lists[i] = m_Lists[0];
  					m_Lists[0] = temp;
  
  					break;
  				}
  			}
  
  			AddPage( 0 );
  
  			//AddBackground( 0, 0, 380, 280, 5054 );
  			AddBackground(0, 0, 335, 375, 2620);
  			AddAlphaRegion( 5, 5, 330, 365 );
  
  			AddButton( 10, 275, 4005, 4007, 1, GumpButtonType.Reply, 0 );
  			//AddHtmlLocalized( 45, 210, 140, 25, 1011036, false, false ); // OKAY
  			AddLabel( 45, 275, 38, "OKAY" );
  
  			AddButton( 10, 300, 4005, 4007, 0, GumpButtonType.Reply, 0 );
  			//AddHtmlLocalized( 45, 235, 140, 25, 1011012, false, false ); // CANCEL
  			AddLabel( 45, 300, 38, "CANCEL" );
  
  			//AddHtmlLocalized( 5, 5, 200, 20, 1012011, false, false ); // Pick your destination:
  
gt:             AddLabel( 190, 5, 1153, "Pick your destination:" );