/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-24-2011 10:26:42pm
Filepath: scripts\Items\Artifacts\Artifacts of Assimilation\greater\grimreapersstrike.cs
Lines of code: 159

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 grimreapersstrike : Scythe
	{
	
			private static Type[] UndeadsList = new Type[]
			{
			typeof( LichLord ) , typeof( Lich ), typeof( SkeletalKnight ), typeof( BoneKnight ) , typeof(SkeletalDragon)
			};
	
	
		public override int InitMinHits{ get{ return 255; } }
		public override int InitMaxHits{ get { return 255; } }
		
		
		DateTime lastuse;	

		[Constructable]
		public grimreapersstrike() : base()
		{
			Name="Grim Reaper's Strike";
			Hue=37;


			Attributes.WeaponDamage=60;
			Attributes.SpellChanneling=1;
			WeaponAttributes.UseBestSkill = 1;
			Attributes.SpellDamage = 15;
			
			WeaponAttributes.HitHarm = 100;
			Slayer=SlayerName.Repond;		
		
			AosElementDamages.Physical=0;
			AosElementDamages.Fire=0;
			AosElementDamages.Cold=50;
			AosElementDamages.Poison=50;
			AosElementDamages.Energy=0;
			AosElementDamages.Chaos=0;		
		}
		

		
		
		public override void OnDoubleClick( Mobile from )
		{
		if(from==null)return;
		
		if(ParentEntity!=from)
		{
		from.SendMessage("You must equip this in order to summon undead");
		return;
		}		
		
		if(UseDelaySystem.CheckContext(from, DelayContextType.GrimReapers))
		{
		from.SendMessage("You must wait before using this ability again");
		return;
		}
	
		if(DateTime.Now<lastuse + TimeSpan.FromMinutes(30))
		{
		from.SendMessage("The staff has not fully charged yet.");
		return;
		}		
		
		if(from.Mana<25)
		{
		from.SendMessage("You must have at least 25 mana to perform this action");
		return;
		}
		
		if(from.Mana<from.ManaMax)
		{
		from.SendMessage("You must be at full mana to perform this action");
		return;
		}
		
		if ((from.Skills[SkillName.Necromancy].Value<100) || (from.Skills[SkillName.SpiritSpeak].Value<50))
		{
		from.SendMessage("You must have at least 100 necromancy and 50 spirit speak to use this weapon's summoning ability.");
		return;
		}
		
		if(from.Region.IsPartOf( typeof( GuardedRegion )))
		{
		from.SendMessage("You cannot use this here");		
		return;
		}
		
	    if(from.Backpack==null || !from.Backpack.ConsumeTotal( typeof(DaemonBone), 10 ))
		{
		from.SendMessage("You need 10 daemon bones to use this");
		return;
		}			
		
		
		UseDelaySystem.AddContext(from, DelayContextType.GrimReapers, TimeSpan.FromMinutes(5));
		

		
		int mobs = (((int)((from.Skills[SkillName.SpiritSpeak].Value+from.Skills[SkillName.Necromancy].Value)) + from.ManaMax)/10);
		
		if (mobs>30)mobs=30;
		if (mobs<10)mobs=10;

		
		
		
		bool didspawn=false;
		for(int i=0;i<mobs;i++)
		{
		int tx = from.X - (Utility.Random(50)-25);
		int ty = from.Y - (Utility.Random(50)-25);
		
		Map map = this.Map;	

		LandTile t = map.Tiles.GetLandTile( tx, ty );


		Point3D spawnpoint = new Point3D( tx, ty, t.Z );

		
				GuardedRegion reg = (GuardedRegion) Region.Find( spawnpoint, map ).GetRegion( typeof( GuardedRegion ) );
				if(reg != null && !reg.IsDisabled())
				{
				continue;
				}
		
				if ( map.CanSpawnMobile( new Point2D( tx, ty ), t.Z ) )
				{		
				Effects.SendLocationParticles( EffectItem.Create( spawnpoint, map, EffectItem.DefaultDuration ), 0x3789, 1, 40, 0x3F, 3, 9907, 0 );

				BaseCreature undead = Activator.CreateInstance( UndeadsList[Utility.Random( UndeadsList.Length )] ) as BaseCreature;

							Container pack = undead.Backpack;
					if ( pack != null )
					{
						for ( int itemsi = pack.Items.Count - 1; itemsi >= 0; --itemsi)
						{
							if ( itemsi >= pack.Items.Count )
								continue;

							pack.Items[itemsi].Delete();
						}
					}

				undead.ControlSlots=0;
				undead.Summoned = true;
			    undead.SummonMaster = from; 
				undead.MoveToWorld( spawnpoint, map );				

				Timer.DelayCall( TimeSpan.FromSeconds( 2.0 ), TimeSpan.FromSeconds( 0.1+ (from.Skills[SkillName.SpiritSpeak].Value/200)), new TimerStateCallback( Summoned_Damage ), undead );	

				didspawn=true;
				
				undead.PlaySound( 0x1FB );
				}

		}		

			if(didspawn)
			{
			from.SendMessage( "You summon massive undead from the ground!" );
			from.Mana=0;
			
			lastuse=DateTime.Now;
			}
			
		}
		
		private static void Summoned_Damage( object state )
		{
			Mobile mob = (Mobile)state;

			if ( mob.Hits > 0 )
				--mob.Hits;
			else
				mob.Kill();
		}

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

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

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

			int version = reader.ReadInt();

			if ( version <= 2 )
			{
		
				WeaponAttributes.HitLightning = 0;
				WeaponAttributes.HitHarm = 100;
				Attributes.WeaponDamage=60;
				Attributes.SpellDamage=0;				
			}

		}
	}
	
}