/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\mobiles\PoisonIvy.cs
Lines of code: 108
***********************************************************/


using System;
using System.Collections;
using Server;
using Server.Network;
using Server.Items;
using Server.Targeting;
using Server.Mobiles;

//TODO: Loot packs
//Ability Breakdown:
//Immune to poison
//Immobile
//When melee'd, creates a new vine (20 max)
//Poison hit 50% of the time
//Main ivy can concussion blow, copies crushing blow
//Throws poisonous spike balls at ranged opponents and mages

namespace Server.Mobiles
{
	[CorpseName("an ivy corpse")]
	public class PoisonIvy : BaseCreature
	{
		public int MaxSpawns = 0; 
		
		public override WeaponAbility GetWeaponAbility()
		{
			return WeaponAbility.ConcussionBlow;
		}

		[Constructable]
		public PoisonIvy() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
		{
			Name = "a poison ivy";
			Body = 8;
			Hue = 67;
			BaseSoundID = 684;

			SetStr( 161, 360 );
			SetDex( 151, 300 );
			SetInt( 21, 40 );

			SetHits( 265, 310 );

			SetDamage( 10, 28 );

			SetDamageType( ResistanceType.Physical, 50 );
			SetDamageType( ResistanceType.Poison, 50 );

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

			SetSkill( SkillName.Poisoning, 90.1, 100.0 );
			SetSkill( SkillName.MagicResist, 95.1, 100.0 );
			SetSkill( SkillName.Tactics, 80.1, 95.0 );
			SetSkill( SkillName.Wrestling, 120 );

			Fame = 8000;
			Karma = -8000;

			VirtualArmor = 40;
			PackItem( new Log( 10 ) );
			PackItem( new Nightshade (20) );
			PackItem( new MandrakeRoot( 5 ) );
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Rich, 4 );
			AddLoot( LootPack.Gems, 5 );
		}

		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override Poison HitPoison{ get{ return Poison.Lethal; } }
		public override double HitPoisonChance{ get{ return 0.5; } }
		public override bool DisallowAllMoves{ get{ return true; } }
		
		public override void OnDamagedBySpell(Mobile attacker)
		{
		if (!attacker.InRange( this, 1 ) && this.InLOS( attacker ))
		{
			attacker.SendMessage( "The ivy throws a toxic spike at you");
			attacker.ApplyPoison( this, Poison.Lethal );
			Effects.SendPacket( attacker, attacker.Map, new HuedEffect( EffectType.Moving, Serial.Zero, Serial.Zero, 0xC7B, this.Location, attacker.Location, 10, 0, false, false, 68, 0 ) );
			AOS.Damage( attacker, this, Utility.RandomMinMax( 40, 60 ), 0, 0, 0, 100, 0 );
		}
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
			Map map = attacker.Map;
			
			if (!attacker.InRange( this, 1 ) && this.InLOS( attacker ))
			{
			attacker.SendMessage( "The ivy throws a toxic spike at you");
			attacker.ApplyPoison( this, Poison.Lethal );
			Effects.SendPacket( attacker, attacker.Map, new HuedEffect( EffectType.Moving, Serial.Zero, Serial.Zero, 0xC7B, this.Location, attacker.Location, 10, 0, false, false, 68, 0 ) );
			AOS.Damage( attacker, this, Utility.RandomMinMax( 15, 35 ), 0, 0, 0, 100, 0 );
			}
			
			if (MaxSpawns < 10)
			{
				Mobile spawn = new PoisonIvySpawn();
				int x = this.X + Utility.RandomMinMax( -5, 5 );
				int y = this.Y + Utility.RandomMinMax( -5, 5 );
				int z = this.Z;
				if ( map.CanSpawnMobile( new Point3D( x, y, z) ) )
					{
					attacker.SendMessage( "The ivy grows another vine" );
					spawn.MoveToWorld( new Point3D( x, y, z ), Map );
					spawn.Combatant = attacker;
					}
				MaxSpawns += 1; 
			}	
		}
		
		public PoisonIvy(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();

			if ( BaseSoundID == -1 )
				BaseSoundID = 219;
		}
	}
}