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


//Brunus Arkkaza -AOV- www.uovalor.com, this script was based on Greywolf's system

using System;
using Server.Network;
using Server;
using Server.Targeting; 
using Server.Items;
using Server.Mobiles;
using Server.Targets;

namespace Server.Items
{
	[FlipableAttribute( 0x13F6, 0x13F7 )]
	public class ForensicsRipper : BaseKnife, IUsesRemaining
	{
		public override WeaponAbility PrimaryAbility{ get{ return WeaponAbility.InfectiousStrike; } }
		public override WeaponAbility SecondaryAbility{ get{ return WeaponAbility.Disarm; } }

		public override int AosStrengthReq{ get{ return 5; } }
		public override int AosMinDamage{ get{ return 9; } }
		public override int AosMaxDamage{ get{ return 11; } }
		public override double SpeedSecs{ get{ return 2.25; } }

		public override int InitMinHits{ get{ return 31; } }
		public override int InitMaxHits{ get{ return 60; } }

		private int m_UsesRemaining;
		private bool m_ShowUsesRemaining;

		[CommandProperty( AccessLevel.GameMaster )]
		public int UsesRemaining
		{
			get { return m_UsesRemaining; }
			set { m_UsesRemaining = value; InvalidateProperties(); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool ShowUsesRemaining
		{
			get { return m_ShowUsesRemaining; }
			set { m_ShowUsesRemaining = value; InvalidateProperties(); }
		}

		[Constructable]
		public ForensicsRipper() : this( 50 )
		{
		}

		[Constructable]
		public ForensicsRipper( int uses ) : base( 0x13F6 )
		{
			Weight = 1.0;
			Hue = 2101;
			UsesRemaining = uses;
			ShowUsesRemaining = true;
			Name = "Forensics Ripper";
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( !IsChildOf( from.Backpack ) )
			{
				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
			}
			else if ( from.Skills[SkillName.Forensics].Base < 89.9 )
			{
				from.SendMessage( "You do not understand how to use this." );
			}
			else
			{
				from.Target = new ForensicsRipperTarget( this );
				from.SendMessage( "Which corpse you want to carve?" );
			}					
		}
		
		private class ForensicsRipperTarget : Target 
		{ 
			private ForensicsRipper m_Knife;

			public ForensicsRipperTarget( ForensicsRipper knife ) : base( 15, false, TargetFlags.None )
			{
				m_Knife = knife;
			}
			
			protected override void OnTarget( Mobile from, object target ) 
			{ 
				if ( target is Corpse ) 
				{	
					Corpse c = (Corpse)target; 
					if (c.Owner is BaseCreature)
					{
						BaseCreature cowner = c.Owner as BaseCreature;
						if (c.Carved == false)
						{
							Map map = from.Map;
							if ( map == null )
								return;
							int wool = (int)(((BaseCreature)c.Owner).Wool / 2);
							int feathers = (int)(((BaseCreature)c.Owner).Feathers / 2);
							int meat = (int)(((BaseCreature)c.Owner).Meat / 2);
							int hides = (int)(((BaseCreature)c.Owner).Hides / 2);
							int scales = (int)(((BaseCreature)c.Owner).Scales / 2);
							double skillper = (from.Skills.Forensics.Value / 2000);

							if (m_Knife != null )
							{
								if ( feathers != 0 )
								{
									c.DropItem( new Feather( feathers ) );
									from.SendMessage("You get more feathers from the corpse.");
								}

								if ( wool != 0 )
								{
									c.DropItem( new Wool( wool ) );
									from.SendMessage("You get more wool from the corpse.");
								}

								if ( meat >= 1)
								{
									if ( ((BaseCreature)c.Owner).MeatType == MeatType.Ribs )
										c.DropItem( new RawRibs( meat ) );
									else if ( ((BaseCreature)c.Owner).MeatType == MeatType.Bird )
										c.DropItem( new RawBird( meat ) );
									else if ( ((BaseCreature)c.Owner).MeatType == MeatType.LambLeg )
										c.DropItem( new RawLambLeg( meat ) );

									from.SendMessage("You get more meat from the corpse.");
								}

								if ( hides >= 1)
								{
									if (((BaseCreature)c.Owner).HideType == HideType.Regular )
										c.DropItem( new Hides( hides ) );
									else if (((BaseCreature)c.Owner).HideType == HideType.Spined )
										c.DropItem( new SpinedHides( hides ) );
									else if (((BaseCreature)c.Owner).HideType == HideType.Horned )
										c.DropItem( new HornedHides( hides ) );
									else if (((BaseCreature)c.Owner).HideType == HideType.Barbed )
										c.DropItem( new BarbedHides( hides ) );
									from.SendMessage("You get more hides from the corpse.");
								}

								if ( scales >= 1)
								{
									if (((BaseCreature)c.Owner).ScaleType == ScaleType.Red )
										c.DropItem( new RedScales( scales ) );
									else if (((BaseCreature)c.Owner).ScaleType == ScaleType.Yellow )
										c.DropItem( new YellowScales( scales ) );
									else if (((BaseCreature)c.Owner).ScaleType == ScaleType.Black )
										c.DropItem( new BlackScales( scales ) );
									else if (((BaseCreature)c.Owner).ScaleType == ScaleType.Green )
										c.DropItem( new GreenScales( scales ) );
									else if (((BaseCreature)c.Owner).ScaleType == ScaleType.White )
										c.DropItem( new WhiteScales( scales ) );
									else if (((BaseCreature)c.Owner).ScaleType == ScaleType.Blue )
										c.DropItem( new BlueScales( scales ) );

									from.SendMessage("You get more scales from the corpse.");
								}

								//Rares, can be used for demitel stuff or something
								if ( skillper >= Utility.RandomDouble() )
								{
									if (cowner is Dracolich ) 
									{
										c.DropItem( new DragonBone() );
										from.SendMessage("Your high knowledge on forensic evaluation allows you to remove the bone from the undead creature's body.");
									}

									if (cowner.BodyValue == 745 || cowner.BodyValue == 744 || cowner.BodyValue == 401 || cowner.BodyValue == 400 || cowner.BodyValue == 186 || 
										cowner.BodyValue == 185 || cowner.BodyValue == 184 || cowner.BodyValue == 183 || cowner.BodyValue == 751 || cowner.BodyValue == 750) 
									{
										c.DropItem( new SpineBones() );
										from.SendMessage("Your knoledge allowed you to get the spine of the creature.");
									}


								} // End of rares

								if (m_Knife.UsesRemaining > 1)
									m_Knife.UsesRemaining--; 
								else
								{
									m_Knife.Delete();
									from.SendMessage("You used up your forensic ripper.");
								}

								from.SendMessage("You carve the corpse.");

								if ( c is ICarvable )
								{
									((ICarvable)c).Carve( from, m_Knife );
								}
								else
								{
									c.Carved = true;
								}
							}
						}
						else
							from.SendMessage("You see nothing useful to carve from the corpse.");
					}
				}
			}
		}
		public ForensicsRipper( Serial serial ) : base( serial )
		{
		}

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

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

			writer.Write( (int) m_UsesRemaining );
		}

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

			int version = reader.ReadInt();

			m_ShowUsesRemaining = reader.ReadBool();
			m_UsesRemaining = reader.ReadInt();
			if ( m_UsesRemaining < 1 )
				m_UsesRemaining = 50;
		}
	}
}