| 1 | import { clothingTemplate, yarnItemId, wovenClothItemId } from "../definitions/clothItems.js"; |
| 2 | import { CLOTH_TIER_ORDER, ClothTier, tierCraftSkillLevel } from "../definitions/materialTiers.js"; |
| 3 | import { ItemId } from "../definitions/items.js"; |
| 4 | |
| 5 | /** |
| 6 | * Resolve a tailor craft into a concrete recipe (inputs/output) for the chosen cloth tier. |
| 7 | * @returns {{ ok: true, recipe: object } | { ok: false, reason: string }} |
| 8 | */ |
| 9 | export function resolveTailorCraft ({ templateId, clothTier, dyeStack = null }) |
| 10 | { |
| 11 | const template = clothingTemplate(templateId); |
| 12 | if (!template) |
| 13 | { return { ok: false, reason: "Unknown garment template." }; } |
| 14 | const tier = CLOTH_TIER_ORDER.includes(clothTier) ? clothTier : ClothTier.cotton; |
| 15 | const outputItemId = template.outputItemIdForTier(tier); |
| 16 | if (!outputItemId) |
| 17 | { return { ok: false, reason: "That material cannot make this garment." }; } |
| 18 | |
| 19 | const inputs = []; |
| 20 | for (const need of template.inputs ?? []) |
| 21 | { |
| 22 | const quantity = Math.max(1, need.quantity | 0 || 1); |
| 23 | if (need.kind === "yarn") |
| 24 | { inputs.push({ itemId: yarnItemId(tier), quantity }); } |
| 25 | else if (need.kind === "cloth") |
| 26 | { inputs.push({ itemId: wovenClothItemId(tier), quantity }); } |
| 27 | else |
| 28 | { return { ok: false, reason: "Unsupported tailor ingredient." }; } |
| 29 | } |
| 30 | |
| 31 | let dyeColor = null; |
| 32 | if (dyeStack) |
| 33 | { |
| 34 | if (dyeStack.itemId !== ItemId.dye || dyeStack.instance?.kind !== "dye") |
| 35 | { return { ok: false, reason: "That is not a dye." }; } |
| 36 | dyeColor = dyeStack.instance.color; |
| 37 | } |
| 38 | |
| 39 | return { |
| 40 | ok: true, |
| 41 | recipe: Object.freeze({ |
| 42 | recipeId: `tailor-${template.templateId}`, |
| 43 | stationId: "tailor-bench", |
| 44 | tailorTemplate: template.templateId, |
| 45 | clothTier: tier, |
| 46 | output: { itemId: outputItemId, quantity: 1 }, |
| 47 | inputs, |
| 48 | minSkillLevel: Math.max(template.minSkillLevel | 0 || 1, tierCraftSkillLevel(tier)), |
| 49 | skillId: "tailoring", |
| 50 | xpMaterial: tier, |
| 51 | dyeColor, |
| 52 | consumeDye: !!dyeColor |
| 53 | }) |
| 54 | }; |
| 55 | } |