/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Aug-08-2011 09:29:13pm
Filepath: scripts\Items\artifacts\leviathan\CryOfTheKraken.cs
Lines of code: 123

Description: 

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


using Server;
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Items; 
using Server.ContextMenus; 
using Server.Misc; 
using Server.Mobiles;
using Server.Network; 
using Server.Regions;

namespace Server.Items
{ 
	public class CryOfTheKraken : ShepherdsCrook
	{

		public override int InitMinHits{ get{ return 255; } }
		public override int InitMaxHits{ get { return 255; } }
		
		
		DateTime lastuse;	

		[Constructable]
		public CryOfTheKraken() : base()
		{
			Name="Cry of the Kraken";
			Hue=688;

			Attributes.WeaponSpeed=100;
			
			WeaponAttributes.HitLeechMana = 50;
			WeaponAttributes.HitLeechStam = 50;
				
				
			AosElementDamages.Physical=50;
			AosElementDamages.Fire=0;
			AosElementDamages.Cold=50;
			AosElementDamages.Poison=0;
			AosElementDamages.Energy=0;						
		}
		
		
		public override void OnAfterLoad()
		{		
			Misc.ObjectConverter.ConvertItem(this,new CryOfTheKraken2());
		}		
		
		
		
		public override void OnDoubleClick( Mobile from )
		{
		
		if(from==null)return;
		
		if(ParentEntity!=from)
		{
		from.SendMessage("You must equip this in order to summon the kraken");
		return;
		}
		
	
		if(DateTime.Now<lastuse + TimeSpan.FromMinutes(8))
		{
		from.SendMessage("You must wait to use this ability again.");
		return;
		}		
		
		if(from.Mana<25)
		{
		from.SendMessage("You must have at least 25 mana to perform this action");
		return;
		}
		
		int mobs = 1;
		
		if (mobs>1)mobs=1;
		
		bool didspawn=false;
		for(int i=0;i<mobs;i++)
		{
		int tx = from.X - (Utility.Random(2)-2);
		int ty = from.Y - (Utility.Random(2)-2);
		
		Map map = this.Map;	

		Point3D loc = new Point3D(tx ,ty, -4);
						
		//check if its water:
		LandTile t = map.Tiles.GetLandTile( tx, ty );
			
		Point3D spawnpoint = new Point3D( tx, ty, from.Z );
		
				GuardedRegion reg = (GuardedRegion) Region.Find( spawnpoint, map ).GetRegion( typeof( GuardedRegion ) );
				if(reg != null && !reg.IsDisabled())
				{
				continue;
				}
		
				if ( map.CanSpawnMobile( new Point2D( tx, ty ), from.Z ) || ( (t.Z == -15) || ((t.Z == -5) && ( (t.ID >= 0xA8 && t.ID <= 0xAB) || (t.ID >= 0x136 && t.ID <= 0x137) || (t.ID == 100)  ) ) && !Spells.SpellHelper.CheckMulti( new Point3D( tx, ty, -5 ), map ) ))
				{		
				Effects.SendLocationParticles( EffectItem.Create( spawnpoint, map, EffectItem.DefaultDuration ), 0x3789, 1, 40, 688, 3, 9907, 0 );

				BaseCreature kraken = Activator.CreateInstance( typeof( SummonedKraken ) ) as BaseCreature;

				kraken.ControlSlots=0; 
			    kraken.Controlled = true;
			    kraken.ControlMaster = from;
				kraken.MoveToWorld( spawnpoint, map );				

		Timer.DelayCall( TimeSpan.FromMinutes( 5.0 ), TimeSpan.FromMinutes( 5.0 ), new TimerStateCallback( Summon_Vanish ), kraken );	
	
				didspawn=true;
				
				kraken.PlaySound( 38 );
				}

		}		

			if(didspawn)
			{
			from.SendMessage( "You summon a fearsome kraken to do your bidding" );
			from.Mana -= 25;
			
			lastuse=DateTime.Now;
			}
			else
			{
			from.SendMessage( "You cannot summon a kraken here" );
			}
			
		}
		
		private static void Summon_Vanish( object state )
		{
			Mobile mob = (Mobile)state;
			
			if (mob.Alive)
			{
				mob.Delete();
			}
		}

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

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

			writer.Write( (int) 2 );
		}
		
		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			if ( version <= 1 )
			{
				MaxHitPoints = 255;
				HitPoints = 255;
			}

			if( version == 0 )
				SkillBonuses.SetValues( 0, SkillName.AnimalLore, 5.0 );
		}
	}
	
}