Fix [add command failing with ambiguous type names + refactor for performance ### Problem [add blight would fail with "No type with that name was found" because multiple types contain "blight" (e.g., Server.Items.Blight, Server.Ethics.Evil.Blight, Server.Items.BlightGrippedLongbow, Server.Items.QuiverOfBlight). The old code only succeeded when exactly one type matched the search regardless of constructability and inheriting Mobi les/Items. ### Solution Exact match takes priority: If a type's name exactly equals the search string (case-insensitive), use it directly. Otherwise, show the AddGump with all partial matches. - [add blight → Creates Blight (exact name match) - [add bligh → Shows gump with Blight, BlightGrippedLongbow, etc. ### Refactoring - CommandEventArgs context: Added GetContext<T>/SetContext<T> to pass resolved type through the command chain without method signature changes - Removed TrySetupTarget duplication: Validation now happens only in ValidateArgs, eliminating redundant code paths - Split type matching: - ExactMatch(string) → Returns Type for exact name match (used by [add) - MatchEmptyCtor(string) → Returns ConstructorInfo[] for gump display (empty-callable constructors only) ### Memory & Performance Improvements | Optimization | Benefit | |-------------------------------|----------------------------------------------------------------------------------------------| | _mobileItemTypes cache | Filters Mobile/Item types once per assembly, reused on all subsequent searches | | ReadOnlySpan<string> for args | Avoids string[] heap allocations when slicing arguments | | ValueStringBuilder | Stack-allocated string building, avoids StringBuilder heap allocation | | Single type resolution | Type resolved once in ValidateArgs, passed via context to Execute (was resolved 2-3x before) |
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
namespace Server.Commands
|
|
{
|
|
public static class DragEffects
|
|
{
|
|
public static void Configure()
|
|
{
|
|
CommandSystem.Register("DragEffects", AccessLevel.Developer, DragEffects_OnCommand);
|
|
}
|
|
|
|
[Usage("DragEffects [enable=false]")]
|
|
[Description("Enables or disables the item drag and drop effects.")]
|
|
public static void DragEffects_OnCommand(CommandEventArgs e)
|
|
{
|
|
if (e.Length == 0)
|
|
{
|
|
if (Mobile.DragEffects)
|
|
{
|
|
e.Mobile.SendMessage("Drag effects are currently enabled.");
|
|
}
|
|
else
|
|
{
|
|
e.Mobile.SendMessage("Drag effects are currently disabled.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Mobile.DragEffects = e.GetBoolean(0);
|
|
|
|
if (Mobile.DragEffects)
|
|
{
|
|
e.Mobile.SendMessage("Drag effects have been enabled.");
|
|
}
|
|
else
|
|
{
|
|
e.Mobile.SendMessage("Drag effects have been disabled.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|