ModernUO/Projects/UOContent
Kamron Batman f4a87a8629
fix: Fixes adding items with ambiguous type lookup (#2307)
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) |
2026-01-06 21:21:29 -08:00
..
Accounting chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Assistants chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Commands fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Compression chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Configuration chore: Updates copyright (#1448) 2023-08-09 09:09:26 -07:00
Console feat: Adds console commands (#1714) 2024-03-30 09:40:43 -07:00
Context Menus fix: Moves ContextMenu out of core, streamlines code, fixes bugs (#1873) 2024-07-20 21:33:23 -07:00
Engines fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Gumps feat: Adds grid support for the DynamicGump system (#2306) 2026-01-03 10:12:22 -08:00
Holiday Stuff chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Items feat: Fixes spawner bugs with position finding, Adds [ShowSpawnerBorders (#2297) 2025-12-28 18:26:03 -08:00
Migrations feat: Fixes spawner bugs with position finding, Adds [ShowSpawnerBorders (#2297) 2025-12-28 18:26:03 -08:00
Misc chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Mobiles fix: Fixes BaseVendor IsInvuln configuration (#2309) 2026-01-05 09:19:48 -08:00
Multis feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00
Network feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00
Regions feat: New Jail System (#2215) 2025-07-16 20:41:21 -07:00
Skills chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Special Systems fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Spells feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00
Systems/JailSystem feat: Adds size/style support to gump builders, optimizes EscapeHtml (#2257) 2025-11-23 11:35:31 -08:00
Targets chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Text feat: Adds size/style support to gump builders, optimizes EscapeHtml (#2257) 2025-11-23 11:35:31 -08:00
Utilities chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
World Saves fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Module.cs fix: Fixes sending packets and sidesteps a major issue with stackalloc and PGO in .NET 8 (#1607) 2023-11-21 12:18:20 -08:00
UOContent.csproj feat: Bumps Serialization Generator for better support (#2292) 2025-12-26 14:27:24 -08:00