Fixes [dupe for items with optional param constructors (#93)

This commit is contained in:
Andrew Fryer 2020-02-20 05:09:59 -05:00 • committed by GitHub
parent 11cac69eba
commit 005e97eb22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,6 +127,7 @@ 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.");
} }