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


using System;
using System.Collections;
using System.Collections.Generic;
using Server.Targeting;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
	[CorpseName( "a pile of metal" )]
	public class AorXXX : BaseCreature
	{

		[Constructable]
		public AorXXX() : base( AIType.AI_Melee, FightMode.Aggressor, 10, 1, 0.2, 0.4 )
		{
			Name = "AORXXX1";
			Title = "the metal minion";
			Body = 795;
			Hue = 2101;
			BaseSoundID = 0x39D;

			SetStr( 500, 500 );
			SetDex( 10, 10 );
			SetInt( 10, 10 );

			SetHits( 110, 110 );
			SetMana( 0 );

			SetDamage( 0, 0 );

			SetDamageType( ResistanceType.Physical, 100 );

			SetResistance( ResistanceType.Physical, 150, 150 );
			SetResistance( ResistanceType.Cold, 150, 150 );
			SetResistance( ResistanceType.Poison, 150, 150 );
			SetResistance( ResistanceType.Fire, 150, 150 );
			SetResistance( ResistanceType.Energy, 150, 150 );

			SetSkill( SkillName.MagicResist, 500.0, 500.0 );
			SetSkill( SkillName.Tactics, 0.0, 0.0 );
			SetSkill( SkillName.Wrestling, 120.0, 120.0 );

			Fame = 25000;
			Karma = 0;

			ControlSlots = 5;
			MinTameSkill = 117.1;

			AddItem( new LightSource() );
			PackItem( new IronIngot( Utility.RandomMinMax( 300, 500 ) ) );
			PackItem( new Gold( Utility.RandomMinMax( 3500, 5000 ) ) );
		}

		public override bool BleedImmune{ get{ return true; } }
		public override bool BardImmune{ get{ return !Core.AOS; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override void CheckReflect( Mobile caster, ref bool reflect )
		{
			reflect = true;
		}

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

			attacker.Damage( Utility.Random( 10, 30 ), this );
			attacker.Stam -= Utility.Random( 10, 30 );
		}

		public override void OnGaveMeleeAttack( Mobile defender )
		{
			base.OnGaveMeleeAttack( defender );

			if ( 0.05 > Utility.RandomDouble() )
			{
				/* Rune Corruption
				 * Start cliloc: 1070846 "The creature magically corrupts your armor!"
				 * Effect: All resistances -70 (lowest 0) for 5 seconds
				 * End ASCII: "The corruption of your armor has worn off"
				 */

				ExpireTimer timer = (ExpireTimer)m_Table[defender];

				if ( timer != null )
				{
					timer.DoExpire();
					defender.SendLocalizedMessage( 1070845 ); // The creature continues to corrupt your armor!
				}
				else
					defender.SendLocalizedMessage( 1070846 ); // The creature magically corrupts your armor!

				List<ResistanceMod> mods = new List<ResistanceMod>();

				if ( defender.PhysicalResistance > 0 )
					mods.Add( new ResistanceMod( ResistanceType.Physical, (defender.PhysicalResistance > 70) ? -70 : -defender.PhysicalResistance ) );

				if ( defender.FireResistance > 0 )
					mods.Add( new ResistanceMod( ResistanceType.Fire, (defender.FireResistance > 70) ? -70 : -defender.FireResistance ) );

				if ( defender.ColdResistance > 0 )
					mods.Add( new ResistanceMod( ResistanceType.Cold, (defender.ColdResistance > 70) ? -70 : -defender.ColdResistance ) );

				if ( defender.PoisonResistance > 0 )
					mods.Add( new ResistanceMod( ResistanceType.Poison, (defender.PoisonResistance > 70) ? -70 : -defender.PoisonResistance ) );

				if ( defender.EnergyResistance > 0 )
					mods.Add( new ResistanceMod( ResistanceType.Energy, (defender.EnergyResistance > 70) ? -70 : -defender.EnergyResistance ) );

				for ( int i = 0; i < mods.Count; ++i )
					defender.AddResistanceMod( mods[i] );

				defender.FixedEffect( 0x37B9, 10, 5 );

				timer = new ExpireTimer( defender, mods, TimeSpan.FromSeconds( 5.0 ) );
				timer.Start();
				m_Table[defender] = timer;
			}
		}

		private static Hashtable m_Table = new Hashtable();

		private class ExpireTimer : Timer
		{
			private Mobile m_Mobile;
			private List<ResistanceMod> m_Mods;

			public ExpireTimer( Mobile m, List<ResistanceMod> mods, TimeSpan delay ) : base( delay )
			{
				m_Mobile = m;
				m_Mods = mods;
				Priority = TimerPriority.TwoFiftyMS;
			}

			public void DoExpire()
			{
				for ( int i = 0; i < m_Mods.Count; ++i )
					m_Mobile.RemoveResistanceMod( m_Mods[i] );

				Stop();
				m_Table.Remove( m_Mobile );
			}

			protected override void OnTick()
			{
				m_Mobile.SendMessage( "The corruption of your armor has worn off" );
				DoExpire();
			}
		}

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

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

			writer.Write((int) 0);
		}

		public override void AddNameProperties( ObjectPropertyList list )
		{
			base.AddNameProperties( list );

			list.Add("Event Prize");
		}

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

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