ModernUO/Projects/UOContent/Items/Skill Items/Tools/BaseTool.cs
Kamron Batman 88859ac69e
fix: T2A cooking works without a craft menu (#2693)
## Summary
With T2A packet crafting menus enabled (`t2aCraftMenus`, default for pre-UOTD eras), cooking did nothing. Double-clicking a Skillet set a target, and `T2ACraftSystem.ShowMenu` had no Cooking branch, so the target was accepted and silently dropped. Nothing else could cook either: the old RunUO "use food on a heat source" code was never hooked up and was removed in #1054.

T2A cooking never used a menu, so this restores the item-on-item / item-on-heat-source flow:

- **Per-item handling:** each ingredient (`CookableFood`, `Dough`, `SweetDough`, `SackFlour`, `BowlFlour`, `JarHoney`) implements `IT2ACombinable.TryCombine` and switches on the target. `T2ACooking` holds the shared target, water, combine and heat-timer helpers.
- **Heat source:** all `CookableFood` (raw meats, fish, eggs, unbaked pies/quiche/pizzas, cookie and cake mix), dough → bread loaf, sweet dough → muffins. One unit is used up at the start, then a 5 s timer; the Cooking check runs from `CookingLevel` to 100 (bread and muffins use `DefCooking`'s range). The food burns on failure or if the cook moves more than 3 tiles away.
- **Combinations:**
  - Open flour sack or bowl of flour + water → dough
  - Dough + pear / peach / apple / pumpkin / eggs / meat / sausage → the matching unbaked pie, quiche or pizza
  - Dough + honey → sweet dough
  - Sweet dough + honey → cookie mix
  - Flour + sweet dough → cake mix
  - The honey and flour + sweet dough recipes work in either direction.
- **Water:** water drinks (pitchers), buckets, barrels, tubs and trough add-ons, in the pack, in hand, or on the ground within 2 tiles and in line of sight.
- **Cooking tools are passive:** with T2A menus on, a tool whose system has no T2A menu (`T2ACraftSystem.HasMenu`) falls through to `ShowCraftMenu`, which does nothing under T2A. No dead target is left.

Behaviour with T2A menus off is unchanged.

## Follow-ups
- Static troughs/barrels and open water aren't water sources here or for pitcher filling (no static water ID list exists); to be fixed separately.
- Whether a bowl of flour returns an empty bowl is unconfirmed (`//TODO`).
- Cooking tools that must merely be in the pack for some recipes are not modelled yet.

## Testing
- `dotnet build`: 0 warnings, 0 errors
- New `T2ACookingTests`: flour + water, closed sack refused, dough + apple, honey in both directions, cookie mix, cake mix, wrong target consumes nothing, water in another player's pack refused
- Not covered: the heat timer (untested); not yet exercised in game
2026-10-20 23:37:28 -07:00

184 lines
4.8 KiB
C#

using System;
using ModernUO.Serialization;
using Server.Engines.Craft;
using Server.Engines.Craft.T2A;
using Server.Network;
namespace Server.Items;
public enum ToolQuality
{
Low,
Regular,
Exceptional
}
[SerializationGenerator(2, false)]
public abstract partial class BaseTool : Item, IUsesRemaining, ICraftable
{
[InvalidateProperties]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _crafter;
[InvalidateProperties]
[SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _usesRemaining;
public BaseTool(int itemID) : this(Utility.RandomMinMax(25, 75), itemID)
{
}
public BaseTool(int uses, int itemID) : base(itemID)
{
_usesRemaining = uses;
_quality = ToolQuality.Regular;
}
[CommandProperty(AccessLevel.GameMaster)]
[SerializableProperty(1)]
public ToolQuality Quality
{
get => _quality;
set
{
UnscaleUses();
_quality = value;
ScaleUses();
this.MarkDirty();
}
}
public virtual bool BreakOnDepletion => true;
public abstract CraftSystem CraftSystem { get; }
private bool ShowUsesRemaining { get; set; } = true;
public virtual int OnCraft(
int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
CraftItem craftItem, int resHue
)
{
Quality = (ToolQuality)quality;
if (makersMark)
{
Crafter = from?.RawName;
}
if (Core.UOR)
{
if (Quality == ToolQuality.Exceptional)
{
UsesRemaining = 100;
}
}
else if (Quality != ToolQuality.Regular)
{
UsesRemaining += (int)(UsesRemaining * ((int)Quality - 1) * 0.2);
}
return quality;
}
bool IUsesRemaining.ShowUsesRemaining
{
get => ShowUsesRemaining;
set => ShowUsesRemaining = value;
}
public void ScaleUses()
{
UsesRemaining = _usesRemaining * GetUsesScalar() / 100;
InvalidateProperties();
}
public void UnscaleUses()
{
UsesRemaining = _usesRemaining * 100 / GetUsesScalar();
}
public int GetUsesScalar() => _quality == ToolQuality.Exceptional ? 200 : 100;
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
// Makers mark not displayed on OSI
// if (m_Crafter != null)
// list.Add( 1050043, m_Crafter.Name ); // crafted by ~1_NAME~
if (_quality == ToolQuality.Exceptional)
{
list.Add(1060636); // exceptional
}
list.Add(1060584, _usesRemaining); // uses remaining: ~1_val~
}
public virtual void DisplayDurabilityTo(Mobile m)
{
LabelToAffix(m, 1017323, AffixType.Append, $": {_usesRemaining}"); // Durability
}
public static bool CheckAccessible(Item tool, Mobile m) => tool.IsChildOf(m) || tool.Parent == m;
public static bool CheckTool(Item tool, Mobile m)
{
var check = m.FindItemOnLayer(Layer.OneHanded);
if (check is BaseTool && check != tool && check is not AncientSmithyHammer)
{
return false;
}
check = m.FindItemOnLayer(Layer.TwoHanded);
return check is not BaseTool || check == tool || check is AncientSmithyHammer;
}
public override void OnSingleClick(Mobile from)
{
DisplayDurabilityTo(from);
base.OnSingleClick(from);
}
public override void OnDoubleClick(Mobile from)
{
if (IsChildOf(from.Backpack) || Parent == from)
{
var system = CraftSystem;
var num = system.CanCraft(from, this, null);
// Blacksmithing shows the gump regardless of proximity of an anvil and forge after SE
if (num > 0 && (num != 1044267 || !Core.SE))
{
from.SendLocalizedMessage(num);
}
else if (T2ACraftSystem.Enabled && T2ACraftSystem.HasMenu(system))
{
from.Target = new T2ACraftToolTarget(this, system);
from.SendAsciiMessage("Target this tool to make last item, or any other target to begin crafting.");
}
else
{
CraftItem.ShowCraftMenu(from, system, this, null);
}
}
else
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
}
private void Deserialize(IGenericReader reader, int version)
{
Timer.DelayCall((item, crafter) => item._crafter = crafter?.RawName, this, reader.ReadEntity<Mobile>());
_quality = (ToolQuality)reader.ReadInt();
_usesRemaining = reader.ReadInt();
}
}