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


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

namespace Server.Items
{
	public class PlagueBrain : Item
	{
		private Item m_BleedingWound;
		private Item m_PlaguePack;

		private bool m_Opened = false;

		private BrainTypes m_BrainType;

		[CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )]
		public BrainTypes HeldBrainType
		{
			get {return m_BrainType;}
			set {m_BrainType = value;}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsOpened
		{
			get {return m_Opened;}
			set
			{
				if ( value ) //Only Open
					m_Opened = value;
			}
		}

		public Item MyWound
		{
			get {return m_BleedingWound;}
			set {m_BleedingWound = value;}
		}

		public Item MyPlaguePack
		{
			get {return m_PlaguePack;}
			set {m_PlaguePack = value;}
		}

		[Constructable]
		public PlagueBrain ( BrainTypes t ) : base( 7408 )
		{
			Name = PlagueHelper.Line[6]; 
			HeldBrainType = t;
			Hue = PlagueHelper.BrainColors[(int)t];
			Stackable = false;
			Movable = true;
			Weight = 40;
			Visible=false;
		}

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

		public virtual void CreateTissue( int offSetX,int offSetY )
		{
  		    Container c = Parent as Container;
			MyPlaguePack = c;
			MyWound = new Plague_Blood();
			c.AddItem( MyWound );
			MyWound.Location = new Point3D( X + offSetX - 5, Y + offSetY, 0 );
			Plague_Blood pb = MyWound as Plague_Blood;
			pb.CreateTissue();
		}
	
		public void MakeBleed( Mobile from )
		{
			Plague_Blood blood = MyWound as Plague_Blood;
			if ( blood != null )
				blood.DoBleed( from );
		}

		public override bool DropToMobile( Mobile from, Mobile target, Point3D p )
		{
			return false;
		}

		public override void OnItemLifted( Mobile from, Item item )
		{
			MakeBleed( from );
			base.OnItemLifted( from,item );
		}

		public override bool DropToItem( Mobile from, Item target, Point3D p )
		{
			if ( HeldBrainType != BrainTypes.Brain_None && target == MyPlaguePack )
			{
				PlagueBeastLord plaguebl = MyPlaguePack.Parent as PlagueBeastLord;
				Point3D p2 = PlagueHelper.BrainSlotPositions[(int)HeldBrainType];
				if ( p2.X <= p.X && p.X <= p2.X + 5 && p2.Y <= p.Y && p.Y <= p2.Y + 5 )
				{
					plaguebl.CoreCheck( (int)HeldBrainType - 1, true );
					Movable = false;
					from.LocalOverheadMessage( MessageType.Regular,0x66B,false,PlagueHelper.Line[7] );
				}
				else
					plaguebl.CoreCheck( (int)HeldBrainType - 1, false );
            }
			return ( target == MyPlaguePack && p.X != -1 && p.Y != -1 && base.DropToItem( from, target, p ) );
		}

		public override bool DropToWorld( Mobile from, Point3D p )
		{
			return false;
		}

		public override int GetLiftSound( Mobile from )
		{
			return 682;
		}

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

			writer.Write( (int) 0 ); // version
			writer.Write( (bool)m_Opened );
			writer.Write( (int)m_BrainType );
			writer.Write( (Item)m_BleedingWound );
			writer.Write( (Item)m_PlaguePack );
		}

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

			int version = reader.ReadInt();
			m_Opened = reader.ReadBool();
			m_BrainType = (BrainTypes)reader.ReadInt();
			m_BleedingWound = reader.ReadItem();
			m_PlaguePack = reader.ReadItem();

			if ( m_BleedingWound == null || m_PlaguePack == null )
				Delete();
		}
	}
}
