fix: T2A menus only offer what the chosen resource can make (#2695)

## Summary
The T2A crafting menus offered items the chosen resource couldn't make:

- **Tailoring honours the targeted cloth hue.** The menu was built from all cloth in the pack, but the craft consumes only the targeted hue, so it offered items that then failed on resources. `CanCraftItem` / `FilterEntries` / `AnyCraftableInCategory` now take the hue and count with the same helper the craft uses.
- **Uncut cloth counts in the hued path.** The hue-aware count and consume matched only `Cloth`, so targeting uncut cloth gave an empty menu. The hued path now uses `CraftItem`'s equivalence table like the unhued path. `T2ACraftSystem` reuses that table instead of a narrower copy, which also covers the coloured woods and leathers on later-era shards.
- **T2A tinkering only uses iron ingots.** Coloured ingots are refused with a re-prompt. The menu filter now uses the selected ingot, and Make Last for tinkering always resolves to iron, so a coloured choice left over from the gump flow can't be used.

## Testing
- `dotnet build`: 0 warnings, 0 errors
- New `T2AHuedFilterTests`: only cloth of the targeted hue counts, and uncut cloth of the same hue counts toward the recipe
- No test for the tinkering target and message flow; not yet exercised in game
This commit is contained in:
Kamron Batman 2026-10-20 23:12:10 -07:00 • committed by GitHub
parent 54c0040ac8
commit ef8057d38e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 206 additions and 56 deletions

View file

@ -190,9 +190,11 @@ public static class T2ACraftSystem
/// Checks if a player can craft a specific item, accounting for sub-resource types.
/// When <paramref name="selectedResourceType"/> is non-null, checks against that specific sub-resource.
/// When null, checks against ANY available sub-resource the player has sufficient skill and materials for.
/// A non-negative <paramref name="hue"/> counts only same-hue stock for the primary resource, exactly as
/// the hue-aware craft path consumes it.
/// </summary>
public static bool CanCraftItem(
Mobile from, CraftItem itemDef, CraftSystem system, Type selectedResourceType = null
Mobile from, CraftItem itemDef, CraftSystem system, Type selectedResourceType = null, int hue = -1
)
{
var pack = from.Backpack;
@ -214,6 +216,27 @@ public static class T2ACraftSystem
var res = itemDef.Resources[i];
var resType = res.ItemType;
if (hue >= 0 && i == 0)
{
if (resCol.Init && resType == resCol.ResType && selectedResourceType != null)
{
var subRes = resCol.SearchFor(selectedResourceType);
if (subRes != null && from.Skills[system.MainSkill].Value < subRes.RequiredSkill)
{
return false;
}
resType = selectedResourceType;
}
if (CraftItem.GetHuedAmount(pack, resType, hue) < res.Amount)
{
return false;
}
continue;
}
// If this resource is the base sub-resource type (e.g. IronIngot for blacksmithing),
// handle sub-resource substitution
if (resCol.Init && resType == resCol.ResType)
@ -250,17 +273,20 @@ public static class T2ACraftSystem
/// <summary>
/// Convenience overload that resolves a Type to a CraftItem first.
/// </summary>
public static bool CanCraftItem(Mobile from, Type itemType, CraftSystem system, Type selectedResourceType = null)
public static bool CanCraftItem(
Mobile from, Type itemType, CraftSystem system, Type selectedResourceType = null, int hue = -1
)
{
var itemDef = system.CraftItems.SearchFor(itemType);
return itemDef != null && CanCraftItem(from, itemDef, system, selectedResourceType);
return itemDef != null && CanCraftItem(from, itemDef, system, selectedResourceType, hue);
}
/// <summary>
/// Filters static template entries to only those the player can craft.
/// </summary>
public static ItemListEntry[] FilterEntries(
Mobile from, ItemListEntry[] staticEntries, Type[] types, CraftSystem system, Type selectedResourceType = null
Mobile from, ItemListEntry[] staticEntries, Type[] types, CraftSystem system,
Type selectedResourceType = null, int hue = -1
)
{
var filtered = new ItemListEntry[staticEntries.Length];
@ -271,7 +297,7 @@ public static class T2ACraftSystem
var entry = staticEntries[i];
var typeIndex = entry.CraftIndex;
if (typeIndex >= 0 && typeIndex < types.Length &&
CanCraftItem(from, types[typeIndex], system, selectedResourceType))
CanCraftItem(from, types[typeIndex], system, selectedResourceType, hue))
{
filtered[count++] = entry;
}
@ -294,12 +320,12 @@ public static class T2ACraftSystem
/// Returns true if at least one item in the type array is craftable.
/// </summary>
public static bool AnyCraftableInCategory(
Mobile from, Type[] types, CraftSystem system, Type selectedResourceType = null
Mobile from, Type[] types, CraftSystem system, Type selectedResourceType = null, int hue = -1
)
{
for (var i = 0; i < types.Length; i++)
{
if (CanCraftItem(from, types[i], system, selectedResourceType))
if (CanCraftItem(from, types[i], system, selectedResourceType, hue))
{
return true;
}
@ -308,28 +334,11 @@ public static class T2ACraftSystem
return false;
}
/// <summary>
/// Equivalent type pairs mirroring CraftItem.m_TypesTable — used so that menu filtering
/// counts boards when checking for logs, hides when checking for leather, etc.
/// </summary>
private static readonly Type[][] _equivalentTypes =
[
[typeof(Log), typeof(Board)],
[typeof(Cloth), typeof(UncutCloth)],
[typeof(Items.Leather), typeof(Hides)]
];
// Shares CraftItem's equivalence table so the menu counts exactly what the craft will consume
private static int GetResourceAmount(Container pack, Type type)
{
for (var i = 0; i < _equivalentTypes.Length; i++)
{
if (_equivalentTypes[i][0] == type)
{
return pack.GetAmount(_equivalentTypes[i]);
}
}
return pack.GetAmount(type);
var equivalents = CraftItem.GetEquivalentTypes(type);
return equivalents != null ? pack.GetAmount(equivalents) : pack.GetAmount(type);
}
private static bool HasAnySufficientSubResource(