ModernUO/Projects/UOContent/Items/Food/CookableFood.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

351 lines
7.9 KiB
C#

using ModernUO.Serialization;
using Server.Engines.Craft.T2A;
using Server.Targeting;
namespace Server.Items;
[SerializationGenerator(0, false)]
public abstract partial class CookableFood : Item, IT2ACombinable
{
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _cookingLevel;
public CookableFood(int itemID, int cookingLevel) : base(itemID) => _cookingLevel = cookingLevel;
public abstract Food Cook();
public override void OnDoubleClick(Mobile from)
{
if (T2ACraftSystem.Enabled)
{
T2ACooking.Prompt(from, this);
}
else
{
base.OnDoubleClick(from);
}
}
public bool TryCombine(Mobile from, object target) =>
IsHeatSource(target) ? T2ACooking.BeginHeat(from, this, target) : T2ACooking.CannotCombine(from);
public static bool IsHeatSource(object targeted)
{
int itemID;
if (targeted is Item item)
{
itemID = item.ItemID;
}
else if (targeted is StaticTarget target)
{
itemID = target.ItemID;
}
else
{
return false;
}
if (itemID >= 0xDE3 && itemID <= 0xDE9)
{
return true; // Campfire
}
if (itemID >= 0x461 && itemID <= 0x48E)
{
return true; // Sandstone oven/fireplace
}
if (itemID >= 0x92B && itemID <= 0x96C)
{
return true; // Stone oven/fireplace
}
if (itemID == 0xFAC)
{
return true; // Firepit
}
if (itemID >= 0x184A && itemID <= 0x184C)
{
return true; // Heating stand (left)
}
if (itemID >= 0x184E && itemID <= 0x1850)
{
return true; // Heating stand (right)
}
if (itemID >= 0x398C && itemID <= 0x399F)
{
return true; // Fire field
}
return false;
}
}
[SerializationGenerator(0, false)]
public partial class RawRibs : CookableFood
{
[Constructible]
public RawRibs(int amount = 1) : base(0x9F1, 10)
{
Stackable = true;
Amount = amount;
}
public override double DefaultWeight => 1.0;
public override Food Cook() => new Ribs();
}
[SerializationGenerator(0, false)]
public partial class RawLambLeg : CookableFood
{
[Constructible]
public RawLambLeg(int amount = 1) : base(0x1609, 10)
{
Stackable = true;
Amount = amount;
}
public override Food Cook() => new LambLeg();
}
[SerializationGenerator(0, false)]
public partial class RawChickenLeg : CookableFood
{
[Constructible]
public RawChickenLeg() : base(0x1607, 10)
{
Stackable = true;
}
public override double DefaultWeight => 1.0;
public override Food Cook() => new ChickenLeg();
}
[SerializationGenerator(0, false)]
public partial class RawBird : CookableFood
{
[Constructible]
public RawBird(int amount = 1) : base(0x9B9, 10)
{
Stackable = true;
Amount = amount;
}
public override double DefaultWeight => 1.0;
public override Food Cook() => new CookedBird();
}
[SerializationGenerator(0, false)]
public partial class UnbakedPeachCobbler : CookableFood
{
[Constructible]
public UnbakedPeachCobbler() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041335; // unbaked peach cobbler
public override Food Cook() => new PeachCobbler();
}
[SerializationGenerator(0, false)]
public partial class UnbakedFruitPie : CookableFood
{
[Constructible]
public UnbakedFruitPie() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041334; // unbaked fruit pie
public override Food Cook() => new FruitPie();
}
[SerializationGenerator(0, false)]
public partial class UnbakedMeatPie : CookableFood
{
[Constructible]
public UnbakedMeatPie() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041338; // unbaked meat pie
public override Food Cook() => new MeatPie();
}
[SerializationGenerator(0, false)]
public partial class UnbakedPumpkinPie : CookableFood
{
[Constructible]
public UnbakedPumpkinPie() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041342; // unbaked pumpkin pie
public override Food Cook() => new PumpkinPie();
}
[SerializationGenerator(0, false)]
public partial class UnbakedApplePie : CookableFood
{
[Constructible]
public UnbakedApplePie() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041336; // unbaked apple pie
public override Food Cook() => new ApplePie();
}
[TypeAlias("Server.Items.UncookedPizza")]
[SerializationGenerator(0, false)]
public partial class UncookedCheesePizza : CookableFood
{
[Constructible]
public UncookedCheesePizza() : base(0x1083, 20)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041341; // uncooked cheese pizza
public override Food Cook() => new CheesePizza();
}
[SerializationGenerator(0, false)]
public partial class UncookedSausagePizza : CookableFood
{
[Constructible]
public UncookedSausagePizza() : base(0x1083, 20)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041337; // uncooked sausage pizza
public override Food Cook() => new SausagePizza();
}
[SerializationGenerator(0, false)]
public partial class UnbakedQuiche : CookableFood
{
[Constructible]
public UnbakedQuiche() : base(0x1042, 25)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041339; // unbaked quiche
public override Food Cook() => new Quiche();
}
[SerializationGenerator(0, false)]
public partial class Eggs : CookableFood
{
[Constructible]
public Eggs(int amount = 1) : base(0x9B5, 15)
{
Stackable = true;
Amount = amount;
}
public override double DefaultWeight => 1.0;
public override Food Cook() => new FriedEggs();
}
[SerializationGenerator(0, false)]
public partial class BrightlyColoredEggs : CookableFood
{
[Constructible]
public BrightlyColoredEggs() : base(0x9B5, 15)
{
Hue = 3 + Utility.Random(20) * 5;
}
public override double DefaultWeight => 0.5;
public override string DefaultName => "brightly colored eggs";
public override Food Cook() => new FriedEggs();
}
[SerializationGenerator(0, false)]
public partial class EasterEggs : CookableFood
{
[Constructible]
public EasterEggs() : base(0x9B5, 15)
{
Hue = 3 + Utility.Random(20) * 5;
}
public override double DefaultWeight => 0.5;
public override int LabelNumber => 1016105; // Easter Eggs
public override Food Cook() => new FriedEggs();
}
[SerializationGenerator(0, false)]
public partial class CookieMix : CookableFood
{
[Constructible]
public CookieMix() : base(0x103F, 20)
{
}
public override double DefaultWeight => 1.0;
public override Food Cook() => new Cookies();
}
[SerializationGenerator(0, false)]
public partial class CakeMix : CookableFood
{
[Constructible]
public CakeMix() : base(0x103F, 40)
{
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1041002; // cake mix
public override Food Cook() => new Cake();
}
[SerializationGenerator(0, false)]
public partial class RawFishSteak : CookableFood
{
[Constructible]
public RawFishSteak(int amount = 1) : base(0x097A, 10)
{
Stackable = true;
Amount = amount;
}
public override double DefaultWeight => 0.1;
public override Food Cook() => new FishSteak();
}