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.Targeting;
|
||||
using Server.Utilities;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Server.Commands
|
||||
{
|
||||
|
|
@ -90,18 +91,17 @@ namespace Server.Commands
|
|||
pack = from.Backpack;
|
||||
}
|
||||
|
||||
Type t = copy.GetType();
|
||||
|
||||
//ConstructorInfo[] info = t.GetConstructors();
|
||||
|
||||
ConstructorInfo c = t.GetConstructor(Type.EmptyTypes);
|
||||
|
||||
ConstructorInfo c = ActivatorUtil.GetConstructor(copy.GetType());
|
||||
if (c != null)
|
||||
{
|
||||
var paramList = c.GetParameters();
|
||||
object[] args = paramList.Length == 0 ? null : new object[paramList.Length];
|
||||
Array.Fill(args, Type.Missing);
|
||||
try
|
||||
{
|
||||
from.SendMessage("Duping {0}...", m_Amount);
|
||||
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 );
|
||||
copy.OnAfterDuped(newItem);
|
||||
|
|
@ -127,9 +127,10 @@ namespace Server.Commands
|
|||
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