using Server.Accounting;
using Server.Commands.Generic;
using Server.Commands;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Network;
using Server.Regions;
using Server.Spells;
using Server.Targeting;
using Server;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System;

namespace Server.Items
{
	public class TaskManager : Item
	{
		[Constructable]
		public TaskManager () : base( 0x0EDE )
		{
			Movable = false;
			Name = "Task Manager";
			Visible = false;
			TaskTimer thisTimer = new TaskTimer( this ); 
			thisTimer.Start(); 
		}

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

		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();

			FirstTimer thisTimer = new FirstTimer( this ); 
			thisTimer.Start();
		}

		public class TaskTimer : Timer 
		{
			private Item i_item; 
			public TaskTimer( Item task ) : base( TimeSpan.FromMinutes( 60.0 ) )
			{ 
				Priority = TimerPriority.OneMinute; 
				i_item = task; 
			} 

			protected override void OnTick() 
			{
				TaskTimer thisTimer = new TaskTimer( i_item ); 
				thisTimer.Start(); 
				RunThis( i_item );
			} 
		}

		public class FirstTimer : Timer 
		{ 
			private Item i_item; 
			public FirstTimer( Item task ) : base( TimeSpan.FromSeconds( 10.0 ) )
			{ 
				Priority = TimerPriority.OneSecond; 
				i_item = task; 
			} 

			protected override void OnTick() 
			{
				TaskTimer thisTimer = new TaskTimer( i_item ); 
				thisTimer.Start(); 
				RunThis( i_item );
			} 
		}

		public static void RunThis( Item item )
		{
			TaskTimer thisTimer = new TaskTimer( item ); 
			thisTimer.Start();

			// ************************************************************************************

			ArrayList citizens = new ArrayList();
			foreach ( Mobile citizen in World.Mobiles.Values )
			if ( citizen is Citizen )
			{
				if ( citizen != null )
				{
					citizens.Add( citizen );
				}
			}
			for ( int i = 0; i < citizens.Count; ++i )
			{
				Mobile person = ( Mobile )citizens[ i ];
				person.Delete();
			}

			// ************************************************************************************

			ArrayList camps = new ArrayList();
			foreach ( Item camp in World.Items.Values )
			if ( camp is CampAAddon || camp is CampBAddon || camp is CampCAddon || camp is CampDAddon )
			{
				if ( camp != null )
				{
					camps.Add( camp );
				}
			}
			for ( int i = 0; i < camps.Count; ++i )
			{
				Item fire = ( Item )camps[ i ];
				fire.Delete();
			}

			// ************************************************************************************

			ArrayList traps = new ArrayList();
			foreach ( Item trap in World.Items.Values )
			{
				if ( trap is BaseTrap )
				{
					traps.Add( trap );
				}
			}

			for ( int i = 0; i < traps.Count; ++i )
			{
				BaseTrap trapped = ( BaseTrap )traps[ i ];




			}

			// ************************************************************************************
		}
	}
}