## 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
211 lines
6.7 KiB
C#
211 lines
6.7 KiB
C#
using System;
|
|
using Server.Items;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Engines.Craft.T2A;
|
|
|
|
/// <summary>An item that can be double-clicked under T2A to combine with, or cook over, a target.</summary>
|
|
public interface IT2ACombinable
|
|
{
|
|
bool TryCombine(Mobile from, object target);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shared helpers for T2A cooking, which is item-on-item and item-on-heat-source rather than a craft menu.
|
|
/// Each ingredient item decides its own results in <see cref="IT2ACombinable.TryCombine"/>.
|
|
/// </summary>
|
|
public sealed class T2ACooking
|
|
{
|
|
private const int _heatSourceRange = 1;
|
|
private const int _waterRange = 2;
|
|
private const int _burnRange = 3;
|
|
|
|
private T2ACooking()
|
|
{
|
|
}
|
|
|
|
/// <summary>Asks the player for a target if the item is in their pack.</summary>
|
|
public static void Prompt(Mobile from, Item source)
|
|
{
|
|
if (!ValidateInPack(from, source))
|
|
{
|
|
return;
|
|
}
|
|
|
|
from.SendAsciiMessage("What do you wish to combine this with, or cook it over?");
|
|
from.Target = new CookTarget(source);
|
|
}
|
|
|
|
public static bool ValidateInPack(Mobile from, Item item)
|
|
{
|
|
if (item is { Deleted: false } && item.IsChildOf(from.Backpack))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
|
|
return false;
|
|
}
|
|
|
|
public static bool CannotCombine(Mobile from)
|
|
{
|
|
from.SendAsciiMessage("You cannot combine those.");
|
|
return false;
|
|
}
|
|
|
|
//TODO Support static water troughs and barrels (no static water ID list exists yet)
|
|
public static IHasQuantity GetWaterSource(object o) =>
|
|
o switch
|
|
{
|
|
BaseBeverage { Content: BeverageType.Water, Quantity: > 0 } bev => bev,
|
|
BaseWaterContainer { IsEmpty: false } container => container,
|
|
AddonComponent { Addon: IWaterSource { Quantity: > 0 } trough } => trough,
|
|
IWaterSource { Quantity: > 0 } source => source,
|
|
_ => null
|
|
};
|
|
|
|
// Ground water only, so a nearby open container (someone else's pack) cannot be drawn from.
|
|
public static bool CanReachWater(Mobile from, Item water)
|
|
{
|
|
if (water.IsChildOf(from.Backpack) || water.Parent == from ||
|
|
water.RootParent == null && water.Map == from.Map &&
|
|
from.InRange(water.GetWorldLocation(), _waterRange) && from.InLOS(water))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Spends one unit of each ingredient and gives the player the result.</summary>
|
|
public static bool Combine(Mobile from, object source, object target, Item result, string message)
|
|
{
|
|
ConsumeOne(source);
|
|
ConsumeOne(target);
|
|
|
|
if (!GiveResult(from, result))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
from.SendAsciiMessage(message);
|
|
return true;
|
|
}
|
|
|
|
// AddToBackpack drops a result that does not fit at the mobile's feet (or logout location),
|
|
// but with no valid map either it would be left on the internal map forever.
|
|
private static bool GiveResult(Mobile from, Item result)
|
|
{
|
|
if (from.AddToBackpack(result) || result.Map != null && result.Map != Map.Internal)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
result.Delete();
|
|
return false;
|
|
}
|
|
|
|
//TODO Confirm whether an empty bowl is returned when a BowlFlour is used up
|
|
private static void ConsumeOne(object o)
|
|
{
|
|
if (o is IHasQuantity container)
|
|
{
|
|
container.Quantity--;
|
|
}
|
|
else if (o is Item item)
|
|
{
|
|
item.Consume();
|
|
}
|
|
}
|
|
|
|
/// <summary>Cooks the source over a heat source if it is close enough and the player is not already cooking.</summary>
|
|
public static bool BeginHeat(Mobile from, Item source, object target)
|
|
{
|
|
var point = target is IPoint3D p ? new Point3D(p) : from.Location;
|
|
if (from.Map == null || !from.InRange(point, _heatSourceRange))
|
|
{
|
|
from.SendLocalizedMessage(500446); // That is too far away.
|
|
return false;
|
|
}
|
|
|
|
if (!from.BeginAction<T2ACooking>())
|
|
{
|
|
from.SendLocalizedMessage(500119); // You must wait to perform another action
|
|
return false;
|
|
}
|
|
|
|
from.PlaySound(0x225);
|
|
source.Consume();
|
|
|
|
Timer.DelayCall(TimeSpan.FromSeconds(5.0), FinishHeat, from, source, from.Map, point);
|
|
return true;
|
|
}
|
|
|
|
// The source is already consumed here and may be deleted, so only its type and CookingLevel are read.
|
|
private static void FinishHeat(Mobile from, Item source, Map map, Point3D point)
|
|
{
|
|
from.EndAction<T2ACooking>();
|
|
|
|
if (from.Deleted)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (from.Map != map || !from.InRange(point, _burnRange))
|
|
{
|
|
from.SendLocalizedMessage(500686); // You burn the food to a crisp! It's ruined.
|
|
return;
|
|
}
|
|
|
|
var (min, max) = source switch
|
|
{
|
|
CookableFood food => (food.CookingLevel, 100.0),
|
|
Dough => CraftRange(typeof(BreadLoaf)),
|
|
SweetDough => CraftRange(typeof(Muffins)),
|
|
_ => (0.0, 100.0)
|
|
};
|
|
|
|
if (!from.CheckSkill(SkillName.Cooking, min, max))
|
|
{
|
|
from.SendLocalizedMessage(500686); // You burn the food to a crisp! It's ruined.
|
|
return;
|
|
}
|
|
|
|
Item result = source switch
|
|
{
|
|
CookableFood food => food.Cook(),
|
|
Dough => new BreadLoaf(),
|
|
SweetDough => new Muffins(),
|
|
_ => null
|
|
};
|
|
|
|
if (result != null && GiveResult(from, result))
|
|
{
|
|
from.PlaySound(0x57);
|
|
}
|
|
}
|
|
|
|
// Falls back to the full range when the cooking craft system has no entry or is not initialized.
|
|
private static (double Min, double Max) CraftRange(Type type)
|
|
{
|
|
var skills = DefCooking.CraftSystem?.CraftItems.SearchFor(type)?.Skills;
|
|
|
|
return skills is { Count: > 0 } ? (skills[0].MinSkill, skills[0].MaxSkill) : (0.0, 100.0);
|
|
}
|
|
|
|
private sealed class CookTarget : Target
|
|
{
|
|
private readonly Item _source;
|
|
|
|
public CookTarget(Item source) : base(_waterRange, false, TargetFlags.None) => _source = source;
|
|
|
|
protected override void OnTarget(Mobile from, object targeted)
|
|
{
|
|
if (ValidateInPack(from, _source) && _source is IT2ACombinable combinable)
|
|
{
|
|
combinable.TryCombine(from, targeted);
|
|
}
|
|
}
|
|
}
|
|
}
|