/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\Event System\events\CTF\CtfFlagBase.cs
Lines of code: 59
***********************************************************/


using Server;
using System;
using Server.Mobiles;

namespace Server.EventSystem
{
	public class CtfFlagBase : Item
	{
		
		private CtfEventController m_Controller;
		private int m_team;
		

		
		[CommandProperty( AccessLevel.GameMaster )]
		public CtfEventController Controller
		{
			get { return m_Controller; }
			set { m_Controller = value;Modify(); }
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int Team
		{
			get { return m_team; }
			set { m_team = value;Modify(); }
		}
		

				
		[Constructable]
		public CtfFlagBase() : base( 7026 )
		{
			Name="Flag Base";
			Movable=false;
			Visible=false;
		}


		
		
		
		public override bool OnMoveOver(Mobile m)
		{
			if(!m.Alive || !(m is PlayerMobile) || m.Backpack==null || Controller==null || Controller.EventStatus!=2 || m.Team==0)return true;

			CtfFlag flag = CtfEventController.GetFlag(m);
			
			if(flag!=null && flag.OwnerTeam!=Team && Team==m.Team)
			{
				flag.ReturnToBase(false,m);
				Controller.OnCaptureFlag(m.Team,m);	
				return false;				
			}

			return true;
		}		
		
		
	
		
		
		public CtfFlagBase( Serial serial ) : base( serial )
		{
		}
		
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write(m_Controller);
			writer.Write(m_team);

		}

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

			int version = reader.ReadInt();
			m_Controller=(CtfEventController)reader.ReadItem();
			m_team=reader.ReadInt();
	
		}	
	}
}