From 005e97eb22afeba04d3a882038608b1440f2455e Mon Sep 17 00:00:00 2001 From: Andrew Fryer Date: Thu, 20 Feb 2020 05:09:59 -0500 Subject: [PATCH] Fixes [dupe for items with optional param constructors (#93) --- Projects/Scripts/Commands/Dupe.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Projects/Scripts/Commands/Dupe.cs b/Projects/Scripts/Commands/Dupe.cs index 7ed32436a..556dd8116 100644 --- a/Projects/Scripts/Commands/Dupe.cs +++ b/Projects/Scripts/Commands/Dupe.cs @@ -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."); } } } -} \ No newline at end of file +}