Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -5,138 +5,131 @@ using Server.Targeting;
|
|||
|
||||
namespace Server.Commands
|
||||
{
|
||||
public class Dupe
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register( "Dupe", AccessLevel.GameMaster, Dupe_OnCommand );
|
||||
CommandSystem.Register( "DupeInBag", AccessLevel.GameMaster, DupeInBag_OnCommand );
|
||||
}
|
||||
public class Dupe
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("Dupe", AccessLevel.GameMaster, Dupe_OnCommand);
|
||||
CommandSystem.Register("DupeInBag", AccessLevel.GameMaster, DupeInBag_OnCommand);
|
||||
}
|
||||
|
||||
[Usage( "Dupe [amount]" )]
|
||||
[Description( "Dupes a targeted item." )]
|
||||
private static void Dupe_OnCommand( CommandEventArgs e )
|
||||
{
|
||||
int amount = 1;
|
||||
if ( e.Length >= 1 )
|
||||
amount = e.GetInt32( 0 );
|
||||
e.Mobile.Target = new DupeTarget( false, amount > 0 ? amount : 1 );
|
||||
e.Mobile.SendMessage( "What do you wish to dupe?" );
|
||||
}
|
||||
[Usage("Dupe [amount]")]
|
||||
[Description("Dupes a targeted item.")]
|
||||
private static void Dupe_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
int amount = 1;
|
||||
if (e.Length >= 1)
|
||||
amount = e.GetInt32(0);
|
||||
e.Mobile.Target = new DupeTarget(false, amount > 0 ? amount : 1);
|
||||
e.Mobile.SendMessage("What do you wish to dupe?");
|
||||
}
|
||||
|
||||
[Usage( "DupeInBag <count>" )]
|
||||
[Description( "Dupes an item at it's current location (count) number of times." )]
|
||||
private static void DupeInBag_OnCommand( CommandEventArgs e )
|
||||
{
|
||||
int amount = 1;
|
||||
if ( e.Length >= 1 )
|
||||
amount = e.GetInt32( 0 );
|
||||
[Usage("DupeInBag <count>")]
|
||||
[Description("Dupes an item at it's current location (count) number of times.")]
|
||||
private static void DupeInBag_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
int amount = 1;
|
||||
if (e.Length >= 1)
|
||||
amount = e.GetInt32(0);
|
||||
|
||||
e.Mobile.Target = new DupeTarget( true, amount > 0 ? amount : 1 );
|
||||
e.Mobile.SendMessage( "What do you wish to dupe?" );
|
||||
}
|
||||
e.Mobile.Target = new DupeTarget(true, amount > 0 ? amount : 1);
|
||||
e.Mobile.SendMessage("What do you wish to dupe?");
|
||||
}
|
||||
|
||||
private class DupeTarget : Target
|
||||
{
|
||||
private bool m_InBag;
|
||||
private int m_Amount;
|
||||
public static void CopyProperties(Item dest, Item src)
|
||||
{
|
||||
PropertyInfo[] props = src.GetType().GetProperties();
|
||||
|
||||
public DupeTarget( bool inbag, int amount )
|
||||
: base( 15, false, TargetFlags.None )
|
||||
{
|
||||
m_InBag = inbag;
|
||||
m_Amount = amount;
|
||||
}
|
||||
for (int i = 0; i < props.Length; i++)
|
||||
try
|
||||
{
|
||||
if (props[i].CanRead && props[i].CanWrite) props[i].SetValue(dest, props[i].GetValue(src, null), null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Console.WriteLine( "Denied" );
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnTarget( Mobile from, object targ )
|
||||
{
|
||||
bool done = false;
|
||||
if ( !( targ is Item ) )
|
||||
{
|
||||
from.SendMessage( "You can only dupe items." );
|
||||
return;
|
||||
}
|
||||
private class DupeTarget : Target
|
||||
{
|
||||
private int m_Amount;
|
||||
private bool m_InBag;
|
||||
|
||||
CommandLogging.WriteLine( from, "{0} {1} duping {2} (inBag={3}; amount={4})", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ), m_InBag, m_Amount );
|
||||
public DupeTarget(bool inbag, int amount)
|
||||
: base(15, false, TargetFlags.None)
|
||||
{
|
||||
m_InBag = inbag;
|
||||
m_Amount = amount;
|
||||
}
|
||||
|
||||
Item copy = (Item)targ;
|
||||
Container pack = null;
|
||||
protected override void OnTarget(Mobile from, object targ)
|
||||
{
|
||||
bool done = false;
|
||||
if (!(targ is Item))
|
||||
{
|
||||
from.SendMessage("You can only dupe items.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_InBag )
|
||||
{
|
||||
if ( copy.Parent is Container cont )
|
||||
pack = cont;
|
||||
else if ( copy.Parent is Mobile m )
|
||||
pack = m.Backpack;
|
||||
}
|
||||
else
|
||||
pack = from.Backpack;
|
||||
CommandLogging.WriteLine(from, "{0} {1} duping {2} (inBag={3}; amount={4})", from.AccessLevel,
|
||||
CommandLogging.Format(from), CommandLogging.Format(targ), m_InBag, m_Amount);
|
||||
|
||||
Type t = copy.GetType();
|
||||
Item copy = (Item)targ;
|
||||
Container pack = null;
|
||||
|
||||
//ConstructorInfo[] info = t.GetConstructors();
|
||||
if (m_InBag)
|
||||
{
|
||||
if (copy.Parent is Container cont)
|
||||
pack = cont;
|
||||
else if (copy.Parent is Mobile m)
|
||||
pack = m.Backpack;
|
||||
}
|
||||
else
|
||||
{
|
||||
pack = from.Backpack;
|
||||
}
|
||||
|
||||
ConstructorInfo c = t.GetConstructor( Type.EmptyTypes );
|
||||
Type t = copy.GetType();
|
||||
|
||||
if ( c != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
from.SendMessage( "Duping {0}...", m_Amount );
|
||||
for ( int i = 0; i < m_Amount; i++ )
|
||||
{
|
||||
if ( c.Invoke( null ) is Item newItem )
|
||||
{
|
||||
CopyProperties( newItem, copy );//copy.Dupe( item, copy.Amount );
|
||||
copy.OnAfterDuped( newItem );
|
||||
newItem.Parent = null;
|
||||
//ConstructorInfo[] info = t.GetConstructors();
|
||||
|
||||
if ( pack != null )
|
||||
pack.DropItem( newItem );
|
||||
else
|
||||
newItem.MoveToWorld( from.Location, from.Map );
|
||||
ConstructorInfo c = t.GetConstructor(Type.EmptyTypes);
|
||||
|
||||
newItem.InvalidateProperties();
|
||||
if (c != null)
|
||||
try
|
||||
{
|
||||
from.SendMessage("Duping {0}...", m_Amount);
|
||||
for (int i = 0; i < m_Amount; i++)
|
||||
if (c.Invoke(null) is Item newItem)
|
||||
{
|
||||
CopyProperties(newItem, copy); //copy.Dupe( item, copy.Amount );
|
||||
copy.OnAfterDuped(newItem);
|
||||
newItem.Parent = null;
|
||||
|
||||
CommandLogging.WriteLine( from, "{0} {1} duped {2} creating {3}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ), CommandLogging.Format( newItem ) );
|
||||
}
|
||||
}
|
||||
from.SendMessage( "Done" );
|
||||
done = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
from.SendMessage( "Error!" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pack != null)
|
||||
pack.DropItem(newItem);
|
||||
else
|
||||
newItem.MoveToWorld(from.Location, from.Map);
|
||||
|
||||
if ( !done )
|
||||
{
|
||||
from.SendMessage( "Unable to dupe. Item must have a 0 parameter constructor." );
|
||||
}
|
||||
}
|
||||
}
|
||||
newItem.InvalidateProperties();
|
||||
|
||||
public static void CopyProperties( Item dest, Item src )
|
||||
{
|
||||
PropertyInfo[] props = src.GetType().GetProperties();
|
||||
CommandLogging.WriteLine(from, "{0} {1} duped {2} creating {3}", from.AccessLevel,
|
||||
CommandLogging.Format(from), CommandLogging.Format(targ),
|
||||
CommandLogging.Format(newItem));
|
||||
}
|
||||
|
||||
for ( int i = 0; i < props.Length; i++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( props[i].CanRead && props[i].CanWrite )
|
||||
{
|
||||
//Console.WriteLine( "Setting {0} = {1}", props[i].Name, props[i].GetValue( src, null ) );
|
||||
props[i].SetValue( dest, props[i].GetValue( src, null ), null );
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Console.WriteLine( "Denied" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
from.SendMessage("Done");
|
||||
done = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
from.SendMessage("Error!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!done) from.SendMessage("Unable to dupe. Item must have a 0 parameter constructor.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue