/**********************************************************
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_Calamar.cs
Lines of code: 133
***********************************************************/


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

namespace Server.Items
{
	public class Organo_Calamar : BaseOrgano
	{
		private Item m_Suborgan;
		private Item m_Wound;
		private Item m_GreenGland;
		private Item m_Tissue;

        private Item m_VeinI;
        private Item m_VeinII;
        private Item m_VeinIII;
        private Item m_VeinIV;
        
        private Item m_Stain;
        private Item m_GlandCase;

		private bool m_GlandIsReplaced = false;

		public Organo_Calamar( BrainTypes cerebro ) : base( 4962 , PlagueHelper.Line[15], 106, cerebro )
		{
			Weight = 0;
		}
       
		public Organo_Calamar( Serial serial ) : base( serial )
		{
		}

		public override void CreateTissue()
		{
			m_Tissue = new Plague_deco( 4650, PlagueHelper.Line[15], 106, false, false );
			PutGuts( m_Tissue, -2, 8 );
			m_GreenGland = new Plague_deco( 7407, PlagueHelper.Line[16], 166, true, false );
			PutGuts( m_GreenGland, -3, 15 );
			
			m_Suborgan = new Plague_deco( 4960, PlagueHelper.Line[17], 166, false, true );
			PutGuts( m_Suborgan, 75, 73 ); 
			
			m_VeinI = new Plague_deco( 6939, PlagueHelper.Line[26], 166, false, true );
			PutGuts( m_VeinI, 49, 49 );
			m_VeinII = new Plague_deco( 6939, PlagueHelper.Line[26], 166, false, true );
			PutGuts( m_VeinII, 43, 53 );
			m_VeinIII = new Plague_deco( 6939, PlagueHelper.Line[26], 166, false, true );
			PutGuts( m_VeinIII, 45, 64 );
			m_VeinIV = new Plague_deco( 6939, PlagueHelper.Line[26], 166, false, true );
			PutGuts( m_VeinIV, 25, 44 );
	
			m_GlandCase = new Plague_deco( 4959, PlagueHelper.Line[17], 166, false, true );
			PutGuts( m_GlandCase, 53, 64 );
			m_Stain = new Plague_deco( 7410, PlagueHelper.Line[15], 166, false, true ); 
			PutGuts( m_Stain, 22, 35 );

			m_Wound = new Plague_deco( 7027, PlagueHelper.Line[8], 1, false, false );
			PutGuts( m_Wound, 68, 80 );
			MyBrain = new PlagueBrain( HeldBrainType );
			PutGuts( MyBrain, 66, 82 );
			PlagueBrain Cere = MyBrain as PlagueBrain;
			Cere.CreateTissue( -4, -5 );
		}

		public void OnGlandDrop( Mobile from, Item gland )
		{
			if ( m_GreenGland.Parent == Parent )
				from.LocalOverheadMessage( MessageType.Emote,0x66B, false, PlagueHelper.Line[18] );
			if ( m_GlandIsReplaced )
				from.LocalOverheadMessage( MessageType.Emote,0x66B, false, PlagueHelper.Line[19] );

			if ( !m_GlandIsReplaced && !m_GreenGland.IsChildOf(RootParent) )
			{
				m_Suborgan.Hue = Hue;
				m_VeinI.Hue = Hue;
				m_VeinII.Hue = Hue;
				m_VeinIII.Hue = Hue;
				m_VeinIV.Hue = Hue;
				m_Stain.Hue = Hue;
				m_GlandCase.Hue = Hue;
				m_GlandIsReplaced = true;
				gland.Movable = false;
				m_Wound.Visible = true;
				base.OpenOrganTo( from );
				from.LocalOverheadMessage( MessageType.Emote, 0x66B, false, PlagueHelper.Line[20] );
				//If there is no brain, the wound begins to bleed directly
				if ( HeldBrainType == BrainTypes.Brain_None )
				{
					PlagueBrain brain = MyBrain as PlagueBrain;
					brain.MakeBleed( from );
				}
			}
		}

		public override void OpenOrganTo( Mobile from )
		{
			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( 0x248 );
				from.PlaySound( 0x2AC );
				m_Tissue.Visible = true;
				m_GreenGland.Visible = true;
			}
		}

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

			writer.Write( (int) 0 ); // version

			writer.Write( (Item)m_Wound );
			writer.Write( (Item)m_GreenGland );
			writer.Write( (Item)m_Tissue );
			writer.Write( (Item)m_Suborgan );
			writer.Write( (Item)m_VeinI );
			writer.Write( (Item)m_VeinII );
			writer.Write( (Item)m_VeinIII );
			writer.Write( (Item)m_VeinIV );
			writer.Write( (Item)m_Stain );
			writer.Write( (Item)m_GlandCase );
			writer.Write( (bool)m_GlandIsReplaced);
		}

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

			int version = reader.ReadInt();

			m_Wound = reader.ReadItem();
			m_GreenGland = reader.ReadItem();
			m_Tissue = reader.ReadItem();
			m_Suborgan = reader.ReadItem();
			m_VeinI = reader.ReadItem();
			m_VeinII = reader.ReadItem();
			m_VeinIII = reader.ReadItem();
			m_VeinIV = reader.ReadItem();
			m_Stain = reader.ReadItem();
			m_GlandCase = reader.ReadItem();
			m_GlandIsReplaced = reader.ReadBool();

			if ( m_Wound == null || m_GreenGland == null || m_Tissue == null || m_Suborgan == null || m_VeinI == null || m_VeinII == null || m_VeinIII == null || m_VeinIV == null || m_Stain == null || m_GlandCase == null)
				Delete();
		}
	}
}
