Fixes [dupe for items with optional param constructors (#93)
This commit is contained in:
parent
11cac69eba
commit
005e97eb22
1 changed files with 11 additions and 10 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
using Server.Items;
|
using Server.Items;
|
||||||
using Server.Targeting;
|
using Server.Targeting;
|
||||||
|
using Server.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Server.Commands
|
namespace Server.Commands
|
||||||
{
|
{
|
||||||
|
|
@ -90,18 +91,17 @@ namespace Server.Commands
|
||||||
pack = from.Backpack;
|
pack = from.Backpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type t = copy.GetType();
|
ConstructorInfo c = ActivatorUtil.GetConstructor(copy.GetType());
|
||||||
|
|
||||||
//ConstructorInfo[] info = t.GetConstructors();
|
|
||||||
|
|
||||||
ConstructorInfo c = t.GetConstructor(Type.EmptyTypes);
|
|
||||||
|
|
||||||
if (c != null)
|
if (c != null)
|
||||||
|
{
|
||||||
|
var paramList = c.GetParameters();
|
||||||
|
object[] args = paramList.Length == 0 ? null : new object[paramList.Length];
|
||||||
|
Array.Fill(args, Type.Missing);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
from.SendMessage("Duping {0}...", m_Amount);
|
from.SendMessage("Duping {0}...", m_Amount);
|
||||||
for (int i = 0; i < m_Amount; i++)
|
for (int i = 0; i < m_Amount; i++)
|
||||||
if (c.Invoke(null) is Item newItem)
|
if (c.Invoke(args) is Item newItem)
|
||||||
{
|
{
|
||||||
CopyProperties(newItem, copy); //copy.Dupe( item, copy.Amount );
|
CopyProperties(newItem, copy); //copy.Dupe( item, copy.Amount );
|
||||||
copy.OnAfterDuped(newItem);
|
copy.OnAfterDuped(newItem);
|
||||||
|
|
@ -127,9 +127,10 @@ namespace Server.Commands
|
||||||
from.SendMessage("Error!");
|
from.SendMessage("Error!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!done) from.SendMessage("Unable to dupe. Item must have a 0 parameter constructor.");
|
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