## Summary
Adds authentic **T2A-era (pre-UO:Third-Dawn) packet-based crafting menus**, enabled via the **`t2aCraftMenus` server setting** (read once at startup; default **`!Core.UOTD`**, so a pre-UO:TD shard gets them automatically). When enabled, double-clicking a crafting tool opens the classic `0x7C`/`0x7D` item-list menu — skill- and material-filtered — instead of the modern gump, covering all 8 tool/skill crafts (blacksmithy, tailoring, tinkering, carpentry, alchemy, bowcraft/fletching, inscription, cartography). It is **not** a runtime/admin-flippable feature flag.
This is the **definitive, reconciled** branch and **supersedes**:
- **#2181** (Delphi — `T2A_CraftingMenus`): the original effort.
- **#2381** (Jack/UOLL — `t2a_crafting_menus`): the research-grounded superset (Delphi's base + 12 corrections), rebased onto current `main`.
Original authorship is preserved across the cherry-picked history: foundation commit **@Delphi79**, mechanic fixes **@jackuoll (Jack Ward)**, reconciliation/fixes/docs mine.
## How it was built
1. Cherry-picked Jack's 13 commits onto current `main` (superset of Delphi's; only 2 trivial FeatureFlags conflicts).
2. Applied targeted fixes (below) with tests.
3. Full convention audit, build, and test pass.
Grounded in independent historical research plus Jack's deep dive. Maintainer reference: `dev-docs/t2a-crafting.md`.
## Mechanics (highlights)
- Double-click tool → target resource → skill/material-filtered menu → craft. Resource pre-selection per skill; make-last by targeting the tool.
- **Stacked-gem jewelry:** target a gem stack → the **full stack** is consumed and the piece is named by count ("a 1000 diamond ring"); count persists (`BaseJewel` serialization **v4 → v5**, new `_gemCount`).
- **Tool-less inscription & cartography** (skill-list invoked; no pen/sextant); inscription consumes reagents+scroll on success and failure, mana only on success.
- **Tailoring matching-hue consumption:** targeting hued cloth/leather consumes only that hue. Crafted items take color from their **`CraftResource`** (not the dyed hue), so dyed leather/cloth don't tint the product; in T2A only colored ingots/ore color items (metal armor/shields).
- **Half-resources on failed non-scroll crafts** (pre-UO:TD).
- **Maker's mark** always prompted for exceptional items, via the shared `QueryMakersMarkGump`.
- Server-side menu infra changes are additive (`ItemListEntry.CraftIndex`, `Entries` setter, `HasSent`).
## Notable changes on top of the cherry-pick
- **Toggle is a startup server setting, not a feature flag.** Removed `ContentFeatureFlags.T2ACraftMenus` (and its admin-flippable plumbing); the value is read once via `ServerConfiguration.GetSetting("t2aCraftMenus", !Core.UOTD)` into `T2ACraftSystem.Enabled`. Since the default tracks the era and it can't be flipped at runtime, there's no incoherent "menus-on / UO:TD-era" state.
- **Stacked-gem consumption (B3a/B3):** consume the full `PendingGemCount` (was deliberately consuming 1 while naming by the stack), null-safe gem type, plain-piece fallback + message. New `T2AJewelGemCraftTests`.
- **Convention audit:** `new List<Item>()` → `PooledRefList<Item>` on the hue-aware consume path; removed dead code.
## Decisions & deviations
- `make-last` kept as **QoL** (post-T2A gump-era feature).
- `half-on-failure` (non-scroll) kept as a **reconstruction** (not OSI-confirmed).
- **Stacked-gem** behavior set per shard authority (overrides the "single gem" reconstruction).
- **Cooking** out of scope (no T2A crafting menu existed for it).
- **No colored items from dyed materials:** crafted color comes from the `CraftResource` type. Pre-AOS leather has no colored variant, so leather is always uncolored; weapons retain resource color only in AOS+ (unchanged, intended).
## Test plan
- Automated: `dotnet build ModernUO.slnx -c Debug` clean; `dotnet test Projects/UOContent.Tests` → **421 passed** (incl. 3 new jewelry tests).
- Manual (needs a running T2A shard + client):
- [ ] Each of the 8 skills opens the correct menu; empty-menu guard fires.
- [ ] Make-last repeats the last craft (jewelry re-prompts gem).
- [ ] Jewelry consumes the full targeted gem stack and names by count.
- [ ] Cartography consumes blank maps only with T2A enabled / maps+scrolls when disabled.
- [ ] Tailoring consumes only the targeted-hue material; crafted items are not tinted by dyed cloth/leather.
- [ ] Maker's-mark prompt on exceptional.
- [ ] Failed non-scroll craft consumes half resources.
- [ ] Inscription: reagents+scroll on success/failure, mana only on success.
- [ ] T2A disabled: gump crafting unchanged.
## Credits
Co-authored-by: @Delphi79
Co-authored-by: @jackuoll
426 lines
13 KiB
C#
426 lines
13 KiB
C#
using System;
|
|
using Server.Items;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Engines.Craft
|
|
{
|
|
public enum EnhanceResult
|
|
{
|
|
None,
|
|
NotInBackpack,
|
|
BadItem,
|
|
BadResource,
|
|
AlreadyEnhanced,
|
|
Success,
|
|
Failure,
|
|
Broken,
|
|
NoResources,
|
|
NoSkill
|
|
}
|
|
|
|
public static class Enhance
|
|
{
|
|
public static EnhanceResult Invoke(
|
|
Mobile from, CraftSystem craftSystem, BaseTool tool, Item item,
|
|
CraftResource resource, Type resType, ref TextDefinition resMessage
|
|
)
|
|
{
|
|
if (item == null)
|
|
{
|
|
return EnhanceResult.BadItem;
|
|
}
|
|
|
|
if (!item.IsChildOf(from.Backpack))
|
|
{
|
|
return EnhanceResult.NotInBackpack;
|
|
}
|
|
|
|
if (item is not BaseArmor && item is not BaseWeapon)
|
|
{
|
|
return EnhanceResult.BadItem;
|
|
}
|
|
|
|
if (item is IArcaneEquip eq && eq.IsArcane)
|
|
{
|
|
return EnhanceResult.BadItem;
|
|
}
|
|
|
|
if (CraftResources.IsStandard(resource))
|
|
{
|
|
return EnhanceResult.BadResource;
|
|
}
|
|
|
|
var num = craftSystem.CanCraft(from, tool, item.GetType());
|
|
|
|
if (num > 0)
|
|
{
|
|
resMessage = num;
|
|
return EnhanceResult.None;
|
|
}
|
|
|
|
var craftItem = craftSystem.CraftItems.SearchFor(item.GetType());
|
|
|
|
if (craftItem == null || craftItem.Resources.Count == 0)
|
|
{
|
|
return EnhanceResult.BadItem;
|
|
}
|
|
|
|
if (craftItem.GetSuccessChance(from, resType, craftSystem, false, out _) <= 0.0)
|
|
{
|
|
return EnhanceResult.NoSkill;
|
|
}
|
|
|
|
var info = CraftResources.GetInfo(resource);
|
|
|
|
if (info == null || info.ResourceTypes.Length == 0)
|
|
{
|
|
return EnhanceResult.BadResource;
|
|
}
|
|
|
|
var attributes = info.AttributeInfo;
|
|
|
|
if (attributes == null)
|
|
{
|
|
return EnhanceResult.BadResource;
|
|
}
|
|
|
|
var resHue = 0;
|
|
var maxAmount = 0;
|
|
|
|
var consumeRes = craftItem.ConsumeRes(
|
|
from,
|
|
resType,
|
|
craftSystem,
|
|
ref resHue,
|
|
ref maxAmount,
|
|
ConsumeType.None,
|
|
ref resMessage
|
|
);
|
|
|
|
if (!consumeRes)
|
|
{
|
|
return EnhanceResult.NoResources;
|
|
}
|
|
|
|
if (craftSystem is DefBlacksmithy)
|
|
{
|
|
var hammer = from.FindItemOnLayer<AncientSmithyHammer>(Layer.OneHanded);
|
|
if (hammer != null && --hammer.UsesRemaining < 1)
|
|
{
|
|
hammer.Delete();
|
|
}
|
|
}
|
|
|
|
int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
|
|
int dura, luck, lreq, dinc = 0;
|
|
int baseChance;
|
|
|
|
var physBonus = false;
|
|
bool fireBonus;
|
|
bool coldBonus;
|
|
bool nrgyBonus;
|
|
bool poisBonus;
|
|
bool duraBonus;
|
|
bool luckBonus;
|
|
bool lreqBonus;
|
|
bool dincBonus;
|
|
|
|
if (item is BaseWeapon weapon)
|
|
{
|
|
if (!CraftResources.IsStandard(weapon.Resource))
|
|
{
|
|
return EnhanceResult.AlreadyEnhanced;
|
|
}
|
|
|
|
baseChance = 20;
|
|
|
|
dura = weapon.MaxHitPoints;
|
|
luck = weapon.Attributes.Luck;
|
|
lreq = weapon.WeaponAttributes.LowerStatReq;
|
|
dinc = weapon.Attributes.WeaponDamage;
|
|
|
|
fireBonus = attributes.WeaponFireDamage > 0;
|
|
coldBonus = attributes.WeaponColdDamage > 0;
|
|
nrgyBonus = attributes.WeaponEnergyDamage > 0;
|
|
poisBonus = attributes.WeaponPoisonDamage > 0;
|
|
|
|
duraBonus = attributes.WeaponDurability > 0;
|
|
luckBonus = attributes.WeaponLuck > 0;
|
|
lreqBonus = attributes.WeaponLowerRequirements > 0;
|
|
dincBonus = dinc > 0;
|
|
}
|
|
else
|
|
{
|
|
var armor = (BaseArmor)item;
|
|
|
|
if (!CraftResources.IsStandard(armor.Resource))
|
|
{
|
|
return EnhanceResult.AlreadyEnhanced;
|
|
}
|
|
|
|
baseChance = 20;
|
|
|
|
phys = armor.PhysicalResistance;
|
|
fire = armor.FireResistance;
|
|
cold = armor.ColdResistance;
|
|
pois = armor.PoisonResistance;
|
|
nrgy = armor.EnergyResistance;
|
|
|
|
dura = armor.MaxHitPoints;
|
|
luck = armor.Attributes.Luck;
|
|
lreq = armor.ArmorAttributes.LowerStatReq;
|
|
|
|
physBonus = attributes.ArmorPhysicalResist > 0;
|
|
fireBonus = attributes.ArmorFireResist > 0;
|
|
coldBonus = attributes.ArmorColdResist > 0;
|
|
nrgyBonus = attributes.ArmorEnergyResist > 0;
|
|
poisBonus = attributes.ArmorPoisonResist > 0;
|
|
|
|
duraBonus = attributes.ArmorDurability > 0;
|
|
luckBonus = attributes.ArmorLuck > 0;
|
|
lreqBonus = attributes.ArmorLowerRequirements > 0;
|
|
dincBonus = false;
|
|
}
|
|
|
|
var skill = (int)from.Skills[craftSystem.MainSkill].Value;
|
|
|
|
if (skill >= 100)
|
|
{
|
|
baseChance -= (skill - 90) / 10;
|
|
}
|
|
|
|
var res = EnhanceResult.Success;
|
|
|
|
if (physBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + phys);
|
|
}
|
|
|
|
if (fireBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + fire);
|
|
}
|
|
|
|
if (coldBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + cold);
|
|
}
|
|
|
|
if (nrgyBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + nrgy);
|
|
}
|
|
|
|
if (poisBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + pois);
|
|
}
|
|
|
|
if (duraBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + dura / 40);
|
|
}
|
|
|
|
if (luckBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + 10 + luck / 2);
|
|
}
|
|
|
|
if (lreqBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + lreq / 4);
|
|
}
|
|
|
|
if (dincBonus)
|
|
{
|
|
CheckResult(ref res, baseChance + dinc / 4);
|
|
}
|
|
|
|
switch (res)
|
|
{
|
|
case EnhanceResult.Broken:
|
|
{
|
|
if (!craftItem.ConsumeRes(
|
|
from,
|
|
resType,
|
|
craftSystem,
|
|
ref resHue,
|
|
ref maxAmount,
|
|
ConsumeType.Half,
|
|
ref resMessage
|
|
))
|
|
{
|
|
return EnhanceResult.NoResources;
|
|
}
|
|
|
|
item.Delete();
|
|
break;
|
|
}
|
|
case EnhanceResult.Success:
|
|
{
|
|
if (!craftItem.ConsumeRes(
|
|
from,
|
|
resType,
|
|
craftSystem,
|
|
ref resHue,
|
|
ref maxAmount,
|
|
ConsumeType.All,
|
|
ref resMessage
|
|
))
|
|
{
|
|
return EnhanceResult.NoResources;
|
|
}
|
|
|
|
if (item is BaseWeapon w)
|
|
{
|
|
w.Resource = resource;
|
|
|
|
var hue = w.GetElementalDamageHue();
|
|
if (hue > 0)
|
|
{
|
|
w.Hue = hue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
((BaseArmor)item).Resource = resource;
|
|
}
|
|
|
|
break;
|
|
}
|
|
case EnhanceResult.Failure:
|
|
{
|
|
if (!craftItem.ConsumeRes(
|
|
from,
|
|
resType,
|
|
craftSystem,
|
|
ref resHue,
|
|
ref maxAmount,
|
|
ConsumeType.Half,
|
|
ref resMessage
|
|
))
|
|
{
|
|
return EnhanceResult.NoResources;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
public static void CheckResult(ref EnhanceResult res, int chance)
|
|
{
|
|
if (res != EnhanceResult.Success)
|
|
{
|
|
return; // we've already failed..
|
|
}
|
|
|
|
var random = Utility.Random(100);
|
|
|
|
if (random < 10)
|
|
{
|
|
res = EnhanceResult.Failure;
|
|
}
|
|
else if (chance > random)
|
|
{
|
|
res = EnhanceResult.Broken;
|
|
}
|
|
}
|
|
|
|
public static void BeginTarget(Mobile from, CraftSystem craftSystem, BaseTool tool)
|
|
{
|
|
var context = craftSystem.GetContext(from);
|
|
|
|
if (context == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var lastRes = context.LastResourceIndex;
|
|
var subRes = craftSystem.CraftSubRes;
|
|
|
|
if (lastRes >= 0 && lastRes < subRes.Count)
|
|
{
|
|
var res = subRes.GetAt(lastRes);
|
|
|
|
if (from.Skills[craftSystem.MainSkill].Value < res.RequiredSkill)
|
|
{
|
|
CraftItem.ShowCraftMenu(from, craftSystem, tool, res.Message);
|
|
}
|
|
else
|
|
{
|
|
var resource = CraftResources.GetFromType(res.ItemType);
|
|
|
|
if (resource != CraftResource.None)
|
|
{
|
|
from.Target = new InternalTarget(craftSystem, tool, res.ItemType, resource);
|
|
// Target an item to enhance with the properties of your selected material.
|
|
from.SendLocalizedMessage(1061004);
|
|
}
|
|
else
|
|
{
|
|
CraftItem.ShowCraftMenu(from, craftSystem, tool, 1061010);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CraftItem.ShowCraftMenu(from, craftSystem, tool, 1061010);
|
|
}
|
|
}
|
|
|
|
private class InternalTarget : Target
|
|
{
|
|
private readonly CraftSystem m_CraftSystem;
|
|
private readonly CraftResource m_Resource;
|
|
private readonly Type m_ResourceType;
|
|
private readonly BaseTool m_Tool;
|
|
|
|
public InternalTarget(CraftSystem craftSystem, BaseTool tool, Type resourceType, CraftResource resource) : base(
|
|
2,
|
|
false,
|
|
TargetFlags.None
|
|
)
|
|
{
|
|
m_CraftSystem = craftSystem;
|
|
m_Tool = tool;
|
|
m_ResourceType = resourceType;
|
|
m_Resource = resource;
|
|
}
|
|
|
|
protected override void OnTarget(Mobile from, object targeted)
|
|
{
|
|
if (targeted is Item item)
|
|
{
|
|
TextDefinition message = null;
|
|
var res = Enhance.Invoke(
|
|
from,
|
|
m_CraftSystem,
|
|
m_Tool,
|
|
item,
|
|
m_Resource,
|
|
m_ResourceType,
|
|
ref message
|
|
);
|
|
|
|
message = res switch
|
|
{
|
|
EnhanceResult.NotInBackpack => 1061005,
|
|
EnhanceResult.AlreadyEnhanced => 1061012,
|
|
EnhanceResult.BadItem => 1061011,
|
|
EnhanceResult.BadResource => 1061010,
|
|
EnhanceResult.Broken => 1061080,
|
|
EnhanceResult.Failure => 1061082,
|
|
EnhanceResult.Success => 1061008,
|
|
EnhanceResult.NoSkill => 1044153,
|
|
_ => message
|
|
};
|
|
|
|
CraftItem.ShowCraftMenu(from, m_CraftSystem, m_Tool, message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|