using System;
using Server;
using Server.Mobiles;
using Server.Targeting;
using Server.Items;
using Server.Network;
namespace Server.SkillHandlers
{
public class Stealing
{
public static void Initialize()
{
SkillInfo.Table[33].Callback = new SkillUseCallback( OnUse );
}
public static readonly bool ClassicMode = false;
public static readonly bool SuspendOnMurder = false;
public static bool IsInGuild( Mobile m )
{
return ( m is PlayerMobile && ((PlayerMobile)m).NpcGuild == NpcGuild.ThievesGuild );
}
public static bool IsInnocentTo( Mobile from, Mobile to )
{
return ( Notoriety.Compute( from, (Mobile)to ) == Notoriety.Innocent );
}
private class StealingTarget : Target
{
private Mobile m_Thief;
public StealingTarget( Mobile thief ) : base ( 1, false, TargetFlags.None )
{
m_Thief = thief;
AllowNonlocal = true;
}
private Item TryStealItem( Item toSteal, ref bool caught )
{
Item stolen = null;
object root = toSteal.RootParent;
if ( !IsEmptyHanded( m_Thief ) )
{
m_Thief.SendLocalizedMessage( 1005584 ); // Both hands must be free to steal.
}
else if ( root is Mobile && ((Mobile)root).Player && IsInnocentTo( m_Thief, (Mobile)root ) && !IsInGuild( m_Thief ) )
{
m_Thief.SendLocalizedMessage( 1005596 ); // You must be in the thieves guild to steal from other players.
}
else if ( SuspendOnMurder && root is Mobile && ((Mobile)root).Player && IsInGuild( m_Thief ) && m_Thief.Kills > 0 )
{
m_Thief.SendLocalizedMessage( 502706 ); // You are currently suspended from the thieves guild.
}
else if ( root is BaseVendor && ((BaseVendor)root).IsInvulnerable )
{
m_Thief.SendLocalizedMessage( 1005598 ); // You can't steal from shopkeepers.
}
else if ( root is PlayerVendor )
{
m_Thief.SendLocalizedMessage( 502709 ); // You can't steal from vendors.
}
else if ( !m_Thief.CanSee( toSteal ) )
{
m_Thief.SendLocalizedMessage( 500237 ); // Target can not be seen.
}
else if ( toSteal.Parent == null || !toSteal.Movable || toSteal.LootType == LootType.Newbied || toSteal.CheckBlessed( root ) )
{
m_Thief.SendLocalizedMessage( 502710 ); // You can't steal that!
}
else if ( !m_Thief.InRange( toSteal.GetWorldLocation(), 1 ) )
{
m_Thief.SendLocalizedMessage( 502703 ); // You must be standing next to an item to steal it.
}
else if ( toSteal.Parent is Mobile )
{
m_Thief.SendLocalizedMessage( 1005585 ); // You cannot steal items which are equiped.
}
else if ( root == m_Thief )
{
m_Thief.SendLocalizedMessage( 502704 ); // You catch yourself red-handed.
}
else if ( root is Mobile && ((Mobile)root).AccessLevel > AccessLevel.Player )
{
m_Thief.SendLocalizedMessage( 502710 ); // You can't steal that!
}
else if ( root is Mobile && !m_Thief.CanBeHarmful( (Mobile)root ) )
{
}
else
{
double w = toSteal.Weight + toSteal.TotalWeight;
if ( w > 10 )
{
m_Thief.SendMessage( "That is too heavy to steal." );
}
else
{
if ( toSteal.Stackable && toSteal.Amount > 1 )
{
int maxAmount = (int)((m_Thief.Skills[SkillName.Stealing].Value / 10.0) / toSteal.Weight);
if ( maxAmount < 1 )
maxAmount = 1;
else if ( maxAmount > toSteal.Amount )
maxAmount = toSteal.Amount;
int amount = Utility.RandomMinMax( 1, maxAmount );
if ( amount >= toSteal.Amount )
{
int pileWeight = (int)Math.Ceiling( toSteal.Weight * toSteal.Amount );
pileWeight *= 10;
if ( m_Thief.CheckTargetSkill( SkillName.Stealing, toSteal, pileWeight - 22.5, pileWeight + 27.5 ) )
stolen = toSteal;
}
else
{
int pileWeight = (int)Math.Ceiling( toSteal.Weight * amount );
pileWeight *= 10;
if ( m_Thief.CheckTargetSkill( SkillName.Stealing, toSteal, pileWeight - 22.5, pileWeight + 27.5 ) )
{
stolen = toSteal.Dupe( amount );
toSteal.Amount -= amount;
}
}
}
else
{
int iw = (int)Math.Ceiling( w );
iw *= 10;
if ( m_Thief.CheckTargetSkill( SkillName.Stealing, toSteal, iw - 22.5, iw + 27.5 ) )
stolen = toSteal;
}
if ( stolen != null )
m_Thief.SendLocalizedMessage( 502724 ); // You succesfully steal the item.
else
m_Thief.SendLocalizedMessage( 502723 ); // You fail to steal the item.
caught = ( m_Thief.Skills[SkillName.Stealing].Value < Utility.Random( 150 ) );
}
}
return stolen;
}
protected override void OnTarget( Mobile from, object target )
{
from.RevealingAction();
Item stolen = null;
object root = null;
bool caught = false;
if ( target is Item )
{
root = ((Item)target).RootParent;
stolen = TryStealItem( (Item)target, ref caught );
}
else if ( target is Mobile )
{
PlayerMobile theif = from as PlayerMobile;
if( theif.SolenFriendship == SolenFriend.Red )
{
if( target is RedSolenQueen || target is RedSolenWarrior || target is RedSolenWorker || target is RedSolenInfiltratorQueen || target is RedSolenInfiltratorWarrior )
theif.SolenFriendship = SolenFriend.None;
}
if( theif.SolenFriendship == SolenFriend.Black )
{
if( target is BlackSolenQueen || target is BlackSolenWarrior || target is BlackSolenWorker || target is BlackSolenInfiltratorQueen || target is BlackSolenInfiltratorWarrior )
theif.SolenFriendship = SolenFriend.None;
}
Container pack = ((Mobile)target).Backpack;
if ( pack != null && pack.Items.Count > 0 )
{
int randomIndex = Utility.Random( pack.Items.Count );
root = target;
stolen = TryStealItem( (Item) pack.Items[randomIndex], ref caught );
}
}
else
{
m_Thief.SendLocalizedMessage( 502710 ); // You can't steal that!
}
if ( stolen != null )
from.AddToBackpack( stolen );
if ( caught )
{
if ( root == null )
{
m_Thief.CriminalAction( false );
}
else if ( root is Corpse && ((Corpse)root).IsCriminalAction( m_Thief ) )
{
m_Thief.CriminalAction( false );
}
else if ( root is Mobile )
{
Mobile mobRoot = (Mobile)root;
if ( !IsInGuild( mobRoot ) && IsInnocentTo( m_Thief, mobRoot ) )
m_Thief.CriminalAction( false );
string message = String.Format( "You notice {0} trying to steal from {1}.", m_Thief.Name, mobRoot.Name );
foreach ( NetState ns in m_Thief.GetClientsInRange( 8 ) )
{
if ( ns != m_Thief.NetState )
ns.Mobile.SendMessage( message );
}
}
}
else if ( root is Corpse && ((Corpse)root).IsCriminalAction( m_Thief ) )
{
m_Thief.CriminalAction( false );
}
if ( root is Mobile && ((Mobile)root).Player && m_Thief is PlayerMobile && IsInnocentTo( m_Thief, (Mobile)root ) && !IsInGuild( (Mobile)root ) )
{
PlayerMobile pm = (PlayerMobile)m_Thief;
pm.PermaFlags.Add( (Mobile)root );
pm.Delta( MobileDelta.Noto );
}
}
}
public static bool IsEmptyHanded( Mobile from )
{
if ( from.FindItemOnLayer( Layer.OneHanded ) != null )
return false;
if ( from.FindItemOnLayer( Layer.TwoHanded ) != null )
return false;
return true;
}
public static TimeSpan OnUse( Mobile m )
{
if ( !IsEmptyHanded( m ) )
{
m.SendLocalizedMessage( 1005584 ); // Both hands must be free to steal.
}
else
{
m.Target = new Stealing.StealingTarget( m );
m.RevealingAction();
m.SendLocalizedMessage( 502698 ); // Which item do you want to steal?
}
return TimeSpan.FromSeconds( 10.0 );
}
}
}