/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Mar-04-2011 09:28:42pm
Filepath: scripts\_custom\events and scenarios\Slime Event 2011\Slimes\AcidSlime.cs
Lines of code: 198

Description: 

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


using System;
using Server.Items;
using Server.Targeting;
using Server.Network;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Server.Mobiles
{
	[CorpseName( "an oozing corpse" )]
	public class AcidSlime : BaseCreature
	{
		//Decided not to serialize/deserialize these because they just reset to defaults on reload and it's not worth saving the 7-12 seconds worth of timers. 
		private bool m_BurstMembrane;
		private DateTime MembraneTimer; //Used to record the time frame where the acid slime can dye a weapon or spellbook
		private DateTime DelayTimer;//Used to add in a time delay between the last time the slime membrane was opened up. This is purely to ensure that overhead "say" text above the slime does not overlap.
		
		Random MembraneFuse = new Random(); 
	
		[Constructable]
		public AcidSlime() : base( AIType.AI_Super, FightMode.Aggressor, 10, 1, 0.2, 0.4 )
		{
			
			Name="an acid slime";
			
			switch(Utility.Random(25))
			{ 
				case 0: Name+=" [Light Olive]"; Hue = 2207; break;
				case 1: Name+=" [Light Blue]"; Hue = 2219; break;
				case 2: Name+=" [Dark Blue]"; Hue = 2224; break;	
				case 3: Name+=" [Light Red]"; Hue = 2201; break;		
				case 4: Name+=" [Dark Tan]"; Hue = 2218;break;	
				case 5: Name+=" [Dark Olive]"; Hue = 2211; break;
				case 6: Name+=" [Cardinal Red]"; Hue = 2118; break;	
				case 7: Name+=" [Dark Red]"; Hue = 2206; break;
				case 8: Name+=" [Orange]"; Hue = 2114; break;
				case 9: Name+=" [Yellow]"; Hue = 2213;break;
				case 10: Name+=" [Rum Red]"; Hue = 1644;break;
				case 11: Name+=" [Fire Orange]"; Hue = 1359; break;
				case 12: Name+=" [Nox Green]"; Hue = 1420; break;
				case 13: Name+=" [Paragon Gold]"; Hue = 1281; break;
				case 14: Name+=" [Berserker Red]"; Hue = 33; break;	
				case 15: Name+=" [Shadow Dancer Black]"; Hue = 1109; break;
				case 16: Name+=" [Luna White]"; Hue = 1150;break; 
				case 17: Name+=" [Red Blue]"; Hue = 1172; break;
				case 18: Name+=" [Europa Gold]"; Hue = 1177; break; 	
				case 19: Name+=" [Blaze Phoenix]"; Hue = 1161; break;
				case 20: Name+=" [Nobility Purple]"; Hue = 1278; break;
				case 21: Name+=" [Invulnerability Blue]"; Hue = 1266;break;
				case 22: Name+=" [Violet Courage Purple]"; Hue = 1158; break;  
				case 23: Name+=" [Frost Blue]"; Hue = 1152;break;
				case 24: Name+=" [Banana Yellow]"; Hue = 1169; break;
			}			
			
			Body = 51;
			BaseSoundID = 456;

			SetStr( 22, 34 );
			SetDex( 16, 21 );
			SetInt( 16, 20 );

			SetHits( 2500, 2900 );

			SetDamage( 1, 5 );

			SetDamageType( ResistanceType.Physical, 100 );
			
			SetResistance( ResistanceType.Physical, 5, 10 );
			SetResistance( ResistanceType.Poison, 10, 20 );

			SetSkill( SkillName.Poisoning, 30.1, 50.0 );
			SetSkill( SkillName.MagicResist, 15.1, 20.0 );
			SetSkill( SkillName.Magery, 30.1, 50.0 );
			SetSkill( SkillName.EvalInt, 15.1, 20.0 );
			this.Skills.Wrestling.Cap = 0;

			Fame = 300;
			Karma = -300;

			VirtualArmor = 8;

			Tamable = false;
		}
		
		public override bool CantbeSupreme { get { return true;} }
		public override bool CantbeParagon { get { return true;} }		
		
		public override void OnThink ()
		{
			if ( this.Alive && this!=null && m_BurstMembrane == true && (MembraneTimer < DateTime.Now) ) {
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The slime's membrane fuses back together *" );
				DelayTimer=DateTime.Now + TimeSpan.FromSeconds(10);
				m_BurstMembrane = false;
			}		
			base.OnThink();	
		}
		
		public override void OnGotMeleeAttack( Mobile attacker )
		{
			base.OnGotMeleeAttack( attacker );
			
			if (attacker!=null && 0.05 >= Utility.RandomDouble() && m_BurstMembrane == false && (DelayTimer < DateTime.Now))
			{
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The slime oozes colored blood as you damage its membrane *" );
				if(attacker.InRange( this, 1 )) attacker.SendMessage(39, "Further attacking at close range may permanently stain your weapon or spellbook!");
				m_BurstMembrane = true;
				MembraneTimer=DateTime.Now + TimeSpan.FromSeconds(MembraneFuse.Next( 4, 7 ));
				//Console.WriteLine("Membrane Timer INIT MELEE: " + MembraneTimer + " Datetime: " + DateTime.Now + "\n");
			}	
			else if ( 0.1 > Utility.RandomDouble() && attacker!=null && m_BurstMembrane == true && attacker.InRange( this, 1 ) ) 
			{
				BaseWeapon weapon = attacker.Weapon as BaseWeapon;

				if (weapon != null)
				{
					if (weapon is Fists) {
						Item book = attacker.FindItemOnLayer( Layer.OneHanded );
						
						if (weapon == null || book == null) return;
						attacker.SendMessage(200,"Your spellbook changes color upon contact with the slime's pigmented blood!");
						book.Hue = this.Hue;
					}
					else {
						attacker.SendMessage(200,"Your weapon changes color upon contact with the slime's pigmented blood!");
						weapon.Hue = this.Hue;
					}

					m_BurstMembrane = false;
					MembraneTimer=DateTime.Now;
					DelayTimer=DateTime.Now + TimeSpan.FromSeconds(10);
					PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The slime's membrane fuses back together *" );
				}
			}
			else if (attacker!=null && m_BurstMembrane == true && attacker.InRange( this, 1 ) ) 
			{
				attacker.SendMessage(39, "Further attacking at close range may permanently stain your weapon or spellbook!");
			}

		}
		
		public override void OnDamagedBySpell(Mobile attacker)
		{
			if (attacker!=null && 0.2 >= Utility.RandomDouble() && m_BurstMembrane == false && (DelayTimer < DateTime.Now))
			{
				PublicOverheadMessage( MessageType.Regular, 0x3B2, true, "* The slime oozes colored blood as you damage its membrane *" );
				m_BurstMembrane = true;
				MembraneTimer=DateTime.Now + TimeSpan.FromSeconds(MembraneFuse.Next( 4, 7 ));
			}	
		}	
		
		public override void OnDeath( Container c )
		{
			base.OnDeath( c );
			
			LootRights(this);
		}
		
		public static void LootRights(Mobile boss)
		{
			if(boss.Region!=null && !boss.Region.CanSpawnArtifacts())
				return;		
		
			ArrayList toGive = new ArrayList();
			List<DamageStore> rights = BaseCreature.GetLootingRights( boss.DamageEntries, boss.HitsMax );

			for ( int i = rights.Count - 1; i >= 0; --i )
			{
				DamageStore ds = rights[i];
				if ( ds.m_HasRight )	toGive.Add( ds.m_Mobile );
			}
			if ( rights.Count == 0 )return;	
			
			for(int i=0;i<rights.Count;i++)
			{
				Mobile m = rights[i].m_Mobile;			
				PlayerMobile mobile = m as PlayerMobile;
							
				Item basin = mobile.Backpack.FindItemByType(typeof(EmptySlimeBasin));
				if (!mobile.Alive)
				{
					mobile.SendMessage("The acid slime has been killed but as you are dead, you are unable to collect its pigmented blood.");
				}
				else if (basin == null) {
					mobile.SendMessage("You kill the slime but have no suitable basin to collect its pigmented blood.");
				}
				else if (!mobile.InRange( boss, 14 )) {
					mobile.SendMessage("You were too far from the acid slime's corpse. The pigmented blood has desolved before you could gather any.");
				}
				else
				{
					string pattern = Regex.Escape("[") + "(.*?)" + Regex.Escape("]"); 
					Match HueName = Regex.Match(boss.Name, pattern);
					
					/*if (s.Success) //Debug stuff
						Console.WriteLine("Match="+s.Groups[1].Value.ToString());
					else
						Console.WriteLine("No Match="+s.Groups[1].Value.ToString());*/

					Item fullBasin = new FullSlimeBasin(boss.Hue, HueName.Groups[1].Value.ToString());							
					Container pack = mobile.Backpack;

					if ( pack == null || !pack.TryDropItem( mobile, fullBasin , false )) {
						basin.Delete();
						mobile.SendMessage("As you cannot carry the full basin of slime, it has been sent to your bank box");
						mobile.BankBox.DropItem( fullBasin );								
					}
					else {
						basin.Delete();
						mobile.SendMessage("You collect the slime's pigmented blood into the basin.");
					}
				}						
			}
		}

		public override void GenerateLoot()
		{
			AddLoot( LootPack.Poor );
			AddLoot( LootPack.Gems );
		}

		public override Poison PoisonImmune{ get{ return Poison.Greater; } }
		public override Poison HitPoison{ get{ return Poison.Greater; } }

		public AcidSlime( 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();
			
			
			//following two lines can be removed on or after March 5 2011:
			if(IsParagon)IsParagon=false;
			if(IsSupreme)IsSupreme=false;			
		}
	}
}
