context: using System;
  using System.Collections.Generic;
  using Server;
  using Server.Mobiles;
  using Server.Spells;
  using Server.Items;
  using Server.Regions;
  using System.Collections;
  using Server.SkillHandlers;
  using Server.Gumps;
  
  namespace Server.Items
  {
  	public class EventRegionControl : RegionControl, IToggle, IToggler
  	{
  		#region Itoggle
  		private Item m_togler;
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Item EventLink
  		{
  			get{ return m_togler;}
  			set
  			{
  				if(value is IToggler || value == null)
  				{
  					m_togler = value;
  				}
  				InvalidateProperties();
  			}
  		}
  		
  		public IToggler Link
  		{
  			get{ return m_togler as IToggler;}
  			set
  			{
  				m_togler = value as Item;
  			}
  		}
  		#endregion
  		
  		#region EventSystem connections
  		private bool m_HandlePlayers = true;
  		
  		[CommandProperty( AccessLevel.GameMaster )]
  		public bool HandlePlayers {
  			get { return m_HandlePlayers; }
  			set
  			{
  				if(m_HandleAllMobiles)
  					value = false;
  				m_HandlePlayers = value;
  			}
  		}
  		private bool m_HandlePets = false;
  		
  		[CommandProperty( AccessLevel.GameMaster )]
  		public bool HandlePets {
  			get { return m_HandlePets; }
  			set
  			{
  				if(m_HandleAllMobiles)
  					value = false;
  				m_HandlePets = value;
  			}
  		}
  		private bool m_HandleAllMobiles = false;
  		
  		[CommandProperty( AccessLevel.GameMaster )]
  		public bool HandleAllMobiles {
  			get { return m_HandleAllMobiles; }
  			set
  			{
  				if(m_HandleAllMobiles)
  					value = false;
  				m_HandleAllMobiles = value;
  			}
  		}
  		private bool m_HandleCreatures = false;
  		
  		[CommandProperty( AccessLevel.GameMaster )]
  		public bool HandleCreatures {
  			get { return m_HandleCreatures; }
  			set
  			{
  				if(m_HandleAllMobiles)
  					value = false;
  				m_HandleCreatures = value;
  			}
  		}
  		
  		private Item m_SignalTogler;
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Item SignalLink
  		{
  			get{ return m_SignalTogler;}
  			set
  			{
  				if(value is IToggler || value ==null)
  				{
  					m_SignalTogler = value;
  				}
  				InvalidateProperties();
  			}
  		}
  		public IToggler signalLink
  		{
  			get{ return m_SignalTogler as IToggler;}
  			set
  			{
  				m_SignalTogler = value as Item;
  			}
  		}
  		
  		
  		private Item m_DeathTogler;
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Item DeathLink
  		{
  			get{ return m_DeathTogler;}
  			set
  			{
  				if(value is IToggler || value == null)
  				{
  					m_DeathTogler = value;
  				}
  				InvalidateProperties();
  			}
  		}
  		public IToggler deathLink
  		{
  			get{ return m_DeathTogler as IToggler;}
  			set
  			{
  				m_DeathTogler = value as Item;
  			}
  		}
  		
  		private Item m_EnterTogler;
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Item EnterLink
  		{
  			get{ return m_EnterTogler;}
  			set
  			{
  				if(value is IToggler || value == null)
  				{
  					m_EnterTogler = value;
  				}
  				InvalidateProperties();
  			}
  		}
  		public IToggler enterLink
  		{
  			get{ return m_EnterTogler as IToggler;}
  			set
  			{
  				m_EnterTogler = value as Item;
  			}
  		}
  		
  		private Item m_ExitTogler;
  		[CommandProperty( AccessLevel.GameMaster )]
  		public Item ExitLink
  		{
  			get{ return m_ExitTogler;}
  			set
  			{
  				if(value is IToggler || value ==null)
  				{
  					m_ExitTogler = value;
  				}
  				InvalidateProperties();
  			}
  		}
  		public IToggler exitLink
  		{
  			get{ return m_ExitTogler as IToggler;}
  			set
  			{
  				m_ExitTogler = value as Item;
  			}
  		}
  		
  		#endregion
  		
  		#region events
  		public void OnEnter(Mobile m)
  		{
  			if (enterLink !=null)
  			{
  				if(HandleAllMobiles)
  					enterLink.Toggle(1,m,Rnd());
  				else if (m_HandlePlayers && m.Player)
  					enterLink.Toggle(1,m,Rnd());
  				else if (m is BaseCreature)
  				{
  					BaseCreature c = m as BaseCreature;
  					if(c.Controlled||c.Summoned)
  					{
  						if(m_HandlePets)
  							enterLink.Toggle(1,m,Rnd());
  					}else if(m_HandleCreatures)
  					{
  						enterLink.Toggle(1,m,Rnd());
  					}
  				}
  			}
  		}
  		public void OnExit(Mobile m)
  		{
  			if (exitLink !=null)
  			{
  				if(HandleAllMobiles)
  					exitLink.Toggle(1,m,Rnd());
  				else if (m_HandlePlayers && m.Player)
  					exitLink.Toggle(1,m,Rnd());
  				else if (m is BaseCreature)
  				{
  					BaseCreature c = m as BaseCreature;
  					if(c.Controlled||c.Summoned)
  					{
  						if(m_HandlePets)
  							exitLink.Toggle(1,m,Rnd());
  					}else if(m_HandleCreatures)
  					{
  						exitLink.Toggle(1,m,Rnd());
  					}
  				}
  			}
  		}
  		public void OnDeath(Mobile m)
  		{
  			if (deathLink !=null)
  			{
  				if(HandleAllMobiles)
  					deathLink.Toggle(1,m,Rnd());
  				else if (m_HandlePlayers && m.Player)
  					deathLink.Toggle(1,m,Rnd());
  				else if (m is BaseCreature)
  				{
  					BaseCreature c = m as BaseCreature;
  					if(c.Controlled||c.Summoned)
  					{
  						if(m_HandlePets)
  							deathLink.Toggle(1,m,Rnd());
  					}else if(m_HandleCreatures)
  					{
  						deathLink.Toggle(1,m,Rnd());
  					}
  				}
  			}
  		}
  		
  		#endregion
  		
  		#region IToggler
  
gt: 		protected int lsid; //last session id