BlueGit

timfa questward

Files

questward / shared / crafting / tailor.js

tailor.js

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