/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-02-2010 02:32:22pm
Filepath: scripts\_custom\engines\Event System\events\pvptourney\TourneyArena.cs
Lines of code: 153
***********************************************************/


using Server;
using Server.Items;
using Server.Mobiles;
using System;
using System.Collections.Generic;


namespace Server.EventSystem
{
	public class TourneyArena : Item
	{	
		private Rectangle3D m_Area;
		private PvpTourneyEventController m_controller;
		private PvPMatch curmatch;    
		private Point3D m_OutLocation; //where people are sent after a death/match
		
		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsAvailable
		{
			get{return (curmatch==null || curmatch.status==0);}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MatchStatus
		{
			get{return (curmatch==null ? -1 : curmatch.status);}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MatchNumber
		{
			get{return (curmatch==null ? -1 : curmatch.matchnum);}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int ForceWinTeam
		{
			get{return 0;}
			set{if(curmatch!=null)curmatch.StopMatch(value);Modify();}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int RegHeight 
		{
			get {
					int tmp=Area.Start.Y-Area.End.Y;
					if(tmp<0)return tmp*-1;
					return tmp;
				}	
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int RegWidth 
		{
			get {
					int tmp=Area.Start.X-Area.End.X;
					if(tmp<0)return tmp*-1;
					return tmp;
				}			
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D OutLocation
		{
			get { return m_OutLocation; }
			set { m_OutLocation = value; Modify();}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public Rectangle3D Area
		{
			get{return m_Area;}
			set{m_Area = value;Modify();}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D Team1Start
		{
			get{return new Point3D(Area.MiddleX,Area.MiddleY-3,Z);}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D Team2Start
		{
			get{return new Point3D(Area.MiddleX,Area.MiddleY+3,Z);}
		}
		
		
		[CommandProperty( AccessLevel.GameMaster )]
		public PvpTourneyEventController Controller 
		{
			get { return m_controller; }
			set 
			{ 
				if(m_controller!=null)m_controller.RemoveArena(this);			
				m_controller=value;
				m_controller.AddArena(this);
				Modify();
			}			
		}
		
		
		
		[Constructable]
		public TourneyArena() : base(0xAFA)
		{
			Name="Tourney Arena Marker";
			Visible=false;
			Movable=false;
		}
		
		
		public void ClearMatch()
		{
			curmatch=null;
		}
		
		
		public override void Delete()
		{
			Controller.RemoveArena(this);
			base.Delete();
		}
		
		
		public override void OnDoubleClick( Mobile from )
		{
			if(from.AccessLevel>AccessLevel.Player)
			{
				Commands.RegionBounds.ShowRectBounds(Area, from.Map, from,false,true);
				
				Commands.RegionBounds.ShowPointBounds(from,Team1Start,0);
				Commands.RegionBounds.ShowPointBounds(from,Team2Start,0);
				
				DivWall(2);
			}
		}	
		

		public void StartMatch(PvPMatch pmatch)
		{
			curmatch=pmatch;
			curmatch.StartMatch();		
		}
		
		
		public void DivWall(int duration)
		{
			wallgenerator.GenerateDualWall(new Point3D(Area.MiddleX,Area.MiddleY,this.Z),this.Map,true,(Area.Width/2),duration,this.Hue);
		}
		
	
		public TourneyArena( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write((int) 0 ); // version		
			writer.Write(m_Area);
			writer.Write(m_controller);
			writer.Write(m_OutLocation);		
			
			if(curmatch!=null)
			{
				writer.Write(true);
				curmatch.Serialize(writer);
			}
			else writer.Write(false);
			
		}

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

			m_Area=reader.ReadRect3D();
			m_controller=(PvpTourneyEventController)reader.ReadItem();
			m_OutLocation=reader.ReadPoint3D();
			
			if(reader.ReadBool())
			{
				curmatch=new PvPMatch();
				curmatch.Deserialize(reader);		
			}
		
		}
	}
}ÿ