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.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.");
}
}
}
}
}