/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Sep-24-2011 10:26:29pm
Filepath: scripts\Engines\peerless\other\Jormundgand\Mobiles\Peerless\Jormundgand.cs
Lines of code: 438

Description: 

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


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

namespace Server.Mobiles
{
	public class Jormundgand : BaseCreature
	{
		private Timer m_Timer;
       	private ArrayList spawns = new ArrayList();
       	private bool Enraged = false;
		Random rand = new Random(); 
		private int amount; 
       	
       	public override WeaponAbility GetWeaponAbility()
		{
			return WeaponAbility.Dismount;
		}
       
		[Constructable]
		public Jormundgand() : base( AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{	
			Name = "Jormungand";
			Hue = 332;
			Body = 150;
			BaseSoundID = 447;

			SetStr( 1281, 1305 );
			SetDex( 591, 815 );
			SetInt( 1226, 1250 );

			SetHits( 70000, 80000 );
			SetStam( 636, 945 );

			SetDamage( 5, 15 );

			SetDamageType( ResistanceType.Physical, 40 );
			SetDamageType( ResistanceType.Poison, 60 );

			SetResistance( ResistanceType.Physical, 80, 90 );
			SetResistance( ResistanceType.Fire, 80, 90 );
			SetResistance( ResistanceType.Cold, 30, 40 );
			SetResistance( ResistanceType.Poison, 50, 60 );
			SetResistance( ResistanceType.Energy, 30, 40 );

			SetSkill( SkillName.EvalInt, 70);
			SetSkill( SkillName.Magery, 70);
			SetSkill( SkillName.MagicResist, 80);
			SetSkill( SkillName.Tactics, 100 );
			SetSkill( SkillName.Wrestling, 100 );

			Fame = 11500;
			Karma = -11500;

			VirtualArmor = 75;
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.AosUltraRich, 2 );
			AddLoot( LootPack.AosSuperBoss, 2);
			AddLoot( LootPack.FilthyRich, 3 );
		}

		public override bool NoFlee { get { return true; } }
		public override bool AutoDispel{ get{ return true; } }
		public override double AutoDispelChance{ get{ return 0.7; } }
		public override Poison HitPoison{ get{ return Poison.Lethal; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override double HitPoisonChance{ get{ return 0.1; } }
		
		public override bool HasBreath{ get{ return true; } }
		public override int BreathPhysicalDamage{ get{ return 0; } } 
		public override int BreathColdDamage{ get{ return 0; } }
		public override int BreathFireDamage{ get{ return 100; } }
		public override int breathtargets{ get{ return 6; } }
		public override double BreathDamageScalar{ get{ return (0.001665); } }  
		
		public override double BreathMinDelay{ get{ return 20.0; } }
		public override double BreathMaxDelay{ get{ return 40.0; } }
		
		public override int Hides{ get{ return 200; } }
		public override HideType HideType{ get{ return HideType.Barbed; } }
		public override int Scales{ get{ return 200; } }
		public override ScaleType ScaleType{ get{ return ScaleType.Black; } }
		
		public override bool ReacquireOnMovement{ get{ return true; } }
		
		public override bool BardImmune{ get{ return true; } }
		public override bool Unprovokable{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }
		
		public override bool CantbeSupreme { get { return true;} }
		
		public override int SuperAI_DelayMax{ get{ return 0; } }
		public override int SuperAI_Intensity{ get{ return 150; } }			

		private static readonly double[] m_Offsets = new double[]
			{
				Math.Cos( 000.0 / 180.0 * Math.PI ), Math.Sin( 000.0 / 180.0 * Math.PI ),
				Math.Cos( 040.0 / 180.0 * Math.PI ), Math.Sin( 040.0 / 180.0 * Math.PI ),
				Math.Cos( 080.0 / 180.0 * Math.PI ), Math.Sin( 080.0 / 180.0 * Math.PI ),
				Math.Cos( 120.0 / 180.0 * Math.PI ), Math.Sin( 120.0 / 180.0 * Math.PI ),
				Math.Cos( 160.0 / 180.0 * Math.PI ), Math.Sin( 160.0 / 180.0 * Math.PI ),
				Math.Cos( 200.0 / 180.0 * Math.PI ), Math.Sin( 200.0 / 180.0 * Math.PI ),
				Math.Cos( 240.0 / 180.0 * Math.PI ), Math.Sin( 240.0 / 180.0 * Math.PI ),
				Math.Cos( 280.0 / 180.0 * Math.PI ), Math.Sin( 280.0 / 180.0 * Math.PI ),
				Math.Cos( 320.0 / 180.0 * Math.PI ), Math.Sin( 320.0 / 180.0 * Math.PI ),
			};
		
		[CommandProperty( AccessLevel.GameMaster )]
		public override int ManaMax{ get{ return 5000; } }

		public Jormundgand( Serial serial ) : base( serial )
		{
		}
		
		public override void OnThink()
		{
			if (this.Hits < 30000 && Enraged == false)
			{
				Rage();
			}
		
			if (this.Combatant != null && 0.015 >= Utility.RandomDouble() && Enraged == false)
				Wave();
			else if (this.Combatant != null && 0.030 >= Utility.RandomDouble() && Enraged == true)
				Wave();
			else if (this.Combatant != null && 0.05 >= Utility.RandomDouble() && 0.05 >= Utility.RandomDouble() && Enraged == false)
				Whirl();		
			else if (this.Combatant != null && 0.07 >= Utility.RandomDouble() && 0.07 >= Utility.RandomDouble() && Enraged == true)
				Whirl();
				
		base.OnThink();	
		}
		
		/*public override void AlterMeleeDamageFrom( Mobile from, ref int damage )
		{
			if ( from is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)from;

				if ( bc.Controlled || bc.BardTarget == this )
					damage = (int)(damage * 0.7); // Reduced Damage
			}
		}*/
		
		public void Wave()
		{
			ArrayList list = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 15 ) )
			{
				if ( m == this || !CanBeHarmful( m ) || !this.InLOS( m ))
					continue;

				if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team ) )
					list.Add( m );
				else if ( m.Player )
					list.Add( m );
			}

