/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\uoparrot\PetParrot.cs
Lines of code: 196
***********************************************************/


using System;
using System.Collections;
using System.Collections.Generic;
using Server.Items;
using Server.Targeting;
using Server.ContextMenus;
using Server.Network;
using Server.Mobiles;

namespace Server.Mobiles
{
	public class PetParrot : BaseCreature
	{
		public override bool DeleteCorpseOnDeath{ get{ return true; } }
		private Item m_parrotperch;	
		
		public string[] ParrotTalk = new string [10]{ "Squawk", "Squawk", "Squawk", "Squawk", "Squawk", "Squawk", "Squawk", "Squawk", "Squawk", "Squawk" };  //**Sure there's likely a way to set all of them to squawk by default but it escapes me**
		
		private bool m_DontLearn;
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public Item ParrotPerch
		{
			get { return m_parrotperch; }
			set { m_parrotperch = value;Modify(); }
		}	
		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase1
		{
			get { return ParrotTalk[0]; }
			set { ParrotTalk[0] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase2
		{
			get { return ParrotTalk[1]; }
			set { ParrotTalk[1] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase3
		{
			get { return ParrotTalk[2]; }
			set { ParrotTalk[2] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase4
		{
			get { return ParrotTalk[3]; }
			set { ParrotTalk[3] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase5
		{
			get { return ParrotTalk[4]; }
			set { ParrotTalk[4] = value; Modify();}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase6
		{
			get { return ParrotTalk[5]; }
			set { ParrotTalk[5] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase7
		{
			get { return ParrotTalk[6]; }
			set { ParrotTalk[6] = value; Modify();}
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase8
		{
			get { return ParrotTalk[7]; }
			set { ParrotTalk[7] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase9
		{
			get { return ParrotTalk[8]; }
			set { ParrotTalk[8] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public string Phrase10
		{
			get { return ParrotTalk[9]; }
			set { ParrotTalk[9] = value;Modify(); }
		}		
		
		[CommandProperty( AccessLevel.GameMaster )] 
		public bool DontLearn
		{
			get { return m_DontLearn; }
			set { m_DontLearn = value;Modify(); }
		}		
		
		
		public override bool Commandable{ get{ return false; } }     
	
		[Constructable]
		public PetParrot() : base( AIType.AI_Melee, FightMode.Aggressor, 10, 1, 0.4, 0.8 )
		{
			Name = "a parrot";
			Blessed = true;
			CantWalk = true;
			Body = 282;
		}

		public PetParrotStatue TurnToStatue()
		{
		//sanity
		if(m_parrotperch !=null && m_parrotperch is ParrotPerch) ((ParrotPerch)m_parrotperch).hasparrot=false;
		PetParrotStatue statue = new PetParrotStatue(this.Hue);
		statue.MoveToWorld(this.Location,this.Map);
		this.Delete();
		return statue;
		}
		
		
		public override void OnThink()
		{
			if(Loyalty<99)Loyalty=99;
			if(IsBonded)IsBonded=false;
			
			if (0.05 > Utility.RandomDouble() && 0.2 > Utility.RandomDouble()) 
				this.PlaySound( Utility.Random( 191, 5 ) );
				
			if(m_parrotperch==null || m_parrotperch.Deleted || m_parrotperch.Movable==true)
			{
			TurnToStatue();
			return;
			}
			
			if(m_parrotperch.X!=X)X=m_parrotperch.X;
			if(m_parrotperch.Y!=Y)Y=m_parrotperch.Y;
			if(m_parrotperch.Z+9!=Z)Z=m_parrotperch.Z+9;
			if(m_parrotperch.Map!=Map)Map=m_parrotperch.Map;			
			
			
			if (0.05 > Utility.RandomDouble()) 
			{
				string tmp = ParrotTalk[Utility.Random( ParrotTalk.Length )];
				if(tmp=="" || tmp==null)return;
				this.Say( true, tmp);		
			}
		}
		
		public override bool CanBeDamaged()
		{
			return false;
		}

		public override bool AlwaysAttackable{ get{ return false; } }
		public override bool BleedImmune{ get{ return true; } }
		public override Poison PoisonImmune{ get{ return Poison.Lethal; } }
		public override FoodType FavoriteFood{ get{ return FoodType.Wafers; } }
		
		public override bool HandlesOnSpeech( Mobile from )
		{
			if ( InRange( from, 10 ) && from==ControlMaster)
				return true;
				
			return false;
		}		
		
		public override void OnSpeech( SpeechEventArgs e )
		{
			if(DontLearn)return;		
			Mobile m = e.Mobile;

			//m.SendMessage("speech detected");//debug
			
			if(m_parrotperch==null)
			{
			TurnToStatue();
			return;
			}

			if ( !m.Player)
			{
				return;
			}
			else if((this.InRange(m,1) && ((m.Z-9)<=Z)) || Map.LineOfSight( new Point3D(m_parrotperch.X,m_parrotperch.Y,m_parrotperch.Z+14) , new Point3D(m.X,m.Y,m.Z+14) ))
			{
				ParrotTalk[Utility.Random(10)] = e.Speech; //Recorded in the array

				e.Handled = true;
				
				//m.SendMessage("recorded");//debug
			return;
			}
			else
			{
				//m.SendMessage("los check failed");//debug
			}
		}	
		
		public override bool OnDragDrop( Mobile from, Item dropped )
		{
			if ( CheckFeed( from, dropped ) )
			{
				PlaySound(1458);
				return true;
			}
			
		return false;
		}		

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 1 );
			writer.Write((Item)m_parrotperch);
			
			for(int i=0;i<10;i++)writer.Write((string)ParrotTalk[i]);			
			
			writer.Write(m_DontLearn);
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
			m_parrotperch = reader.ReadItem();
				
			if(m_parrotperch!=null && m_parrotperch is ParrotPerch)((ParrotPerch)m_parrotperch).hasparrot=true;
			
			for(int i=0;i<10;i++)ParrotTalk[i]=reader.ReadString();			
			
			if(version>=1)m_DontLearn=reader.ReadBool();
			
			if(Map==Map.Internal)OnThink();
		}
	}
}