/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Mar-09-2012 08:19:35pm
Filepath: scripts\Mobiles\custom mobiles - to sort\ML Named\Tangle.cs
Lines of code: 161

Description: 

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


using System;
using System.Collections;
using Server.Items;

namespace Server.Mobiles
{
	[CorpseName( "a tangle corpse" )]
	public class tangle : BaseCreature
	{
		public override WeaponAbility GetWeaponAbility()
		{
			switch ( Utility.Random( 2 ) )
			{
				default:
				case 0: return WeaponAbility.ConcussionBlow;
				case 1: return WeaponAbility.CrushingBlow;
			}
		}
	
		[Constructable]
		public tangle() : base( AIType.AI_Super, FightMode.Closest, 10, 1, 0.6, 1.2 )
		{
			Name = "Tangle";
			Body = 780;
			Hue = 32;

			SetStr( 843, 1021 );
			SetDex( 66, 82 );
			SetInt( 57, 78 );

			SetHits( 2505, 2787 );
			SetStam( 66, 82 );
			SetMana( 57, 78 );

			SetDamage( 15, 25 );

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

			SetResistance( ResistanceType.Physical, 52, 56 );
			SetResistance( ResistanceType.Fire, 40, 44 );
			SetResistance( ResistanceType.Cold, 33, 36 );
			SetResistance( ResistanceType.Poison, 69, 76 );
			SetResistance( ResistanceType.Energy, 42, 46 );

			SetSkill( SkillName.MagicResist, 109.6, 111.6 );
			SetSkill( SkillName.Meditation, 109.6, 111.6 );
			SetSkill( SkillName.Tactics, 96.7, 112.7 );
			SetSkill( SkillName.Wrestling, 85.2, 102.2 );

			Fame = 10000;
			Karma = -10000;

			VirtualArmor = 32;//Bog Thing is 28

			if ( 0.25 > Utility.RandomDouble() )
			{
				PackItem( new Board( 10 ) );
			}
			else
			{
				PackItem( new Log( 10 ) );
			}

			PackReg( 3 );
			PackItem( new Engines.Plants.Seed() );
			PackItem( new Engines.Plants.Seed() );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.UltraRich );
			AddLoot( LootPack.FilthyRich, 2 );
			AddLoot( LootPack.Gems, 6 );
		}

		public override bool IsMLBoss { get { return true;} }
		public override int TreasureMapLevel{ get{ return 6; } }
		public override double MLChestChance{ get{ return 0.05; } }
		
		public override Poison PoisonImmune { get { return Poison.Lethal; } }
		public override bool IsMLCreature { get { return true;} }
		public override bool BardImmune{ get{ return true; } }
		public override bool Uncalmable{ get{ return true; } }

		public override void OnDeath( Container c )
{
	if ( Utility.Random( 12 ) == 0 )
	{
		Item item;

		switch ( Utility.Random( 1 ))
		{
                        default:
			case 1: item = new TaintedSeeds(); break;
					}

		c.DropItem( item );
	}

	base.OnDeath( c );
}
		public tangle( Serial serial ) : base( serial )
		{
		}

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

		public void SpawnBogling( Mobile m )
		{
			Map map = this.Map;

			if ( map == null )
			{
				return;
			}

			Bogling spawned = new Bogling();

			spawned.Team = this.Team;

			bool validLocation = false;
			Point3D loc = this.Location;

			for ( int j = 0; !validLocation && j < 10; ++j )
			{
				int x = X + Utility.Random( 3 ) - 1;
				int y = Y + Utility.Random( 3 ) - 1;
				int z = map.GetAverageZ( x, y );

				if ( validLocation = map.CanFit( x, y, this.Z, 16, false, false ) )
				{
					loc = new Point3D( x, y, Z );
				}
				else if ( validLocation = map.CanFit( x, y, z, 16, false, false ) )
				{
					loc = new Point3D( x, y, z );
				}
			}

			spawned.MoveToWorld( loc, map );
			spawned.Combatant = m;
		}

		public void EatBoglings()
		{
			ArrayList toEat = new ArrayList();

			foreach ( Mobile m in this.GetMobilesInRange( 2 ) )
			{
				if ( m is Bogling )
				{
					toEat.Add( m );
				}
			}

			if ( toEat.Count > 0 )
			{
				PlaySound( Utility.Random( 0x3B, 2 ) ); // Eat sound

				foreach ( Mobile m in toEat )
				{
					Hits += (m.Hits/2);
					m.Delete();
				}
			}
		}

		public override void OnGotMeleeAttack( Mobile attacker )
		{
			base.OnGotMeleeAttack( attacker );

			if ( this.Hits > (this.HitsMax/4) )
			{
				if ( 0.25 >= Utility.RandomDouble() )
				{
					SpawnBogling( attacker );
				}
			}
			else if ( 0.25 >= Utility.RandomDouble() )
			{
				EatBoglings();
			}
		}
	}
}
