RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Fully Automated Tournament System

burento

Wanderer
Sorious.. That fix didnt help with the restarting over and over.. i pasted my funding barrel .cs below just incase you see some other error i may have made.

Thanks

Code:
using System;
using Server;
using System.Net;
using Server.Misc;
using Server.Gumps;
using Server.Items;
using Server.Menus;
using Server.Regions;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Accounting;
using System.Collections;
using Server.Scripts.Commands;
using Server.Menus.Questions;

namespace Server.Items 
{
	public class TFundingBarrel : Container
	{
		public override int MaxWeight{ get{ return 0; } }
		public override int DefaultGumpID{ get{ return 0x3E; } }
		public override int DefaultDropSound{ get{ return 0x42; } }

		public override Rectangle2D Bounds
		{
			get
			{
				return new Rectangle2D( 33, 36, 109, 112 );
			}
		}

		private int m_FMax = 100000; //Customize how much money it will take to fund the event here
		private bool m_FReady;
		private int m_FCurrent;
		private MasterTStone m_Link;

		[CommandProperty( AccessLevel.GameMaster )]
		public int FMax
		{
			get
			{
				return m_FMax;
			}

			set
			{
				m_FMax = value;
				UpdateName();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int FCurrent
		{
			get
			{
				return m_FCurrent;
			}

			set
			{
				m_FCurrent = value;
				UpdateName();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool FReady
		{
			get
			{
                if( FCurrent >= FMax )
                    return true;
                else
                    return false;
            }

			set
			{
				m_FReady = value;

				if(value)
				{
					Visible = false;
					Broadcast( "The event barrel has been funded, and a tournament is about to begin." );
				}

				else
				{
					Visible = true;
					Broadcast( String.Format( "The event has finished and the event barrel at {0} ({1}) is now accessible.", this.Location, Region.Find( this.Location, this.Map ).Name ) );
					m_Link.DespawnGates();
				}
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public MasterTStone Link
		{
			get
			{
				return m_Link;
			}

			set
			{
				m_Link = value;
			}
		}

		[Constructable]
		public TFundingBarrel() : base( 0xE77 )
		{
			Name = "Tournament Funding Barrel - " + m_FCurrent + " out of " + m_FMax;
			Movable = false;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if (m_FReady)
			{
				from.SendMessage( 1161, "The event has already been funded, please find the nearest event moongate to enter the tournament." );
			}
			else
			{
				from.SendMessage( 1161, "Drag and drop gold onto this barrel to fund the tournament." );
				from.SendMessage( 1161, "Once the barrel has reached a certain amount, the tournament will start." );
			}
		}

		public override void OnSingleClick( Mobile from )
		{
			UpdateName();

			LabelTo( from, Name );
		}

		public override bool OnDragDrop( Mobile from, Item item )
		{
			base.OnDragDrop( from, item );

			if(m_Link != null)
			{
				if ( item is Gold )
				{
					if (item.Amount >= 100)
					{
						if (m_FCurrent < m_FMax)
						{
							m_FCurrent = (m_FCurrent + item.Amount);

							if (m_FCurrent >= m_FMax)
							{
								m_FCurrent = m_FMax;
								m_FReady = true;
								m_Link.GateTimer();
							}

							item.Delete();

							UpdateName();

							return true;
						}

						else
						{
							from.SendMessage( 1161, "This event is fully funded." );

							return false;
						}
					}

					else
					{
						from.SendMessage( 1161, "You must place at least 100 gold at a time into the barrel." );
						return false;
					}
				}

				else
				{
					from.SendMessage( 1161, "Only gold may be used to fund the tournament." );

					return false;
				}
			}

			else
			{
				from.SendMessage( 1161, "This event barrel is not linked. Please contact a Game Master for assistance." );
				Broadcast( AccessLevel.GameMaster, String.Format( "Funding Barrel at {0} ({1}) is not linked.", this.Location, Region.Find( this.Location, this.Map ).Name ) );

				return false;
			}
		}

		public void Broadcast( string message )
		{
			Broadcast( AccessLevel.Counselor, message );
		}

		public void Broadcast( AccessLevel ac, string message )
		{
			foreach( NetState state in NetState.Instances )
			{
				Mobile m = state.Mobile;

				if ( m != null && m.AccessLevel >= ac )
					m.SendMessage( 1161, "[System Message]: {0}", message );
			}
		}

		public void UpdateName()
		{
			Name = "Tournament Funding Barrel - " + m_FCurrent + " out of " + m_FMax;
		}

		public TFundingBarrel( Serial serial ) : base( serial )
		{

		}

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

			writer.Write( m_Link );

			writer.Write( (int) m_FMax );
			writer.Write( (int) m_FCurrent );
			writer.Write( (bool) m_FReady );
		}

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

			switch ( version )
			{
				case 1:
				{
					m_Link = reader.ReadItem() as MasterTStone;
					break;
				}

				case 0:
				{
					m_FMax = reader.ReadInt();
					m_FCurrent = reader.ReadInt();
					m_FReady = reader.ReadBool();

					break;
				}
			}
		} 
	}
}
 

Jeff

Lord
burento said:
Sorious.. That fix didnt help with the restarting over and over.. i pasted my funding barrel .cs below just incase you see some other error i may have made.

Thanks

Code:
using System;
using Server;
using System.Net;
using Server.Misc;
using Server.Gumps;
using Server.Items;
using Server.Menus;
using Server.Regions;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using Server.Accounting;
using System.Collections;
using Server.Scripts.Commands;
using Server.Menus.Questions;

namespace Server.Items 
{
	public class TFundingBarrel : Container
	{
		public override int MaxWeight{ get{ return 0; } }
		public override int DefaultGumpID{ get{ return 0x3E; } }
		public override int DefaultDropSound{ get{ return 0x42; } }

		public override Rectangle2D Bounds
		{
			get
			{
				return new Rectangle2D( 33, 36, 109, 112 );
			}
		}

		private int m_FMax = 100000; //Customize how much money it will take to fund the event here
		private bool m_FReady;
		private int m_FCurrent;
		private MasterTStone m_Link;

		[CommandProperty( AccessLevel.GameMaster )]
		public int FMax
		{
			get
			{
				return m_FMax;
			}

			set
			{
				m_FMax = value;
				UpdateName();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int FCurrent
		{
			get
			{
				return m_FCurrent;
			}

			set
			{
				m_FCurrent = value;
				UpdateName();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool FReady
		{
			get
			{
                if( FCurrent >= FMax )
                    return true;
                else
                    return false;
            }

			set
			{
				m_FReady = value;

				if(value)
				{
					Visible = false;
					Broadcast( "The event barrel has been funded, and a tournament is about to begin." );
				}

				else
				{
					Visible = true;
					Broadcast( String.Format( "The event has finished and the event barrel at {0} ({1}) is now accessible.", this.Location, Region.Find( this.Location, this.Map ).Name ) );
					m_Link.DespawnGates();
				}
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public MasterTStone Link
		{
			get
			{
				return m_Link;
			}

			set
			{
				m_Link = value;
			}
		}

		[Constructable]
		public TFundingBarrel() : base( 0xE77 )
		{
			Name = "Tournament Funding Barrel - " + m_FCurrent + " out of " + m_FMax;
			Movable = false;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if (m_FReady)
			{
				from.SendMessage( 1161, "The event has already been funded, please find the nearest event moongate to enter the tournament." );
			}
			else
			{
				from.SendMessage( 1161, "Drag and drop gold onto this barrel to fund the tournament." );
				from.SendMessage( 1161, "Once the barrel has reached a certain amount, the tournament will start." );
			}
		}

		public override void OnSingleClick( Mobile from )
		{
			UpdateName();

			LabelTo( from, Name );
		}

		public override bool OnDragDrop( Mobile from, Item item )
		{
			base.OnDragDrop( from, item );

			if(m_Link != null)
			{
				if ( item is Gold )
				{
					if (item.Amount >= 100)
					{
						if (m_FCurrent < m_FMax)
						{
							m_FCurrent = (m_FCurrent + item.Amount);

							if (m_FCurrent >= m_FMax)
							{
								m_FCurrent = m_FMax;
								m_FReady = true;
								m_Link.GateTimer();
							}

							item.Delete();

							UpdateName();

							return true;
						}

						else
						{
							from.SendMessage( 1161, "This event is fully funded." );

							return false;
						}
					}

					else
					{
						from.SendMessage( 1161, "You must place at least 100 gold at a time into the barrel." );
						return false;
					}
				}

				else
				{
					from.SendMessage( 1161, "Only gold may be used to fund the tournament." );

					return false;
				}
			}

			else
			{
				from.SendMessage( 1161, "This event barrel is not linked. Please contact a Game Master for assistance." );
				Broadcast( AccessLevel.GameMaster, String.Format( "Funding Barrel at {0} ({1}) is not linked.", this.Location, Region.Find( this.Location, this.Map ).Name ) );

				return false;
			}
		}

		public void Broadcast( string message )
		{
			Broadcast( AccessLevel.Counselor, message );
		}

		public void Broadcast( AccessLevel ac, string message )
		{
			foreach( NetState state in NetState.Instances )
			{
				Mobile m = state.Mobile;

				if ( m != null && m.AccessLevel >= ac )
					m.SendMessage( 1161, "[System Message]: {0}", message );
			}
		}

		public void UpdateName()
		{
			Name = "Tournament Funding Barrel - " + m_FCurrent + " out of " + m_FMax;
		}

		public TFundingBarrel( Serial serial ) : base( serial )
		{

		}

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

			writer.Write( m_Link );

			writer.Write( (int) m_FMax );
			writer.Write( (int) m_FCurrent );
			writer.Write( (bool) m_FReady );
		}

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

			switch ( version )
			{
				case 1:
				{
					m_Link = reader.ReadItem() as MasterTStone;
					break;
				}

				case 0:
				{
					m_FMax = reader.ReadInt();
					m_FCurrent = reader.ReadInt();
					m_FReady = reader.ReadBool();

					break;
				}
			}
		} 
	}
}
I need to see the Tstone :)
 

burento

Wanderer
Tstone..

Code:
using System;
using Server;
using System.Collections;
using Server.Mobiles;
using Server.Items;
using Server.GateConfig;
using Server.Targeting;
using Server.Gumps;
using Server.Regions;
using Server.Network;
using Server.Spells;
using Server.Spells.Second;
using Server.Spells.Third;

namespace Server.Items
{
	public enum GateSpawn
	{
		All,
		None,
		FeluccaOnly,
		TrammelOnly
	}

	public enum DuelType
	{
		Any,
		Mage,
		Dexxer,
		Tank
	}

	public enum DuelSet
	{
		Allow,
		Sevenx,
		Fivex
	}

	public class MasterTStone : Item
	{
		private GateSpawn m_GateSpawn;
		private DuelType m_DuelType;
		private DuelSet m_DuelSet;
		private Point3D m_TargetDest;
		private Map m_MapDest;
		private ArrayList m_Gates = new ArrayList();
		private bool m_CanHeal;
		private bool m_CanUsePotions;
		private bool m_MagicWeapons;
		private ArrayList m_Players = new ArrayList();
		private ArrayList m_NextRoundPlayers = new ArrayList();
		private Mobile m_Advance;
		private Mobile m_D1;
		private Mobile m_D2;
		private static MasterTStone curStone;
		private int m_ArenaZ;
		private bool m_InUse;
		private int m_MinPlayers;

		private DuelRegion m_DuelingRegion;
		private Rectangle2D m_DuelCoords;
		private BitArray m_RestrictedSpells;
		private BitArray m_RestrictedSkills;

		public bool InUse
		{
			get{ return m_InUse; }
			set{ m_InUse = value; }
		}

		public Mobile Advance
		{
			get{ return m_Advance; }
			set{ m_Advance = value; }
		}

		public Mobile D1
		{
			get{ return m_D1; }
			set{ m_D1 = value; }
		}

		public Mobile D2
		{
			get{ return m_D2; }
			set{ m_D2 = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int ArenaZ
		{
			get{ return m_ArenaZ; }
			set{ m_ArenaZ = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MinPlayers
		{
			get{ return m_MinPlayers; }
			set{ m_MinPlayers = value; }
		}

		public BitArray RestrictedSpells
		{
			get{ return m_RestrictedSpells; }
		}

		public BitArray RestrictedSkills
		{
			get{ return m_RestrictedSkills; }
		}

		public DuelRegion DuelingRegion
		{
			get{ return m_DuelingRegion; }
		}

		public Rectangle2D DuelCoords
		{
			get{ return m_DuelCoords; }
			set{ m_DuelCoords = value; }
		}

		public ArrayList Players
		{
			get{ return m_Players; }
			set{ m_Players = value; }
		}

		public ArrayList NextRoundPlayers
		{
			get{ return m_NextRoundPlayers; }
			set{ m_NextRoundPlayers = value; }
		}

		public ArrayList Gates
		{
			get{ return m_Gates; }
			set{ m_Gates = value; }
		}

		public bool CanHeal
		{
			get
			{
				return m_CanHeal;
			}

			set
			{
				m_CanHeal = value;
			}
		}

		public bool CanUsePotions
		{
			get
			{
				return m_CanUsePotions;
			}

			set
			{
				m_CanUsePotions = value;
			}
		}

		public bool MagicWeapons
		{
			get
			{
				return m_MagicWeapons;
			}

			set
			{
				m_MagicWeapons = value;
			}
		}

		public GateSpawn GateSpawn
		{
			get
			{
				return m_GateSpawn;
			}

			set
			{
				m_GateSpawn = value;
			}
		}

		public DuelType DuelType
		{
			get
			{
				return m_DuelType;
			}

			set
			{
				m_DuelType = value;
			}
		}

		public DuelSet DuelSet
		{
			get
			{
				return m_DuelSet;
			}

			set
			{
				m_DuelSet = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D SpectatorArea
		{
			get
			{
				return m_TargetDest;
			}

			set
			{
				m_TargetDest = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Map MapDest
		{
			get
			{
				return m_MapDest;
			}

			set
			{
				m_MapDest = value;
			}
		}

		public static void Initialize()
		{
			EventSink.Disconnected += new DisconnectedEventHandler( OnDisconnect );
			EventSink.Login += new LoginEventHandler( OnLogin );
			EventSink.PlayerDeath += new PlayerDeathEventHandler( OnDeath );

			try
			{
				ArrayList toDelete = new ArrayList();
				int count = 0;

				foreach( Item i in World.Items.Values )
				{
					if( i is TourneyGate )
					{
						toDelete.Add( i );
					}
				}

				if( toDelete.Count != 0 )
				{
					foreach( TourneyGate t in toDelete )
					{
						t.Delete();
						count++;
					}
				}
			}

			catch
			{
				Console.WriteLine("Milt's tourney system - An error occured while performing a check. If you receive this message, please report the bug.");
			}

			if( curStone != null )
			{
				curStone.UpdateRegion();
			}

			Console.WriteLine("Milt's Auto Tourney System...Initialized.");
		}

		public static void OnLogin( LoginEventArgs e )
		{
			try
			{
				if( curStone.m_Players.Contains( e.Mobile ) )
				{
					e.Mobile.SendMessage( 1161, "Something must have went wrong during one of the tournaments, and you have been removed.");
					curStone.m_Players.Remove( e.Mobile );
				}
			}

			catch{}
		}

		public static void OnDisconnect( DisconnectedEventArgs e )
		{
			try{
			if( curStone.m_Players != null )
			{
				if( curStone.m_Advance != e.Mobile )
				{
					if( curStone.IsParticipant( e.Mobile ) ) //Player is dueling, or waiting to duel
					{
						if( e.Mobile == curStone.m_D1 || e.Mobile == curStone.m_D2 ) //Mobile is Dueling
						{
							if( e.Mobile == curStone.m_D1 )
							{
								curStone.m_D2.SendMessage( 1161, "Your opponent has logged out, thus you win." );

								curStone.EndRound( curStone.m_D2, curStone.m_D1 );
							}

							else if( e.Mobile == curStone.m_D2 )
							{
								curStone.m_D1.SendMessage( 1161, "Your opponent has logged out, thus you win." );

								curStone.EndRound( curStone.m_D1, curStone.m_D2 );
							}
						}

						else //Mobile is waiting to duel
						{
							if(curStone.m_Players.Contains(e.Mobile))
								curStone.m_Players.Remove(e.Mobile);

							if(curStone.m_NextRoundPlayers.Contains(e.Mobile))
								curStone.m_NextRoundPlayers.Remove(e.Mobile);

							if(e.Mobile == curStone.m_Advance)
								curStone.m_Advance = null; //Just in case!
						}
					}
				}
			}

			else //Player was the auto advancer
			{
				curStone.m_Advance = null;
			}
			}

			catch{}
		}

		public static void OnDeath( PlayerDeathEventArgs e )
		{
			try{
			if( curStone.m_Players != null && curStone.m_D1 != null && curStone.m_D2 != null )
			{
				if( curStone.IsParticipant(e.Mobile) ) //Player is dueling, or waiting to duel
				{
					if( curStone.m_D1 != null && curStone.m_D2 != null )
					{
						if( e.Mobile == curStone.m_D1 || e.Mobile == curStone.m_D2 ) //Mobile is Dueling
						{
							e.Mobile.Resurrect();

							curStone.HandleCorpse( e.Mobile );

							if( e.Mobile == curStone.m_D1 )
								curStone.EndRound( curStone.m_D2, curStone.m_D1 );

							else if( e.Mobile == curStone.m_D2 )
								curStone.EndRound( curStone.m_D1, curStone.m_D2 );
						}

						else //Mobile is waiting to duel
						{
							e.Mobile.SendMessage( 1161, "Please do not participate in any combat before game." );
							curStone.Broadcast( String.Format("{0} has died somehow, while waiting for their turn in the tourney. It is recommended that you make it impossible for this to happen, as it can be exploited.", e.Mobile.Name) );

							e.Mobile.Resurrect();

							curStone.HandleCorpse( e.Mobile );
						}
					}
				}
			}
			}

			catch{}
		}

		[Constructable]
		public MasterTStone() : base( 0xEDD )
		{
			Movable = false;
			Name = "MasterTStone";
			Hue = 1108;
			Gates = new ArrayList();
			Players = new ArrayList();
			NextRoundPlayers = new ArrayList();
			MapDest = Map.Felucca;
			CanHeal = true;
			MinPlayers = 8; //Default minimum

			curStone = this;

			m_DuelCoords = new Rectangle2D();

			UpdateRegion();

			m_RestrictedSpells = new BitArray( SpellRegistry.Types.Length );
			m_RestrictedSkills = new BitArray( SkillInfo.Table.Length );
		}

		public void HandleCorpse( Mobile from )
		{
			if( from.Corpse != null )
			{
				Corpse c = (Corpse)from.Corpse;
				Container b = from.Backpack;

				foreach( Item i in new ArrayList( c.Items ) )
				{
					if( i.Map != Map.Internal )
						b.AddItem( i );
				}

				c.Delete();

				from.SendMessage( 1161, "The contents of your corpse have been safely placed into your backpack" );
			}
		}

		public void StartTheTourney()
		{
			Broadcast( AccessLevel.Player, "The tournament has began, and signups are now closed.");

			TFundingBarrel m = FindLink();

			if(m != null)
			{
				m.Visible = false;
				m.FReady = false;
			}

			m_InUse = true;

			AdvanceRound();
		}

		public void AdvanceRound()
		{
			if( (m_Players.Count % 2) != 0 )
			{
				if( m_Advance == null )
				{
					int ran = Utility.Random( m_Players.Count );

					if(IsOnline((PlayerMobile)m_Players[ran]))
					{
						m_Advance = (PlayerMobile)m_Players[ran];
						m_Players.Remove( m_Advance );
					}

					else
					{
						m_Players.Remove((PlayerMobile)m_Players[ran]);
					}
				}

				else
				{
					if(IsOnline(m_Advance))
					{
						m_Players.Add( m_Advance );
						m_Advance = null;
					}

					else
						m_Advance = null;
				}
			}

			if( (m_Players.Count % 2) == 0 )
			{
				int ran1 = Utility.Random( m_Players.Count );
				int ran2 = Utility.Random( m_Players.Count );

				while( ran1 == ran2 )
					ran2 = Utility.Random( m_Players.Count );

				m_D1 = (PlayerMobile)m_Players[ran1];
				m_D2 = (PlayerMobile)m_Players[ran2];

				m_Players.Remove( m_D1 );
				m_Players.Remove( m_D2 );

				PrepareDuel();
			}
		}

		public void PrepareDuel()
		{
			PrepareDueler( m_D1 );
			PrepareDueler( m_D2 );

			WallandMove();
		}

		public void PrepareDueler( Mobile from )
		{
			if( from is PlayerMobile )
			{
				PlayerMobile pm = (PlayerMobile)from;

				if( !pm.Alive )
					pm.Resurrect();

				if ( pm.Mount != null )
				{
					pm.Mount.Rider = null;
				}

				pm.Criminal = true;
				pm.CurePoison(pm);
				pm.Blessed = true;
				pm.Frozen = true;

				pm.StatMods.Clear();
				pm.Hits = pm.HitsMax;
				pm.Mana = pm.ManaMax;
				pm.Stam = pm.StamMax;

				Targeting.Target.Cancel( pm );
				pm.MagicDamageAbsorb = 0;
				pm.MeleeDamageAbsorb = 0;
				ProtectionSpell.Registry.Remove( pm );
				DefensiveSpell.Nullify( pm );
			}
		}

		public void LetThemDuel()
		{
			PrepareDueler( m_D1 );
			PrepareDueler( m_D2 );

			m_D1.Blessed = false;
			m_D2.Blessed = false;

			m_D1.Frozen = false;
			m_D2.Frozen = false;

			m_D1.SendMessage( 1161, "The duel has begun. Good luck!" );
			m_D2.SendMessage( 1161, "The duel has begun. Good luck!" );
		}

		public void EndRound( Mobile winner, Mobile loser )
		{
			if( m_Players.Count == 0 && m_NextRoundPlayers.Count == 0 && Advance == null ) //means that the last match just finished
			{
				TourneyIsOver( winner, loser );
				return;
			}

			else if( Players.Count == 0 && NextRoundPlayers.Count == 0 && Advance != null ) //means winner and advancer need to duel
			{
				m_Players.Add( winner );
				m_Players.Add( m_Advance );

				m_D1 = null;
				m_D2 = null;
				m_Advance = null;
			}

			else if( m_Players.Count == 0 && NextRoundPlayers.Count != 0 ) //means that nextround needs moved over to player array
			{
				m_Players.Clear();
				m_Players.Add( winner );

				if(m_Advance != null)
					m_Players.Add( m_Advance );

				foreach( Mobile m in m_NextRoundPlayers )
				{
					m_Players.Add( m );
				}

				m_NextRoundPlayers.Clear();

				m_D1 = null;
				m_D2 = null;
				m_Advance = null;
			}

			else if( m_Players.Count != 0 ) //still more people to duel!
			{
				if( m_Players.Count == 1 )
				{
					if( m_Advance != null )
					{
						m_Players.Add( m_Advance );
						m_Advance = null;
					}

					else //means there is one person ready to duel the final person.
					{
						if(m_NextRoundPlayers.Count == 0)
						{
							m_Players.Add( winner );
							m_D1 = null;
							m_D2 = null;
						}

						else //just incase...
						{
							m_NextRoundPlayers.Add( winner );

							m_D1 = null;
							m_D2 = null;
						}
					}
				}

				else if( m_Players.Count > 1 )
				{
					m_NextRoundPlayers.Add( winner );

					m_D1 = null;
					m_D2 = null;
				}
			}

			winner.StatMods.Clear();
			winner.Hits = winner.HitsMax;
			winner.Mana = winner.ManaMax;
			winner.Stam = winner.StamMax;
			loser.StatMods.Clear();
			loser.Hits = loser.HitsMax;
			loser.Mana = loser.ManaMax;
			loser.Stam = loser.StamMax;
			loser.Location = SpectatorArea;
			winner.Location = SpectatorArea;
			winner.Combatant = null;
			loser.Combatant = null;
			winner.Criminal = false;
			loser.Criminal = false;
			winner.CurePoison(winner);
			loser.CurePoison(loser);

			winner.SendMessage( 1161, "Good job on winning your match. Please hang tight for your next match." );
			loser.SendMessage( 1161, "Sorry, you have lost so you are no longer part of this tournament." );

			AdvanceRound();
		}

		public void GateTimer()
		{
			GTimer g = new GTimer(this);
			g.Start();
		}

		public void TourneyIsOver( Mobile winner, Mobile loser)
		{
			try{m_D1 = null;}catch{}
			try{m_D2 = null;}catch{}
			try{m_Advance = null;}catch{}
			try{m_Players.Clear();}catch{}
			try{m_NextRoundPlayers.Clear();}catch{}

			if(!winner.Alive)
				winner.Resurrect();

			if(!loser.Alive)
				loser.Resurrect();

			winner.Location = SpectatorArea;
			loser.Location = SpectatorArea;

			winner.AddToBackpack( new BankCheck( 100000 ) );
			winner.SendMessage( 1161, "Congratulations on winning the tournament. Your prize has been placed into your backpack.");

			Broadcast( AccessLevel.Player, String.Format("The tournament is over. {0} has won the tourney, and {1} came in second place. Make sure you congratulate them!", winner.Name, loser.Name) );

			TFundingBarrel m = FindLink();

			if(m != null)
			{
				m.Visible = true;
				m.FReady = true;
				m.FCurrent = 0;
			}

			m_InUse = false;
		}

		public void SpawnGates()
		{
			DespawnGates();

			if( GateSpawn != GateSpawn.None )
			{
				if( GateSpawn == GateSpawn.FeluccaOnly || GateSpawn == GateSpawn.All )
				{
					for ( int i = 0; i < TInfo.FeluccaCities.Length; ++i )
					{
						try
						{
							TourneyGate m = new TourneyGate();
							m.Target = m_TargetDest;
							m.TargetMap = m_MapDest;
							m.MoveToWorld( TInfo.FeluccaCities[i], Map.Felucca );
							Gates.Add( m );
						}

						catch
						{
							Broadcast( "There was a minor error in the moongate generation. It is probably a minor error. If you receive this message, please report the bug." );
						}
					}
				}

				if( GateSpawn == GateSpawn.TrammelOnly || GateSpawn == GateSpawn.All )
				{
					for ( int i = 0; i < TInfo.TrammelCities.Length; ++i )
					{
						try
						{
							TourneyGate m = new TourneyGate();
							m.Target = m_TargetDest;
							m.TargetMap = m_MapDest;
							m.MoveToWorld( TInfo.TrammelCities[i], Map.Trammel );
							Gates.Add( m );
						}

						catch
						{
							Broadcast( "There was a minor error in the moongate generation. It is probably a minor error. If you receive this message, please report the bug." );
						}
					}
				}
			}

			Broadcast( "The moongates have been spawned in their respective towns." );
		}

		public override void OnDoubleClick( Mobile from )
		{
			if( from.AccessLevel < AccessLevel.GameMaster )
				from.SendMessage("You may not use this.");

			else
			{
				from.SendGump( new TConfigGump( this ) );
				from.SendMessage( 1161, "Please make sure that you set everything up before allowing tourney's!" );
			}
		}

		public void DespawnGates()
		{
			foreach( TourneyGate m in Gates )
			{
				m.Delete();
			}

			Gates.Clear();
		}

		public TFundingBarrel FindLink()
		{
			foreach( Item i in World.Items.Values )
			{
				if( i is TFundingBarrel )
				{
					if( (i as TFundingBarrel).Link == this )
					{
						return i as TFundingBarrel;
					}
				}
			}

			return null;
		}

		public Point2D Middle()
		{
			Rectangle2D r = m_DuelCoords;

			int wMid = r.X + (r.Width / 2);
			int hMid = r.Y + (r.Height / 2);

			Point2D mid = new Point2D( wMid, hMid );

			return mid;
		}

		public Point2D D1Dest()
		{
			Point2D dest = Middle();

			dest.Y -= 2;

			return dest;
		}

		public Point2D D2Dest()
		{
			Point2D dest = Middle();

			dest.Y += 2;

			return dest;
		}

		public void WallandMove()
		{
			Item x = new WallOfStoneEast(this);
			x.MoveToWorld( new Point3D( Middle().X, Middle().Y, m_ArenaZ ), m_MapDest );

			m_D1.MoveToWorld( new Point3D( D1Dest().X, D1Dest().Y, m_ArenaZ ), m_MapDest );

			m_D2.MoveToWorld( new Point3D( D2Dest().X, D2Dest().Y, m_ArenaZ ), m_MapDest );
		}

		public void Broadcast( string message )
		{
			Broadcast( AccessLevel.Counselor, message );
		}

		public void Broadcast( AccessLevel ac, string message )
		{
			foreach( NetState state in NetState.Instances )
			{
				Mobile m = state.Mobile;

				if ( m != null && m.AccessLevel >= ac )
					m.SendMessage( 1161, "[System Message]: {0}", message );
			}
		}

		public bool IsOnline( Mobile from )
		{
			if( from.NetState == null )
			{
				return false;
			}

			return true;
		}

		public bool IsMage( Mobile from ) //Mage
		{
			if(
				from.Skills[SkillName.Magery].Value >= 50     && /*Needs at least 50 magery to qualify */
				from.Skills[SkillName.EvalInt].Value >= 50    && /*Needs at least 50 evalint to qualify*/
				from.Skills[SkillName.Meditation].Value >= 50 &&
			       (from.Skills[SkillName.Swords].Value <= 30   ||   /*				                 */
				from.Skills[SkillName.Fencing].Value <= 30    ||   /* Can not have wep skill to qualify  */
				from.Skills[SkillName.Macing].Value <= 30     ||   /*				                 */
				from.Skills[SkillName.Archery].Value <= 30)   &&
				from.RawDex <= 50 && from.RawInt >= 50    )        /*Can not have more than 50 dexterity to qualify, and needs at least 50 int */

			{ return true; }

			return false;
		}

		public bool IsDexxer( Mobile from ) //Dexxer
		{
			if((
				from.Skills[SkillName.Swords].Value >= 50  ||   /*				   */
				from.Skills[SkillName.Fencing].Value >= 50 ||   /* Needs a weapon skill to qualify */
				from.Skills[SkillName.Macing].Value >= 50  ||   /*				   */
				from.Skills[SkillName.Archery].Value >= 50)&&
				from.Skills[SkillName.Magery].Value <= 30  &&   /*Can not have more than 30 magery to qualify. */
				from.RawInt <= 50	&& from.RawDex >= 50    )	/*Can not have more than 50 int to qualify, and needs at least 50 dex     */

			{ return true; }

			return false;
		}

		public bool IsTank( Mobile from ) //Tank
		{
			if((
				from.Skills[SkillName.Swords].Value >= 50  ||   /*				      */
				from.Skills[SkillName.Fencing].Value >= 50 ||   /* Needs a weapon skill to qualify    */
				from.Skills[SkillName.Macing].Value >= 50  ||   /*				      */
				from.Skills[SkillName.Archery].Value >= 50)&&
				from.Skills[SkillName.Magery].Value >= 50 )     /*Needs at least 50 magery to qualify */

			{ return true; }

			return false;
		}

		public bool Is7x( Mobile from ) //7x Check
		{
			if(from.SkillsTotal == 7000)
				return true;

			return false;
		}

		public bool Is5x( Mobile from ) //5x Check
		{
			if(from.SkillsTotal <= 5000) //Change to == for exactly 5x. This just makes sure they don't have over.
				return true;

			return false;
		}

		public void AcceptPlayer( Mobile from )
		{
			from.SendMessage( 1161, "You have met the pre-requisites, and have been accepted into the tourney. Please have patients, it will begin soon." );
			m_Players.Add( from );
		}

		public void WeaponCheck( Mobile from )
		{
			if( DuelType == DuelType.Mage )
			{
				Item toBank = from.FindItemOnLayer( Layer.OneHanded );
				Container bp = from.BankBox;
				Container pack = from.Backpack;
				Item holding = from.Holding;

				if( holding != null )
				{
					bp.DropItem(holding);
					from.SendMessage( 1161, "The item that you were holding has been moved to you bankbox due to restrictions on the tourney." );
				}
				
				if ( toBank == null || !toBank.Movable )
					toBank = from.FindItemOnLayer( Layer.TwoHanded );
				
				if (toBank != null && bp != null && toBank is BaseWeapon)
				{
					bp.DropItem(toBank);
					from.SendMessage( 1161, "Some equipment has been moved to your bankbox due to restrictions on the tourney." );
				}

				foreach( Item i in new ArrayList( pack.Items ) )
				{
					if(i.Map != Map.Internal)
					{
						if(i is BaseWeapon)
						{
							bp.DropItem(i);
							from.SendMessage( 1161, "Some equipment was moved to your bankbox due to restrictions on this tourney." );
						}
					}
				}
			}

			if( !m_MagicWeapons )
			{
				Item toBank = from.FindItemOnLayer( Layer.OneHanded );
				Container bp = from.BankBox;
				Container pack = from.Backpack;
				Item holding = from.Holding;

				if( holding != null )
				{
					if(IsMagicWeapon(holding))
					{
						bp.DropItem(holding);
						from.SendMessage( 1161, "The item that you were holding has been moved to you bankbox due to restrictions on the tourney." );
					}
				}

				if ( toBank == null || !toBank.Movable )
					toBank = from.FindItemOnLayer( Layer.TwoHanded );

				if (toBank != null && bp != null && toBank is BaseWeapon)
				{
					if(IsMagicWeapon(toBank))
					{
						bp.DropItem(toBank);
						from.SendMessage( 1161, "Some equipment has been moved to your bankbox due to restrictions on the tourney." );
					}
				}

				foreach( Item i in new ArrayList( pack.Items ) )
				{
					if(i.Map != Map.Internal)
					{
						if(i is BaseWeapon || i is BaseArmor || i is BaseJewel)
						{
							if(IsMagicWeapon(i))
							{
								bp.DropItem(i);
								from.SendMessage( 1161, "Some equipment was moved to your bankbox due to restrictions on this tourney." );
							}
						}
					}
				}
			}	
		}

		public bool IsMagicWeapon( Item from )
		{
			bool strike = false;

			if( from is BaseWeapon )
			{
				BaseWeapon b = (BaseWeapon)from;

				if( b.AccuracyLevel > 0 || b.DamageLevel > 0 || b.DurabilityLevel > 0 || b.Slayer > 0 || b.ArtifactRarity > 0 )
					strike = true;
			}

			if( from is BaseArmor )
			{
				BaseArmor b = (BaseArmor)from;

				if(b.ArtifactRarity > 0)
					strike = true;
			}

			if( from is BaseJewel )
			{
				BaseJewel b = (BaseJewel)from;

				if(b.ArtifactRarity > 0)
					strike = true;
			}

			return strike;
		}

		public void DenyPlayer( Mobile from )
		{
			from.SendMessage( 1161, "We are sorry, but you do not meet the pre-requisites. Read the tourney rules for more info.");
		}

		public bool IsParticipant( Mobile from )
		{
			try
			{
				if( m_Players.Contains(from) || m_NextRoundPlayers.Contains(from) || m_D1 == from || m_D2 == from || m_Advance == from )
				{
					return true;
				}

				return false;
			}

			catch
			{return false;}
		}

		public void VerifyJoin( Mobile from )
		{
			if(InUse)
				return;

			if( IsParticipant(from) )
			{
				from.SendMessage( 1161, "You are already signed up for the tourney.");
				return;
			}

			bool canJoin = true;

			switch( DuelType )
			{
				case DuelType.Any:
				{
					break;
				}

				case DuelType.Mage:
				{
					if(IsMage(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelType.Dexxer:
				{
					if(IsDexxer(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelType.Tank:
				{
					if(IsTank(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}
			}

			switch( DuelSet )
			{
				case DuelSet.Allow:
				{
					break;
				}

				case DuelSet.Sevenx:
				{
					if(Is7x(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelSet.Fivex:
				{
					if(Is5x(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}
			}

			if(canJoin)
				AcceptPlayer(from);

			else
				DenyPlayer(from);
		}

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

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

			writer.Write((int) 6); //Version

			writer.Write( (int) m_MinPlayers );
			writer.Write( m_MagicWeapons );
			writer.Write( (int) m_DuelType );
			writer.Write( (int) m_DuelSet );

			writer.Write( (int) m_ArenaZ );

			writer.Write( m_CanHeal );
			writer.Write( m_CanUsePotions );

			WriteBitArray( writer, m_RestrictedSpells );
			WriteBitArray( writer, m_RestrictedSkills );

			writer.Write( m_TargetDest );
			writer.Write( m_MapDest );

			writer.Write( (int) m_GateSpawn );

			writer.Write( (Rectangle2D) m_DuelCoords );
		}

		#region Serialization Helpers

		public static void WriteBitArray( GenericWriter writer, BitArray ba )
		{
			writer.Write( ba.Length );

				for( int i = 0; i < ba.Length; i++ )
				{
					writer.Write( ba[i] );
				}
			return;
		}

		public static BitArray ReadBitArray( GenericReader reader )
		{
			int size = reader.ReadInt();
			BitArray newBA = new BitArray( size );

			for( int i = 0; i < size; i++ )
			{
				newBA[i] = reader.ReadBool();
			}

			return newBA;
		}

		#endregion

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

			curStone = this;

			int version = reader.ReadInt();

			switch ( version )
			{
				case 6:
				{
					m_MinPlayers = reader.ReadInt();
					m_MagicWeapons = reader.ReadBool();
					m_DuelType = (DuelType)reader.ReadInt();
					m_DuelSet = (DuelSet)reader.ReadInt();

					goto case 5;
				}
				case 5:
				{
					m_ArenaZ = reader.ReadInt();
					goto case 4;
				}
				case 4:
				{
					m_CanHeal = reader.ReadBool();
					m_CanUsePotions = reader.ReadBool();

					goto case 3;
				}

				case 3:
				{
					m_RestrictedSpells = ReadBitArray( reader );
					m_RestrictedSkills = ReadBitArray( reader );

					goto case 2;
				}

				case 2:
				{
					m_TargetDest = reader.ReadPoint3D();
					m_MapDest = reader.ReadMap();

					m_GateSpawn = (GateSpawn)reader.ReadInt();

					goto case 1;
				}

				case 1:
				{
					m_DuelCoords = reader.ReadRect2D();

					goto case 0;
				}

				case 0:
				{
					break;
				}
			}
		}

		public void UpdateRegion()
		{
			if( m_DuelingRegion == null )
			{
				m_DuelingRegion = new DuelRegion( this, this.Map );
			}

			try
			{
				Region.RemoveRegion( m_DuelingRegion );

				m_DuelingRegion.Coords.Clear();

				m_DuelingRegion.Coords.Add( m_DuelCoords );

				m_DuelingRegion.Disabled = true;

				m_DuelingRegion.Map = this.Map;

				Region.AddRegion( m_DuelingRegion );

				return;
			}

			catch
			{
				m_DuelCoords = new Rectangle2D();
			}
		}


		public static int GetRegistryNumber( ISpell s )
		{
			Type[] t = SpellRegistry.Types;

			for( int i = 0; i < t.Length; i++ )
			{
				if( s.GetType() == t[i] )
					return i;
			}

			return -1;
		}

		public bool IsRestrictedSpell( ISpell s )
		{
			int regNum = GetRegistryNumber( s );
			
			if( regNum < 0 )	//Happens with unregistered Spells
				return false;

			return m_RestrictedSpells[regNum];
		}

		public bool IsRestrictedSkill( int skill )
		{
			if( skill < 0 )
				return false;

			return m_RestrictedSkills[skill];
		}

		public void ChooseArea( Mobile m )
		{
			BoundingBoxPicker.Begin( m, new BoundingBoxCallback( DuelRegion_Callback ), this );
		}

		private static void DuelRegion_Callback( Mobile from, Map map, Point3D start, Point3D end, object state )
		{
			DoChooseArea( from, map, start, end, state );
		}

		private static void DoChooseArea( Mobile from, Map map, Point3D start, Point3D end, object control )
		{
			MasterTStone r = (MasterTStone)control;
			Rectangle2D rect = new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 );

			r.m_DuelCoords = rect;

			r.UpdateRegion();
		}

		public override void OnDelete()
		{
			if( m_DuelingRegion != null )
				Region.RemoveRegion( m_DuelingRegion );

			try{m_Players.Clear();}catch{}		    /*                      */
			try{m_NextRoundPlayers.Clear();}catch{}     /*   Didn't feel like   */ 
			try{m_D1 = null;}catch{}		    /*      adding null     */
			try{m_D2 = null;}catch{}		    /*        checks        */
			try{m_Advance = null;}catch{}		    /*	                    */

			base.OnDelete();
		}

		public override void OnMapChange()
		{
			UpdateRegion();
			base.OnMapChange();
		}

		public void ShowBounds( Rectangle2D r, Map m )
		{
			if( m == Map.Internal || m == null )
				return;

			Point3D p1 = new Point3D( r.X, r.Y - 1, 0 );
			Point3D p2 = new Point3D( r.X, r.Y + r.Height - 1, 0 );

			Effects.SendLocationEffect( new Point3D( r.X -1, r.Y - 1, m.GetAverageZ( r.X, r.Y -1 ) ) , m, 251, 75, 1, 1151, 3 );	//Top Corner	//Testing color

			for( int x = r.X; x <= ( r.X + r.Width -1 ); x++ )
			{
				p1.X = x;
				p2.X = x;

				p1.Z = m_ArenaZ;
				p2.Z = m_ArenaZ;

				Effects.SendLocationEffect( p1, m, 249, 75, 1, 1151, 3 );	//North bound
				Effects.SendLocationEffect( p2, m, 249, 75, 1, 1151, 3 );	//South bound
			}

			p1 = new Point3D( r.X -1 , r.Y -1 , 0 );
			p2 = new Point3D( r.X + r.Width - 1, r.Y, 0 );

			for( int y = r.Y; y <= ( r.Y + r.Height -1 ); y++ )
			{
				p1.Y = y;
				p2.Y = y;

				p1.Z = m_ArenaZ;
				p2.Z = m_ArenaZ;

				Effects.SendLocationEffect( p1, m, 250, 75, 1, 1151, 3 );	//West Bound
				Effects.SendLocationEffect( p2, m, 250, 75, 1, 1151, 3 );	//East Bound
			}
		}

		public class GTimer : Timer
		{
			MasterTStone m_Stone;

			public GTimer( MasterTStone stone ) : base( TimeSpan.FromMinutes( 10.0 ) ) 
			{
				m_Stone = stone;

				AnnounceTimer at = new AnnounceTimer(m_Stone);
				at.Start();

				m_Stone.SpawnGates();
			}

			protected override void OnTick()
			{
				if(m_Stone.MinPlayers <= m_Stone.Players.Count)
				{
					if(!(m_Stone.InUse))
					{
						m_Stone.StartTheTourney();
						m_Stone.DespawnGates();
					}

					else
						m_Stone.Broadcast("It appears that the tournament has already started.");
				}

				else	
				{
					m_Stone.Broadcast( AccessLevel.Player, "There was not enough people signed up for the tourney, so there will be another 10 minutes to sign up." );
					GTimer g = new GTimer(m_Stone);
					g.Start();
				}
			}
		}

		public class AnnounceTimer : Timer
		{
			MasterTStone m_Stone;
			int count = 0;

			public AnnounceTimer( MasterTStone stone ) : base( TimeSpan.FromMinutes( 5.0 ) )
			{
				m_Stone = stone;
				m_Stone.Broadcast( AccessLevel.Player, "The tourney signups are open. If you would like to participate, please find the nearest moongate to the tourney area." );
			}

			protected override void OnTick()
			{
				if(count <= 5)
				{
					count += 5;
					AnnounceTimer at = new AnnounceTimer( m_Stone );
					at.Start();
				}
			}
		}
	}
}
 

Jeff

Lord
burento said:
Tstone..

Code:
using System;
using Server;
using System.Collections;
using Server.Mobiles;
using Server.Items;
using Server.GateConfig;
using Server.Targeting;
using Server.Gumps;
using Server.Regions;
using Server.Network;
using Server.Spells;
using Server.Spells.Second;
using Server.Spells.Third;

namespace Server.Items
{
	public enum GateSpawn
	{
		All,
		None,
		FeluccaOnly,
		TrammelOnly
	}

	public enum DuelType
	{
		Any,
		Mage,
		Dexxer,
		Tank
	}

	public enum DuelSet
	{
		Allow,
		Sevenx,
		Fivex
	}

	public class MasterTStone : Item
	{
		private GateSpawn m_GateSpawn;
		private DuelType m_DuelType;
		private DuelSet m_DuelSet;
		private Point3D m_TargetDest;
		private Map m_MapDest;
		private ArrayList m_Gates = new ArrayList();
		private bool m_CanHeal;
		private bool m_CanUsePotions;
		private bool m_MagicWeapons;
		private ArrayList m_Players = new ArrayList();
		private ArrayList m_NextRoundPlayers = new ArrayList();
		private Mobile m_Advance;
		private Mobile m_D1;
		private Mobile m_D2;
		private static MasterTStone curStone;
		private int m_ArenaZ;
		private bool m_InUse;
		private int m_MinPlayers;

		private DuelRegion m_DuelingRegion;
		private Rectangle2D m_DuelCoords;
		private BitArray m_RestrictedSpells;
		private BitArray m_RestrictedSkills;

		public bool InUse
		{
			get{ return m_InUse; }
			set{ m_InUse = value; }
		}

		public Mobile Advance
		{
			get{ return m_Advance; }
			set{ m_Advance = value; }
		}

		public Mobile D1
		{
			get{ return m_D1; }
			set{ m_D1 = value; }
		}

		public Mobile D2
		{
			get{ return m_D2; }
			set{ m_D2 = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int ArenaZ
		{
			get{ return m_ArenaZ; }
			set{ m_ArenaZ = value; }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int MinPlayers
		{
			get{ return m_MinPlayers; }
			set{ m_MinPlayers = value; }
		}

		public BitArray RestrictedSpells
		{
			get{ return m_RestrictedSpells; }
		}

		public BitArray RestrictedSkills
		{
			get{ return m_RestrictedSkills; }
		}

		public DuelRegion DuelingRegion
		{
			get{ return m_DuelingRegion; }
		}

		public Rectangle2D DuelCoords
		{
			get{ return m_DuelCoords; }
			set{ m_DuelCoords = value; }
		}

		public ArrayList Players
		{
			get{ return m_Players; }
			set{ m_Players = value; }
		}

		public ArrayList NextRoundPlayers
		{
			get{ return m_NextRoundPlayers; }
			set{ m_NextRoundPlayers = value; }
		}

		public ArrayList Gates
		{
			get{ return m_Gates; }
			set{ m_Gates = value; }
		}

		public bool CanHeal
		{
			get
			{
				return m_CanHeal;
			}

			set
			{
				m_CanHeal = value;
			}
		}

		public bool CanUsePotions
		{
			get
			{
				return m_CanUsePotions;
			}

			set
			{
				m_CanUsePotions = value;
			}
		}

		public bool MagicWeapons
		{
			get
			{
				return m_MagicWeapons;
			}

			set
			{
				m_MagicWeapons = value;
			}
		}

		public GateSpawn GateSpawn
		{
			get
			{
				return m_GateSpawn;
			}

			set
			{
				m_GateSpawn = value;
			}
		}

		public DuelType DuelType
		{
			get
			{
				return m_DuelType;
			}

			set
			{
				m_DuelType = value;
			}
		}

		public DuelSet DuelSet
		{
			get
			{
				return m_DuelSet;
			}

			set
			{
				m_DuelSet = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D SpectatorArea
		{
			get
			{
				return m_TargetDest;
			}

			set
			{
				m_TargetDest = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Map MapDest
		{
			get
			{
				return m_MapDest;
			}

			set
			{
				m_MapDest = value;
			}
		}

		public static void Initialize()
		{
			EventSink.Disconnected += new DisconnectedEventHandler( OnDisconnect );
			EventSink.Login += new LoginEventHandler( OnLogin );
			EventSink.PlayerDeath += new PlayerDeathEventHandler( OnDeath );

			try
			{
				ArrayList toDelete = new ArrayList();
				int count = 0;

				foreach( Item i in World.Items.Values )
				{
					if( i is TourneyGate )
					{
						toDelete.Add( i );
					}
				}

				if( toDelete.Count != 0 )
				{
					foreach( TourneyGate t in toDelete )
					{
						t.Delete();
						count++;
					}
				}
			}

			catch
			{
				Console.WriteLine("Milt's tourney system - An error occured while performing a check. If you receive this message, please report the bug.");
			}

			if( curStone != null )
			{
				curStone.UpdateRegion();
			}

			Console.WriteLine("Milt's Auto Tourney System...Initialized.");
		}

		public static void OnLogin( LoginEventArgs e )
		{
			try
			{
				if( curStone.m_Players.Contains( e.Mobile ) )
				{
					e.Mobile.SendMessage( 1161, "Something must have went wrong during one of the tournaments, and you have been removed.");
					curStone.m_Players.Remove( e.Mobile );
				}
			}

			catch{}
		}

		public static void OnDisconnect( DisconnectedEventArgs e )
		{
			try{
			if( curStone.m_Players != null )
			{
				if( curStone.m_Advance != e.Mobile )
				{
					if( curStone.IsParticipant( e.Mobile ) ) //Player is dueling, or waiting to duel
					{
						if( e.Mobile == curStone.m_D1 || e.Mobile == curStone.m_D2 ) //Mobile is Dueling
						{
							if( e.Mobile == curStone.m_D1 )
							{
								curStone.m_D2.SendMessage( 1161, "Your opponent has logged out, thus you win." );

								curStone.EndRound( curStone.m_D2, curStone.m_D1 );
							}

							else if( e.Mobile == curStone.m_D2 )
							{
								curStone.m_D1.SendMessage( 1161, "Your opponent has logged out, thus you win." );

								curStone.EndRound( curStone.m_D1, curStone.m_D2 );
							}
						}

						else //Mobile is waiting to duel
						{
							if(curStone.m_Players.Contains(e.Mobile))
								curStone.m_Players.Remove(e.Mobile);

							if(curStone.m_NextRoundPlayers.Contains(e.Mobile))
								curStone.m_NextRoundPlayers.Remove(e.Mobile);

							if(e.Mobile == curStone.m_Advance)
								curStone.m_Advance = null; //Just in case!
						}
					}
				}
			}

			else //Player was the auto advancer
			{
				curStone.m_Advance = null;
			}
			}

			catch{}
		}

		public static void OnDeath( PlayerDeathEventArgs e )
		{
			try{
			if( curStone.m_Players != null && curStone.m_D1 != null && curStone.m_D2 != null )
			{
				if( curStone.IsParticipant(e.Mobile) ) //Player is dueling, or waiting to duel
				{
					if( curStone.m_D1 != null && curStone.m_D2 != null )
					{
						if( e.Mobile == curStone.m_D1 || e.Mobile == curStone.m_D2 ) //Mobile is Dueling
						{
							e.Mobile.Resurrect();

							curStone.HandleCorpse( e.Mobile );

							if( e.Mobile == curStone.m_D1 )
								curStone.EndRound( curStone.m_D2, curStone.m_D1 );

							else if( e.Mobile == curStone.m_D2 )
								curStone.EndRound( curStone.m_D1, curStone.m_D2 );
						}

						else //Mobile is waiting to duel
						{
							e.Mobile.SendMessage( 1161, "Please do not participate in any combat before game." );
							curStone.Broadcast( String.Format("{0} has died somehow, while waiting for their turn in the tourney. It is recommended that you make it impossible for this to happen, as it can be exploited.", e.Mobile.Name) );

							e.Mobile.Resurrect();

							curStone.HandleCorpse( e.Mobile );
						}
					}
				}
			}
			}

			catch{}
		}

		[Constructable]
		public MasterTStone() : base( 0xEDD )
		{
			Movable = false;
			Name = "MasterTStone";
			Hue = 1108;
			Gates = new ArrayList();
			Players = new ArrayList();
			NextRoundPlayers = new ArrayList();
			MapDest = Map.Felucca;
			CanHeal = true;
			MinPlayers = 8; //Default minimum

			curStone = this;

			m_DuelCoords = new Rectangle2D();

			UpdateRegion();

			m_RestrictedSpells = new BitArray( SpellRegistry.Types.Length );
			m_RestrictedSkills = new BitArray( SkillInfo.Table.Length );
		}

		public void HandleCorpse( Mobile from )
		{
			if( from.Corpse != null )
			{
				Corpse c = (Corpse)from.Corpse;
				Container b = from.Backpack;

				foreach( Item i in new ArrayList( c.Items ) )
				{
					if( i.Map != Map.Internal )
						b.AddItem( i );
				}

				c.Delete();

				from.SendMessage( 1161, "The contents of your corpse have been safely placed into your backpack" );
			}
		}

		public void StartTheTourney()
		{
			Broadcast( AccessLevel.Player, "The tournament has began, and signups are now closed.");

			TFundingBarrel m = FindLink();

			if(m != null)
			{
				m.Visible = false;
				m.FReady = false;
			}

			m_InUse = true;

			AdvanceRound();
		}

		public void AdvanceRound()
		{
			if( (m_Players.Count % 2) != 0 )
			{
				if( m_Advance == null )
				{
					int ran = Utility.Random( m_Players.Count );

					if(IsOnline((PlayerMobile)m_Players[ran]))
					{
						m_Advance = (PlayerMobile)m_Players[ran];
						m_Players.Remove( m_Advance );
					}

					else
					{
						m_Players.Remove((PlayerMobile)m_Players[ran]);
					}
				}

				else
				{
					if(IsOnline(m_Advance))
					{
						m_Players.Add( m_Advance );
						m_Advance = null;
					}

					else
						m_Advance = null;
				}
			}

			if( (m_Players.Count % 2) == 0 )
			{
				int ran1 = Utility.Random( m_Players.Count );
				int ran2 = Utility.Random( m_Players.Count );

				while( ran1 == ran2 )
					ran2 = Utility.Random( m_Players.Count );

				m_D1 = (PlayerMobile)m_Players[ran1];
				m_D2 = (PlayerMobile)m_Players[ran2];

				m_Players.Remove( m_D1 );
				m_Players.Remove( m_D2 );

				PrepareDuel();
			}
		}

		public void PrepareDuel()
		{
			PrepareDueler( m_D1 );
			PrepareDueler( m_D2 );

			WallandMove();
		}

		public void PrepareDueler( Mobile from )
		{
			if( from is PlayerMobile )
			{
				PlayerMobile pm = (PlayerMobile)from;

				if( !pm.Alive )
					pm.Resurrect();

				if ( pm.Mount != null )
				{
					pm.Mount.Rider = null;
				}

				pm.Criminal = true;
				pm.CurePoison(pm);
				pm.Blessed = true;
				pm.Frozen = true;

				pm.StatMods.Clear();
				pm.Hits = pm.HitsMax;
				pm.Mana = pm.ManaMax;
				pm.Stam = pm.StamMax;

				Targeting.Target.Cancel( pm );
				pm.MagicDamageAbsorb = 0;
				pm.MeleeDamageAbsorb = 0;
				ProtectionSpell.Registry.Remove( pm );
				DefensiveSpell.Nullify( pm );
			}
		}

		public void LetThemDuel()
		{
			PrepareDueler( m_D1 );
			PrepareDueler( m_D2 );

			m_D1.Blessed = false;
			m_D2.Blessed = false;

			m_D1.Frozen = false;
			m_D2.Frozen = false;

			m_D1.SendMessage( 1161, "The duel has begun. Good luck!" );
			m_D2.SendMessage( 1161, "The duel has begun. Good luck!" );
		}

		public void EndRound( Mobile winner, Mobile loser )
		{
			if( m_Players.Count == 0 && m_NextRoundPlayers.Count == 0 && Advance == null ) //means that the last match just finished
			{
				TourneyIsOver( winner, loser );
				return;
			}

			else if( Players.Count == 0 && NextRoundPlayers.Count == 0 && Advance != null ) //means winner and advancer need to duel
			{
				m_Players.Add( winner );
				m_Players.Add( m_Advance );

				m_D1 = null;
				m_D2 = null;
				m_Advance = null;
			}

			else if( m_Players.Count == 0 && NextRoundPlayers.Count != 0 ) //means that nextround needs moved over to player array
			{
				m_Players.Clear();
				m_Players.Add( winner );

				if(m_Advance != null)
					m_Players.Add( m_Advance );

				foreach( Mobile m in m_NextRoundPlayers )
				{
					m_Players.Add( m );
				}

				m_NextRoundPlayers.Clear();

				m_D1 = null;
				m_D2 = null;
				m_Advance = null;
			}

			else if( m_Players.Count != 0 ) //still more people to duel!
			{
				if( m_Players.Count == 1 )
				{
					if( m_Advance != null )
					{
						m_Players.Add( m_Advance );
						m_Advance = null;
					}

					else //means there is one person ready to duel the final person.
					{
						if(m_NextRoundPlayers.Count == 0)
						{
							m_Players.Add( winner );
							m_D1 = null;
							m_D2 = null;
						}

						else //just incase...
						{
							m_NextRoundPlayers.Add( winner );

							m_D1 = null;
							m_D2 = null;
						}
					}
				}

				else if( m_Players.Count > 1 )
				{
					m_NextRoundPlayers.Add( winner );

					m_D1 = null;
					m_D2 = null;
				}
			}

			winner.StatMods.Clear();
			winner.Hits = winner.HitsMax;
			winner.Mana = winner.ManaMax;
			winner.Stam = winner.StamMax;
			loser.StatMods.Clear();
			loser.Hits = loser.HitsMax;
			loser.Mana = loser.ManaMax;
			loser.Stam = loser.StamMax;
			loser.Location = SpectatorArea;
			winner.Location = SpectatorArea;
			winner.Combatant = null;
			loser.Combatant = null;
			winner.Criminal = false;
			loser.Criminal = false;
			winner.CurePoison(winner);
			loser.CurePoison(loser);

			winner.SendMessage( 1161, "Good job on winning your match. Please hang tight for your next match." );
			loser.SendMessage( 1161, "Sorry, you have lost so you are no longer part of this tournament." );

			AdvanceRound();
		}

		public void GateTimer()
		{
			GTimer g = new GTimer(this);
			g.Start();
		}

		public void TourneyIsOver( Mobile winner, Mobile loser)
		{
			try{m_D1 = null;}catch{}
			try{m_D2 = null;}catch{}
			try{m_Advance = null;}catch{}
			try{m_Players.Clear();}catch{}
			try{m_NextRoundPlayers.Clear();}catch{}

			if(!winner.Alive)
				winner.Resurrect();

			if(!loser.Alive)
				loser.Resurrect();

			winner.Location = SpectatorArea;
			loser.Location = SpectatorArea;

			winner.AddToBackpack( new BankCheck( 100000 ) );
			winner.SendMessage( 1161, "Congratulations on winning the tournament. Your prize has been placed into your backpack.");

			Broadcast( AccessLevel.Player, String.Format("The tournament is over. {0} has won the tourney, and {1} came in second place. Make sure you congratulate them!", winner.Name, loser.Name) );

			TFundingBarrel m = FindLink();

			if(m != null)
			{
				m.Visible = true;
				[color=red]m.FReady = true;[/color]
				m.FCurrent = 0;
			}

			m_InUse = false;
		}

		public void SpawnGates()
		{
			DespawnGates();

			if( GateSpawn != GateSpawn.None )
			{
				if( GateSpawn == GateSpawn.FeluccaOnly || GateSpawn == GateSpawn.All )
				{
					for ( int i = 0; i < TInfo.FeluccaCities.Length; ++i )
					{
						try
						{
							TourneyGate m = new TourneyGate();
							m.Target = m_TargetDest;
							m.TargetMap = m_MapDest;
							m.MoveToWorld( TInfo.FeluccaCities[i], Map.Felucca );
							Gates.Add( m );
						}

						catch
						{
							Broadcast( "There was a minor error in the moongate generation. It is probably a minor error. If you receive this message, please report the bug." );
						}
					}
				}

				if( GateSpawn == GateSpawn.TrammelOnly || GateSpawn == GateSpawn.All )
				{
					for ( int i = 0; i < TInfo.TrammelCities.Length; ++i )
					{
						try
						{
							TourneyGate m = new TourneyGate();
							m.Target = m_TargetDest;
							m.TargetMap = m_MapDest;
							m.MoveToWorld( TInfo.TrammelCities[i], Map.Trammel );
							Gates.Add( m );
						}

						catch
						{
							Broadcast( "There was a minor error in the moongate generation. It is probably a minor error. If you receive this message, please report the bug." );
						}
					}
				}
			}

			Broadcast( "The moongates have been spawned in their respective towns." );
		}

		public override void OnDoubleClick( Mobile from )
		{
			if( from.AccessLevel < AccessLevel.GameMaster )
				from.SendMessage("You may not use this.");

			else
			{
				from.SendGump( new TConfigGump( this ) );
				from.SendMessage( 1161, "Please make sure that you set everything up before allowing tourney's!" );
			}
		}

		public void DespawnGates()
		{
			foreach( TourneyGate m in Gates )
			{
				m.Delete();
			}

			Gates.Clear();
		}

		public TFundingBarrel FindLink()
		{
			foreach( Item i in World.Items.Values )
			{
				if( i is TFundingBarrel )
				{
					if( (i as TFundingBarrel).Link == this )
					{
						return i as TFundingBarrel;
					}
				}
			}

			return null;
		}

		public Point2D Middle()
		{
			Rectangle2D r = m_DuelCoords;

			int wMid = r.X + (r.Width / 2);
			int hMid = r.Y + (r.Height / 2);

			Point2D mid = new Point2D( wMid, hMid );

			return mid;
		}

		public Point2D D1Dest()
		{
			Point2D dest = Middle();

			dest.Y -= 2;

			return dest;
		}

		public Point2D D2Dest()
		{
			Point2D dest = Middle();

			dest.Y += 2;

			return dest;
		}

		public void WallandMove()
		{
			Item x = new WallOfStoneEast(this);
			x.MoveToWorld( new Point3D( Middle().X, Middle().Y, m_ArenaZ ), m_MapDest );

			m_D1.MoveToWorld( new Point3D( D1Dest().X, D1Dest().Y, m_ArenaZ ), m_MapDest );

			m_D2.MoveToWorld( new Point3D( D2Dest().X, D2Dest().Y, m_ArenaZ ), m_MapDest );
		}

		public void Broadcast( string message )
		{
			Broadcast( AccessLevel.Counselor, message );
		}

		public void Broadcast( AccessLevel ac, string message )
		{
			foreach( NetState state in NetState.Instances )
			{
				Mobile m = state.Mobile;

				if ( m != null && m.AccessLevel >= ac )
					m.SendMessage( 1161, "[System Message]: {0}", message );
			}
		}

		public bool IsOnline( Mobile from )
		{
			if( from.NetState == null )
			{
				return false;
			}

			return true;
		}

		public bool IsMage( Mobile from ) //Mage
		{
			if(
				from.Skills[SkillName.Magery].Value >= 50     && /*Needs at least 50 magery to qualify */
				from.Skills[SkillName.EvalInt].Value >= 50    && /*Needs at least 50 evalint to qualify*/
				from.Skills[SkillName.Meditation].Value >= 50 &&
			       (from.Skills[SkillName.Swords].Value <= 30   ||   /*				                 */
				from.Skills[SkillName.Fencing].Value <= 30    ||   /* Can not have wep skill to qualify  */
				from.Skills[SkillName.Macing].Value <= 30     ||   /*				                 */
				from.Skills[SkillName.Archery].Value <= 30)   &&
				from.RawDex <= 50 && from.RawInt >= 50    )        /*Can not have more than 50 dexterity to qualify, and needs at least 50 int */

			{ return true; }

			return false;
		}

		public bool IsDexxer( Mobile from ) //Dexxer
		{
			if((
				from.Skills[SkillName.Swords].Value >= 50  ||   /*				   */
				from.Skills[SkillName.Fencing].Value >= 50 ||   /* Needs a weapon skill to qualify */
				from.Skills[SkillName.Macing].Value >= 50  ||   /*				   */
				from.Skills[SkillName.Archery].Value >= 50)&&
				from.Skills[SkillName.Magery].Value <= 30  &&   /*Can not have more than 30 magery to qualify. */
				from.RawInt <= 50	&& from.RawDex >= 50    )	/*Can not have more than 50 int to qualify, and needs at least 50 dex     */

			{ return true; }

			return false;
		}

		public bool IsTank( Mobile from ) //Tank
		{
			if((
				from.Skills[SkillName.Swords].Value >= 50  ||   /*				      */
				from.Skills[SkillName.Fencing].Value >= 50 ||   /* Needs a weapon skill to qualify    */
				from.Skills[SkillName.Macing].Value >= 50  ||   /*				      */
				from.Skills[SkillName.Archery].Value >= 50)&&
				from.Skills[SkillName.Magery].Value >= 50 )     /*Needs at least 50 magery to qualify */

			{ return true; }

			return false;
		}

		public bool Is7x( Mobile from ) //7x Check
		{
			if(from.SkillsTotal == 7000)
				return true;

			return false;
		}

		public bool Is5x( Mobile from ) //5x Check
		{
			if(from.SkillsTotal <= 5000) //Change to == for exactly 5x. This just makes sure they don't have over.
				return true;

			return false;
		}

		public void AcceptPlayer( Mobile from )
		{
			from.SendMessage( 1161, "You have met the pre-requisites, and have been accepted into the tourney. Please have patients, it will begin soon." );
			m_Players.Add( from );
		}

		public void WeaponCheck( Mobile from )
		{
			if( DuelType == DuelType.Mage )
			{
				Item toBank = from.FindItemOnLayer( Layer.OneHanded );
				Container bp = from.BankBox;
				Container pack = from.Backpack;
				Item holding = from.Holding;

				if( holding != null )
				{
					bp.DropItem(holding);
					from.SendMessage( 1161, "The item that you were holding has been moved to you bankbox due to restrictions on the tourney." );
				}
				
				if ( toBank == null || !toBank.Movable )
					toBank = from.FindItemOnLayer( Layer.TwoHanded );
				
				if (toBank != null && bp != null && toBank is BaseWeapon)
				{
					bp.DropItem(toBank);
					from.SendMessage( 1161, "Some equipment has been moved to your bankbox due to restrictions on the tourney." );
				}

				foreach( Item i in new ArrayList( pack.Items ) )
				{
					if(i.Map != Map.Internal)
					{
						if(i is BaseWeapon)
						{
							bp.DropItem(i);
							from.SendMessage( 1161, "Some equipment was moved to your bankbox due to restrictions on this tourney." );
						}
					}
				}
			}

			if( !m_MagicWeapons )
			{
				Item toBank = from.FindItemOnLayer( Layer.OneHanded );
				Container bp = from.BankBox;
				Container pack = from.Backpack;
				Item holding = from.Holding;

				if( holding != null )
				{
					if(IsMagicWeapon(holding))
					{
						bp.DropItem(holding);
						from.SendMessage( 1161, "The item that you were holding has been moved to you bankbox due to restrictions on the tourney." );
					}
				}

				if ( toBank == null || !toBank.Movable )
					toBank = from.FindItemOnLayer( Layer.TwoHanded );

				if (toBank != null && bp != null && toBank is BaseWeapon)
				{
					if(IsMagicWeapon(toBank))
					{
						bp.DropItem(toBank);
						from.SendMessage( 1161, "Some equipment has been moved to your bankbox due to restrictions on the tourney." );
					}
				}

				foreach( Item i in new ArrayList( pack.Items ) )
				{
					if(i.Map != Map.Internal)
					{
						if(i is BaseWeapon || i is BaseArmor || i is BaseJewel)
						{
							if(IsMagicWeapon(i))
							{
								bp.DropItem(i);
								from.SendMessage( 1161, "Some equipment was moved to your bankbox due to restrictions on this tourney." );
							}
						}
					}
				}
			}	
		}

		public bool IsMagicWeapon( Item from )
		{
			bool strike = false;

			if( from is BaseWeapon )
			{
				BaseWeapon b = (BaseWeapon)from;

				if( b.AccuracyLevel > 0 || b.DamageLevel > 0 || b.DurabilityLevel > 0 || b.Slayer > 0 || b.ArtifactRarity > 0 )
					strike = true;
			}

			if( from is BaseArmor )
			{
				BaseArmor b = (BaseArmor)from;

				if(b.ArtifactRarity > 0)
					strike = true;
			}

			if( from is BaseJewel )
			{
				BaseJewel b = (BaseJewel)from;

				if(b.ArtifactRarity > 0)
					strike = true;
			}

			return strike;
		}

		public void DenyPlayer( Mobile from )
		{
			from.SendMessage( 1161, "We are sorry, but you do not meet the pre-requisites. Read the tourney rules for more info.");
		}

		public bool IsParticipant( Mobile from )
		{
			try
			{
				if( m_Players.Contains(from) || m_NextRoundPlayers.Contains(from) || m_D1 == from || m_D2 == from || m_Advance == from )
				{
					return true;
				}

				return false;
			}

			catch
			{return false;}
		}

		public void VerifyJoin( Mobile from )
		{
			if(InUse)
				return;

			if( IsParticipant(from) )
			{
				from.SendMessage( 1161, "You are already signed up for the tourney.");
				return;
			}

			bool canJoin = true;

			switch( DuelType )
			{
				case DuelType.Any:
				{
					break;
				}

				case DuelType.Mage:
				{
					if(IsMage(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelType.Dexxer:
				{
					if(IsDexxer(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelType.Tank:
				{
					if(IsTank(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}
			}

			switch( DuelSet )
			{
				case DuelSet.Allow:
				{
					break;
				}

				case DuelSet.Sevenx:
				{
					if(Is7x(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}

				case DuelSet.Fivex:
				{
					if(Is5x(from))
						break;

					else
					{
						canJoin = false;
						break;
					}
				}
			}

			if(canJoin)
				AcceptPlayer(from);

			else
				DenyPlayer(from);
		}

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

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

			writer.Write((int) 6); //Version

			writer.Write( (int) m_MinPlayers );
			writer.Write( m_MagicWeapons );
			writer.Write( (int) m_DuelType );
			writer.Write( (int) m_DuelSet );

			writer.Write( (int) m_ArenaZ );

			writer.Write( m_CanHeal );
			writer.Write( m_CanUsePotions );

			WriteBitArray( writer, m_RestrictedSpells );
			WriteBitArray( writer, m_RestrictedSkills );

			writer.Write( m_TargetDest );
			writer.Write( m_MapDest );

			writer.Write( (int) m_GateSpawn );

			writer.Write( (Rectangle2D) m_DuelCoords );
		}

		#region Serialization Helpers

		public static void WriteBitArray( GenericWriter writer, BitArray ba )
		{
			writer.Write( ba.Length );

				for( int i = 0; i < ba.Length; i++ )
				{
					writer.Write( ba[i] );
				}
			return;
		}

		public static BitArray ReadBitArray( GenericReader reader )
		{
			int size = reader.ReadInt();
			BitArray newBA = new BitArray( size );

			for( int i = 0; i < size; i++ )
			{
				newBA[i] = reader.ReadBool();
			}

			return newBA;
		}

		#endregion

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

			curStone = this;

			int version = reader.ReadInt();

			switch ( version )
			{
				case 6:
				{
					m_MinPlayers = reader.ReadInt();
					m_MagicWeapons = reader.ReadBool();
					m_DuelType = (DuelType)reader.ReadInt();
					m_DuelSet = (DuelSet)reader.ReadInt();

					goto case 5;
				}
				case 5:
				{
					m_ArenaZ = reader.ReadInt();
					goto case 4;
				}
				case 4:
				{
					m_CanHeal = reader.ReadBool();
					m_CanUsePotions = reader.ReadBool();

					goto case 3;
				}

				case 3:
				{
					m_RestrictedSpells = ReadBitArray( reader );
					m_RestrictedSkills = ReadBitArray( reader );

					goto case 2;
				}

				case 2:
				{
					m_TargetDest = reader.ReadPoint3D();
					m_MapDest = reader.ReadMap();

					m_GateSpawn = (GateSpawn)reader.ReadInt();

					goto case 1;
				}

				case 1:
				{
					m_DuelCoords = reader.ReadRect2D();

					goto case 0;
				}

				case 0:
				{
					break;
				}
			}
		}

		public void UpdateRegion()
		{
			if( m_DuelingRegion == null )
			{
				m_DuelingRegion = new DuelRegion( this, this.Map );
			}

			try
			{
				Region.RemoveRegion( m_DuelingRegion );

				m_DuelingRegion.Coords.Clear();

				m_DuelingRegion.Coords.Add( m_DuelCoords );

				m_DuelingRegion.Disabled = true;

				m_DuelingRegion.Map = this.Map;

				Region.AddRegion( m_DuelingRegion );

				return;
			}

			catch
			{
				m_DuelCoords = new Rectangle2D();
			}
		}


		public static int GetRegistryNumber( ISpell s )
		{
			Type[] t = SpellRegistry.Types;

			for( int i = 0; i < t.Length; i++ )
			{
				if( s.GetType() == t[i] )
					return i;
			}

			return -1;
		}

		public bool IsRestrictedSpell( ISpell s )
		{
			int regNum = GetRegistryNumber( s );
			
			if( regNum < 0 )	//Happens with unregistered Spells
				return false;

			return m_RestrictedSpells[regNum];
		}

		public bool IsRestrictedSkill( int skill )
		{
			if( skill < 0 )
				return false;

			return m_RestrictedSkills[skill];
		}

		public void ChooseArea( Mobile m )
		{
			BoundingBoxPicker.Begin( m, new BoundingBoxCallback( DuelRegion_Callback ), this );
		}

		private static void DuelRegion_Callback( Mobile from, Map map, Point3D start, Point3D end, object state )
		{
			DoChooseArea( from, map, start, end, state );
		}

		private static void DoChooseArea( Mobile from, Map map, Point3D start, Point3D end, object control )
		{
			MasterTStone r = (MasterTStone)control;
			Rectangle2D rect = new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 );

			r.m_DuelCoords = rect;

			r.UpdateRegion();
		}

		public override void OnDelete()
		{
			if( m_DuelingRegion != null )
				Region.RemoveRegion( m_DuelingRegion );

			try{m_Players.Clear();}catch{}		    /*                      */
			try{m_NextRoundPlayers.Clear();}catch{}     /*   Didn't feel like   */ 
			try{m_D1 = null;}catch{}		    /*      adding null     */
			try{m_D2 = null;}catch{}		    /*        checks        */
			try{m_Advance = null;}catch{}		    /*	                    */

			base.OnDelete();
		}

		public override void OnMapChange()
		{
			UpdateRegion();
			base.OnMapChange();
		}

		public void ShowBounds( Rectangle2D r, Map m )
		{
			if( m == Map.Internal || m == null )
				return;

			Point3D p1 = new Point3D( r.X, r.Y - 1, 0 );
			Point3D p2 = new Point3D( r.X, r.Y + r.Height - 1, 0 );

			Effects.SendLocationEffect( new Point3D( r.X -1, r.Y - 1, m.GetAverageZ( r.X, r.Y -1 ) ) , m, 251, 75, 1, 1151, 3 );	//Top Corner	//Testing color

			for( int x = r.X; x <= ( r.X + r.Width -1 ); x++ )
			{
				p1.X = x;
				p2.X = x;

				p1.Z = m_ArenaZ;
				p2.Z = m_ArenaZ;

				Effects.SendLocationEffect( p1, m, 249, 75, 1, 1151, 3 );	//North bound
				Effects.SendLocationEffect( p2, m, 249, 75, 1, 1151, 3 );	//South bound
			}

			p1 = new Point3D( r.X -1 , r.Y -1 , 0 );
			p2 = new Point3D( r.X + r.Width - 1, r.Y, 0 );

			for( int y = r.Y; y <= ( r.Y + r.Height -1 ); y++ )
			{
				p1.Y = y;
				p2.Y = y;

				p1.Z = m_ArenaZ;
				p2.Z = m_ArenaZ;

				Effects.SendLocationEffect( p1, m, 250, 75, 1, 1151, 3 );	//West Bound
				Effects.SendLocationEffect( p2, m, 250, 75, 1, 1151, 3 );	//East Bound
			}
		}

		public class GTimer : Timer
		{
			MasterTStone m_Stone;

			public GTimer( MasterTStone stone ) : base( TimeSpan.FromMinutes( 10.0 ) ) 
			{
				m_Stone = stone;

				AnnounceTimer at = new AnnounceTimer(m_Stone);
				at.Start();

				m_Stone.SpawnGates();
			}

			protected override void OnTick()
			{
				if(m_Stone.MinPlayers <= m_Stone.Players.Count)
				{
					if(!(m_Stone.InUse))
					{
						m_Stone.StartTheTourney();
						m_Stone.DespawnGates();
					}

					else
						m_Stone.Broadcast("It appears that the tournament has already started.");
				}

				else	
				{
					m_Stone.Broadcast( AccessLevel.Player, "There was not enough people signed up for the tourney, so there will be another 10 minutes to sign up." );
					GTimer g = new GTimer(m_Stone);
					g.Start();
				}
			}
		}

		public class AnnounceTimer : Timer
		{
			MasterTStone m_Stone;
			int count = 0;

			public AnnounceTimer( MasterTStone stone ) : base( TimeSpan.FromMinutes( 5.0 ) )
			{
				m_Stone = stone;
				m_Stone.Broadcast( AccessLevel.Player, "The tourney signups are open. If you would like to participate, please find the nearest moongate to the tourney area." );
			}

			protected override void OnTick()
			{
				if(count <= 5)
				{
					count += 5;
					AnnounceTimer at = new AnnounceTimer( m_Stone );
					at.Start();
				}
			}
		}
	}
}
Try changing, the part i highlighted in red in your quote. to this

Code:
m.FReady = false;
 

noob2

Wanderer
So does anyone know when this is going to be(the next release)?

Also i have a suggestion to make.
You should make a second stone just for dualing arenas and then have a gump with a list of arenas. If anyone is in them and if so what char. names and how many loses/wins they have and then theres a button by each listing that you can click to get teleported to the arena. Then maybe like an an easy win/lose system that requires no distro script edits that would be awsome!! Maybe like you can have mobiles which you can dual for training in the dual arenas. And instead of gumps you make it like keywords like abcuo has it.

That would be awsome!

anyways thanks man i'm such a noob
 

Jeff

Lord
noob2 said:
So does anyone know when this is going to be(the next release)?

Also i have a suggestion to make.
You should make a second stone just for dualing arenas and then have a gump with a list of arenas. If anyone is in them and if so what char. names and how many loses/wins they have and then theres a button by each listing that you can click to get teleported to the arena. Then maybe like an an easy xml win/lose system that requires no distro script edits that would be awsome!! Maybe like you can have mobiles which you can dual for training in the dual arenas. And instead of gumps you make it like keywords like abcuo has it.

That would be awsome!

anyways thanks man i'm such a noob
Well milt is away atm and is very busy IRL so i dont know when the next version will be out, but i do know that the things he wants to do require lots of complex coding and code time. Thus it may be some time before it is out. Also XML sucks, there are better ways to do a system aside from XML is a bitch to program and a mess to take char of, I personally hate it dispise it and dont see what so many ppl love it.

If i talk to milt before he is able to check this i will pass the message along.
 

noob2

Wanderer
well some sort of point system other then pm edits would be great cus pm edits like screw up your world saves and if you decide to upgrade your server or something or you want to take the system out then it messes up your saves
 

burento

Wanderer
MILT MAN!!!

You can do what you like bro.. The script is great..

I have seen alot of suggestions and i would like to ask if you would not mind putting a poll up and letting us vote on the changes.

Of course i would not imagine saying you need to care what we think but if our opinion does sway where your energy goes then a poll would let you know your crazy fan followings feelings.

Hahah.
 

milt

Knight
Ok, so although I have heard many suggestions already, I'm going to set something up. If you have any suggestions, make it easy for me and do something like the following

Here is my suggestion I think that you should blah blah blah. I put my suggestion in quotes so it is easier for me to read.
So yeah, just wrap quote tags around your suggestions in a single post so I know what to look for. I am open to suggestions :)

Also, this system is meant to be a tournament system. That is why it does not have a dueling feature, etc. Maybe I'll have to release a package with multiple systems, or maybe I will just make it so that you can get "tourney points" for every time you win a tourney.
 

Jeff

Lord
noob2 said:
well some sort of point system other then pm edits would be great cus pm edits like screw up your world saves and if you decide to upgrade your server or something or you want to take the system out then it messes up your saves
Only if you don't know what you are doing, I on many many occasions have edited playermobile.cs and removed things from it saves included, its not hard you just have to be smart about it and logical
 

Crowley62

Sorceror
Please fix the script so it is automatic. The funding barrel now resets the gold ammount but keeps sending the message that the sign ups are now open use a gate to get to tourney. Only problem is there are no gates because the tourney just ended. It would be real nice to let players fund the barrel and hve tourneys but right now it is impossible. Great script with the exception of the funding barrel.
 

noob2

Wanderer
milt said:
Maybe I'll have to release a package with multiple systems, or maybe I will just make it so that you can get "tourney points" for every time you win a tourney.

that would pwn man you should do that and if you have not seen my awsome suggestions for the system then just go back a page i think it is i'll put it in a box for easy reading lol
 

Crowley62

Sorceror
Anyone else haveing this problem? Everytime we add the fundingbarrel, it is good till we restart then server will not start till we delete funding barrel on console. That damn barrel!!!
 

Blazus

Sorceror
There's a bug in that system when the match is started and then my opponent makes log out I'm automaticly a winner and the system moves me to spectral area. The SEcond Fight starts but when my opponent logs in again the whole game serwer crashes.
 

burento

Wanderer
Crowley62 said:
Please fix the script so it is automatic. The funding barrel now resets the gold ammount but keeps sending the message that the sign ups are now open use a gate to get to tourney. Only problem is there are no gates because the tourney just ended. It would be real nice to let players fund the barrel and hve tourneys but right now it is impossible. Great script with the exception of the funding barrel.

If you read back we have about 4 pages of trying to fix this.. me and sorious.. When we get it fixed i will post a easy altering guide to fix it..

Also i will put the other fixes throughout the thread in one post.. A sort of recap of personal fixes that you can use.

Cool.
 

burento

Wanderer
noob2 said:
man i hope the new release comes out soon there seems to be alot of bugs :(

Actually only about 1 or 2 impacting bugs have been found. A lot have been found because we all have our own agendas but only a few that come from Milts actually intention of the script.

FUNDING BARREL PEOPLE>>>> DO NOT USE IT AT ALL RIGHT NOW> It just doesnt work until a few parts get fixed.

Also if you look back there is other people with the shard crash issues with funding barrel and it was fixed before.
 
Top