/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\engines\PlagueBeastLordQuest\Items\Plague_Blood.cs
Lines of code: 96
***********************************************************/


using System;
using Server;
using Server.Network;
using Server.Mobiles;

namespace Server.Items
{
	public class Plague_Blood : Item
	{
		private Item m_Bandage;

		private bool m_Aided = false;

		private Timer m_BleedingTimer;

		[CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )]
        public bool Aided
        {
            get {return m_Aided;}
            set {m_Aided = value;}
        }

		public Plague_Blood() : base( 0x122C )
		{
			Name = PlagueHelper.Line[8];
			Movable = false;
			Visible = false;
			Weight = 0;
		}

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

     	public virtual void CreateTissue()
		{
			Container c = Parent as Container;

		    m_Bandage = new Plague_deco( 6420, PlagueHelper.Line[9], 0, false, false );
		    c.AddItem( m_Bandage );
			m_Bandage.Location = new Point3D( X + 9, Y, 0 );
		}

		public virtual void DoBleed( Mobile from )
		{
			if ( !Visible && m_BleedingTimer == null )
			{
				Visible = true;
				m_BleedingTimer = Timer.DelayCall( TimeSpan.FromSeconds( 1 ), TimeSpan.FromSeconds( 1 ), new TimerCallback( OnBleedTimerTick ) );
				from.LocalOverheadMessage( MessageType.Emote, 0x66B, false, PlagueHelper.Line[10]) ;
			}
		}

		public virtual void BandAid(Mobile from)
		{
			if ( !m_Aided )
			{
     	    	m_Bandage.Visible = true;
				m_Aided = true;
				LabelTo( from, PlagueHelper.Line[11] );
			}
		}

		public void OnBleedTimerTick()
		{
			PlagueBeastLord plaguebl = RootParent as PlagueBeastLord;
			if ( Deleted || !Visible || Aided || plaguebl == null || !plaguebl.Alive )
			{
				m_BleedingTimer.Stop();
				return;
			}
			switch ( ItemID )
			{
				case 0x122C:
				{
					ItemID = 4654;
					X += 5;
					break;
				}
				case 4654: ItemID = 4653; break;
				case 4653: ItemID = 4650; break;
				default:
				{
					m_BleedingTimer.Stop();
					plaguebl.Kill();
					break;
				}
			}
		}

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

			writer.Write( (int) 0 ); // version
			writer.Write( (bool)m_Aided );
			writer.Write( (Item)m_Bandage );
		}

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

			int version = reader.ReadInt();
			m_Aided = reader.ReadBool();
			m_Bandage = reader.ReadItem();

			if ( m_Bandage == null )
				Delete();
		}
	}
}
