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


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

namespace Server.Items
{
	public class Organo_Venas : BaseOrgano
	{
		public static int[] VenasColors = new int[]
		{
			308,
			379,
			123,
			92,
			308,
			379,
			92
		};
		
		public static Point3D[] Pos_Venas = new Point3D[]
		{
			new Point3D( -27, -10, 0 ),
			new Point3D( 15, 22, 0 ),
			new Point3D( 12, -3, 0 ),
			new Point3D( 5, 35, 0 )
		};

		private Item m_Wound;
        private int m_CutVeinsCount = 0;

		public Organo_Venas( BrainTypes cerebro ) : base( 954, PlagueHelper.Line[15], VenasColors[Utility.Random(7)], cerebro )
		{
			Weight = 0;
		}

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

		public override void CreateTissue()
		{
			PutGuts( new Plague_deco( 955, PlagueHelper.Line[15], Hue, false, true) , -7, -5);
			PutGuts( new Plague_deco( 954, PlagueHelper.Line[15], Hue, false, true) , -10, 15);

			int veins = Utility.Random(4); 

			PutGuts( new Plague_Venas(this,VenasColors[(veins+0)%4], 0) , Pos_Venas[0].X,Pos_Venas[0].Y);
			PutGuts( new Plague_Venas(this,VenasColors[(veins+1)%4], 0) , Pos_Venas[1].X,Pos_Venas[1].Y);
			PutGuts( new Plague_Venas(this,VenasColors[(veins+2)%4], 1) , Pos_Venas[2].X,Pos_Venas[2].Y);
			PutGuts( new Plague_Venas(this,VenasColors[(veins+3)%4], 0) , Pos_Venas[3].X,Pos_Venas[3].Y);
			
			m_Wound = new Plague_deco( 4650 ,PlagueHelper.Line[8],1,false,false);
			PutGuts( m_Wound, -9, 13 );

		    MyBrain = new PlagueBrain( HeldBrainType );
		    PutGuts( MyBrain, -10, 20 );
			PlagueBrain Cere = MyBrain as PlagueBrain;

			Cere.CreateTissue( -4, -5 );
		}

		public void OnVeinCut( Mobile from, int color )
		{
			from.PlaySound( 0x248 );
			if ( color != Hue )
			{
				++m_CutVeinsCount;
				if (m_CutVeinsCount == 3)
				{
					PlagueBeastLord plaguebl = RootParent as PlagueBeastLord;
					if ( plaguebl == null )
						return;

					from.Direction = from.GetDirectionTo( plaguebl );
					if ( IsOpened )
					{
						from.LocalOverheadMessage( MessageType.Emote, 0x66B, false, PlagueHelper.Line[21] );
					}
					else
					{
						from.LocalOverheadMessage( MessageType.Emote, 0x66B, false, PlagueHelper.Line[22] );
						from.PlaySound( 0x2AC );

						m_Wound.Visible = true;
						IsOpened = true;
						if ( MyBrain.Deleted )
							return;
						if ( HeldBrainType == BrainTypes.Brain_None )
						{
							PlagueBrain pb = MyBrain as PlagueBrain;
							pb.MakeBleed( from );
						}
						else
							MyBrain.Visible = true;
					}
				}
			}
			else
			{
				PlagueBeastLord plaguebl = RootParent as PlagueBeastLord;
				if ( plaguebl != null )
					plaguebl.Kill();
			}
		}

		public override void OpenOrganTo( Mobile from )
		{
		}

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

			writer.Write( (int) 0 ); // version
            writer.Write( m_CutVeinsCount );
			writer.Write( (Item)m_Wound );
		}

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

			int version = reader.ReadInt();
			m_CutVeinsCount = reader.ReadInt();
			m_Wound = reader.ReadItem();

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