import { clothingTemplate, yarnItemId, wovenClothItemId } from "../definitions/clothItems.js"; import { CLOTH_TIER_ORDER, ClothTier, tierCraftSkillLevel } from "../definitions/materialTiers.js"; import { ItemId } from "../definitions/items.js"; /** * Resolve a tailor craft into a concrete recipe (inputs/output) for the chosen cloth tier. * @returns {{ ok: true, recipe: object } | { ok: false, reason: string }} */ export function resolveTailorCraft ({ templateId, clothTier, dyeStack = null }) { const template = clothingTemplate(templateId); if (!template) { return { ok: false, reason: "Unknown garment template." }; } const tier = CLOTH_TIER_ORDER.includes(clothTier) ? clothTier : ClothTier.cotton; const outputItemId = template.outputItemIdForTier(tier); if (!outputItemId) { return { ok: false, reason: "That material cannot make this garment." }; } const inputs = []; for (const need of template.inputs ?? []) { const quantity = Math.max(1, need.quantity | 0 || 1); if (need.kind === "yarn") { inputs.push({ itemId: yarnItemId(tier), quantity }); } else if (need.kind === "cloth") { inputs.push({ itemId: wovenClothItemId(tier), quantity }); } else { return { ok: false, reason: "Unsupported tailor ingredient." }; } } let dyeColor = null; if (dyeStack) { if (dyeStack.itemId !== ItemId.dye || dyeStack.instance?.kind !== "dye") { return { ok: false, reason: "That is not a dye." }; } dyeColor = dyeStack.instance.color; } return { ok: true, recipe: Object.freeze({ recipeId: `tailor-${template.templateId}`, stationId: "tailor-bench", tailorTemplate: template.templateId, clothTier: tier, output: { itemId: outputItemId, quantity: 1 }, inputs, minSkillLevel: Math.max(template.minSkillLevel | 0 || 1, tierCraftSkillLevel(tier)), skillId: "tailoring", xpMaterial: tier, dyeColor, consumeDye: !!dyeColor }) }; }