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