			foreach ( Mobile m in list )
			{
				m.FixedParticles( 0x3709, 1, 30, 9904, 286, 1, EffectLayer.RightFoot, 1 );
				m.PlaySound( 18 );				
				m.SendMessage("The wave damages you and reduces your mana" );
				m.Damage(15); 
				m.Mana -= 20;
			}
		}
		
		public void Rage()
		{
			Enraged = true; 
			SetSkill( SkillName.EvalInt, 100 );
			SetSkill( SkillName.Magery, 100);
			SetSkill( SkillName.MagicResist, 100);
			SetSkill( SkillName.Tactics, 110);
			SetSkill( SkillName.Wrestling, 200);
			Hue = 2406;
			
			foreach ( Mobile m in this.GetMobilesInRange( 200 ) )
			{
				if ( m.Player && this.InLOS( m ) )
					m.SendMessage(33, "Jormundgand goes into a rage");
				else
					continue;
			}	
		}
		
		public void Whirl()
		{
			Map map = this.Map;
			ArrayList list = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 25 ) )
			{
				if ( m == this || !CanBeHarmful( m ) || this.Blessed || !this.InLOS( m ))
					continue;

				if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team ) )
					list.Add( m );
				else if ( m.Player )
					list.Add( m );
			}

			foreach ( Mobile m in list )
			{
				DoHarmful( m );
				m.Damage(20);
				m.Location = this.Location;
				this.PlaySound( 18 );
				Effects.SendLocationParticles( EffectItem.Create( this.Location, map, EffectItem.DefaultDuration ), 0x37CC, 1, 40, 1154, 3, 9917, 0 );
				m.SendMessage( "Jormundgand draws you into a whirlwind" );
			}
		}
			
		public override void OnDamage( int amount, Mobile attacker, bool willKill ) 
		{
			if(attacker!=null)
			{		
				if(attacker is BaseCreature && 0.4 >= Utility.RandomDouble())
				{
				BaseCreature atbc = attacker as BaseCreature;
				
					AOS.Damage( atbc, this, Utility.RandomMinMax( 80, 100 ), true, 100, 0, 0, 0, 0 );
				
					if(atbc.ControlMaster!=null)
					{
						atbc.ControlMaster.Hidden = false;
						Combatant=atbc.ControlMaster;
					}
					else if(atbc.SummonMaster!=null)
					{
						atbc.SummonMaster.Hidden = false;
						Combatant=atbc.SummonMaster;
					}
					
					if ((atbc.SummonMaster!=null && !this.InLOS(atbc.SummonMaster) ) || (atbc.ControlMaster!=null && !this.InLOS(atbc.ControlMaster)) )
					{
						AOS.Damage( atbc, this, Utility.RandomMinMax( 80, 100 ), true, 100, 0, 0, 0, 0 );
					}
				}
			
				if ( 0.05 >= Utility.RandomDouble() && 0.3 >= Utility.RandomDouble())
					SummonWhirlwind( attacker );	
			
			}
			base.OnDamage(amount, attacker, willKill );			
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
			if (!attacker.InRange( this, 6 ) && 0.5 >= Utility.RandomDouble())
			{
				SummonWhirlwind( attacker );
			}
			else if (!attacker.InRange( this, 3 ) && 0.6 >= Utility.RandomDouble())
			{
				attacker.Location = this.Location;
				this.Combatant = attacker;
				AOS.Damage( attacker, this, 25, true, 100, 0, 0, 0, 0 );
			}
		base.OnGotMeleeAttack( attacker );
		}
		
		public override void OnDamagedBySpell( Mobile caster )
		{
	
			if ( caster != this && GetLiveSpawns()<3 && !caster.InRange( this, 7 ))
			{
				caster.Location = this.Location;
				this.Combatant = caster;
				AOS.Damage( caster, this, 15, true, 100, 0, 0, 0, 0 );
			}

			base.OnDamagedBySpell( caster );
		}
		
		private int GetLiveSpawns()
		{
		int live=0;
				for( int i = 0; i < spawns.Count; ++i )
                {
                Mobile m = spawns[i] as Mobile;

                if( m == null || m.Deleted || !m.Alive)continue;
				live++;							
                }
				
		return live;
		}
		
		public void SummonWhirlwind( Mobile attacker )
		{
			Mobile spawn;
		
			if ( attacker != this && attacker.Alive && GetLiveSpawns() < 3 && Enraged == false)
			{
				if (GetLiveSpawns()==2)
				{
								
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
				}
				else if (GetLiveSpawns()==1)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);					
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
				else if (GetLiveSpawns()==0)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);			
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
			}
			else if ( attacker != this && attacker.Alive && GetLiveSpawns() < 5 && Enraged == true)
			{
				if (GetLiveSpawns()==4)
				{				
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
				else if (GetLiveSpawns()==3)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);					
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
				else if (GetLiveSpawns()==2)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);			
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
				else if (GetLiveSpawns()==1)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);			
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
				else if (GetLiveSpawns()==0)
				{
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);	
					spawn = new JormundgandWhirlwind();
					spawn.MoveToWorld( this.Location, this.Map );
					spawns.Add(spawn);		
					attacker.SendMessage( "Jormundgand creates whirlwinds" );
						
					if (!attacker.InRange( this, 5 ))
					{
						spawn = new AntiJormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
						spawn.Combatant = attacker;
					}
					else
					{
						spawn = new JormundgandWhirlwind();
						spawn.MoveToWorld( this.Location, this.Map );
						spawns.Add(spawn);	
					}	
				}
			}
		}
		/*
		public override bool OnBeforeDeath()
		{
		
			foreach ( Mobile m in this.GetMobilesInRange( 200 ) )
			{
				if ( m.Player && m.Region.IsPartOf( typeof( Server.Regions.PeerlessRegion ) ))
				{
					Item am = m.Backpack.FindItemByType(typeof(PalaceKey));
					if (am != null)
					{
						am.Delete();
					}
					Item ab = m.Backpack.FindItemByType(typeof(WaterNecklace));
					if (ab != null)
					{
						ab.Delete();
					}
				}
			}
			
			for ( int j = 0; j < 6; j++ )
			{
				PackItem(RandomMResources.Generate());	
			}
		
			for (int i = 0; i < 2; i++)
			{
				AddItem( new PetParrotStatue (Utility.RandomList(41, 495, 567, 48, 131, 75, 1001, 1169, 1155, 1164, 1160, 1162, 2210, 1324, 1157, 1364, 1156, 2101))); //Common hues/reward
			}
			
			if (0.15 >= Utility.RandomDouble())
				AddItem( new PetParrotStatue (Utility.RandomList(1281, 1158, 1266, 1150, 1167, 1109, 33, 1420, 1644, 1359))); //Uncommon 
			else if (0.05 >= Utility.RandomDouble())
				AddItem( new PetParrotStatue (Utility.RandomList(1166, 1165, 1172, 1168, 1175, 1152, 1161, 1151, 1154, 1153, 0, 1177)));//Rare reward hues

			switch ( Utility.Random( 60 ))
            {                                   
            	case 0: AddItem( new CrimsonCinture() ); break;
            	case 1: AddItem( new TheVilesTongue () ); break;   
            	case 2: AddItem( new SerpentsThroat () ); break;       	
		    }

			switch ( Utility.Random( 3 ))
            {                                   
            	case 0: AddItem( new SeaHairDye() ); break;   
            	case 1: AddItem( new JormundgandStatue () ); break;	
			}
			
			switch ( Utility.Random( 2 ))
            {                                   
				case 1: AddItem( new CorruptedHeart () ); break;  	
			}
			
			switch ( Utility.Random( 3 ))
            {                                   
            	case 1: AddItem( new BrazierOfDarkness() ); break;    	
			}
			
			switch ( Utility.Random( 5 ))
            {                                       
            	case 2: AddItem( new SeaTree() ); break;   	
			}
			
			switch ( Utility.Random( 7 ))
            {                                   
            	case 3: AddItem( new EternalFireball () ); break;     	
			}
			
			switch ( Utility.Random( 15 ))
            {                                   
				case 1: AddItem( new SeaSerpentSummoner() ); break;
				case 2: AddItem( new JormundgandIdol() ); break;
			}
			
			switch ( Utility.Random( 32 ))
            {                                   
            	case 0: AddItem( new PlateOfHonorArms() ); break;
            	case 1: AddItem( new PlateOfHonorChest() ); break;
				case 2: AddItem( new PlateOfHonorGloves () ); break;
            	case 3: AddItem( new PlateOfHonorGorget () ); break;       
				case 4: AddItem( new PlateOfHonorHelm () ); break;		
				case 5: AddItem( new PlateOfHonorLegs () ); break;		
				case 6: AddItem( new AcolyteArms() ); break;
            	case 7: AddItem( new AcolyteChest() ); break;
				case 8: AddItem( new AcolyteGloves () ); break;	
				case 9: AddItem( new AcolyteLegs () ); break;	
				case 10: AddItem( new EvocaricusSword() ); break;
            	case 11: AddItem( new MalekisHonor() ); break;
				case 12: AddItem( new GrizzleArms() ); break;
            	case 13: AddItem( new GrizzleChest() ); break;
				case 14: AddItem( new GrizzleGloves () ); break;       
				case 15: AddItem( new GrizzleHelm () ); break;		
				case 16: AddItem( new PlateOfHonorLegs () ); break;
				case 17: AddItem( new MageArmorArms() ); break;
            	case 18: AddItem( new MageArmorChest() ); break;
				case 19: AddItem( new MageArmorGloves () ); break;	
				case 20: AddItem( new MageArmorLegs () ); break;                    
				case 21: AddItem( new MyrmidonArms() ); break;
            	case 22: AddItem( new MyrmidonChest() ); break;
				case 23: AddItem( new MyrmidonGloves () ); break;
            	case 24: AddItem( new MyrmidonGorget () ); break;       
				case 25: AddItem( new MyrmidonHelm () ); break;		
				case 26: AddItem( new MyrmidonLegs () ); break;		
				case 27: AddItem( new DeathEssenceArms() ); break;
            	case 28: AddItem( new DeathEssenceChest() ); break;
				case 29: AddItem( new DeathEssenceGloves () ); break;      
				case 30: AddItem( new DeathEssenceHelm () ); break;		
				case 31: AddItem( new DeathEssenceLegs () ); break;		
			}
			
			if (0.8 >= Utility.RandomDouble()) AddItem( new JormundgandBile(1) );
			
			if (0.4 >= Utility.RandomDouble()) 
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(90,110, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(90,110, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(90,110, 2));break;      		
				}
			}
				
			if (0.10 >= Utility.RandomDouble()) 
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(110,130, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(110,130, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(110,130, 2));break;      		
				}
			}
			
			if (0.05 >= Utility.RandomDouble())
			{
				switch (Utility.RandomMinMax(0, 2 ))
				{
					case 0: PackItem(Loot.RandomMPWeapon(130,150, 0));break;
					case 1: PackItem(Loot.RandomMPWeapon(130,150, 1));break;
					case 2: PackItem(Loot.RandomMPWeapon(130,150, 2));break;      		
				}
			}	
			
			if (Map == Map.Felucca)
				amount = 12;
			else
				amount = 8;

			for (int n = 0; n < amount; n++)
			{
				switch (Utility.RandomMinMax(0, 5 ))
				{
					case 0: AddItem( new Taint(1));break;
					case 1: AddItem( new Muculent(1));break;
					case 2: AddItem( new Corruption(1));break;      		
					case 3: AddItem( new Blight (1));break;
					case 4: AddItem( new Scourge(1));break;
					case 5: AddItem( new Putrefaction(1));break;
				}
			}
			
			for(int i=Utility.Random(4);i>0;i--) PackItem(RandomRecipe.Peerless());

		return base.OnBeforeDeath();
		}		
		*/
		
		public override void OnAfterDelete()
		{

			base.OnAfterDelete();
		}		

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

			writer.Write((int) 0);
		}

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

			int version = reader.ReadInt();
		}
	}
}
