ModernUO/Projects/UOContent/Engines
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
..
Advanced Search chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
BuffIcons feat: Standardizes South/East selection gumps (#1839) 2025-02-14 00:15:14 -08:00
Bulk Orders chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
CannedEvil chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Character Creation chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Chat fix: Fixes thread guard and cleans up incoming packet reader (#1641) 2023-12-19 17:04:09 -08:00
ConPVP fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Craft chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Doom chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Ethics fix: Fixes ethics causing crashes when not used (#1972) 2024-10-15 17:02:11 -07:00
Events fix: Streamlines event scheduler API. Adds months to weekly recurrence (#2178) 2025-05-07 22:42:44 -07:00
Factions chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Harvest chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Help feat: Adds size/style support to gump builders, optimizes EscapeHtml (#2257) 2025-11-23 11:35:31 -08:00
Khaldun fix: Adds missing string interpolation handler for SetStringSlot (#2123) 2025-02-13 19:30:47 -08:00
ML Quests fix: Fixes adding items with ambiguous type lookup (#2307) 2026-01-06 21:21:29 -08:00
Party chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Pathing feat: Refactors A* Movement to use PriorityQueue (#2244) 2025-07-26 15:53:06 -07:00
Plants feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00
Player Murder System chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Quests chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Spawners feat: Adds grid support for the DynamicGump system (#2306) 2026-01-03 10:12:22 -08:00
Stealables fix: Consolidates Color/Center html (#1762) 2024-05-07 23:56:32 -07:00
Treasures of Tokuno fix: Optimizes items to use default weights. (Part 1) (#2240) 2025-07-24 14:44:39 -07:00
UltimaStore fix: Fixes thread guard and cleans up incoming packet reader (#1641) 2023-12-19 17:04:09 -08:00
Veteran Rewards chore: Use var everywhere (#2294) 2025-12-27 16:47:28 -08:00
Virtues feat: Add spawn position caching and spiral scan optimization (#2295) 2025-12-28 02:40:21 -08:00