BlueGit

timfa questward

Files

questward / shared / definitions / leatherArmourItems.js

leatherArmourItems.js

leatherArmourItems.js 4.4 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import { EquipmentKind } from "./equipmentKinds.js";
3import { equipImageName } from "./tileSprites.js";
4import { leatherMaterialItemId } from "./leatherItems.js";
5import { wovenClothItemId } from "./clothItems.js";
6import { CraftingStationId } from "./craftingStations.js";
7import
8{
9 LeatherTier,
10 LEATHER_TIER_ORDER,
11 LEATHER_DISPLAY_NAME,
12 clothTierForLeather,
13 tierMinSkillLevel,
14 tierCraftSkillLevel
15} from "./materialTiers.js";
16
17/** Leather chestguard, chausses, and helmet — dual tint (red leather, blue cloth trim). */
18export const LEATHER_ARMOUR_PIECES = Object.freeze([
19 Object.freeze({
20 suffix: "chestguard",
21 slot: "chest",
22 label: "chestguard",
23 idKey: "Chestguard",
24 leatherQty: 4,
25 clothQty: 2,
26 pieceKey: "chestguard"
27 }),
28 Object.freeze({
29 suffix: "chausses",
30 slot: "legs",
31 label: "chausses",
32 idKey: "Chausses",
33 leatherQty: 3,
34 clothQty: 1,
35 pieceKey: "chausses"
36 }),
37 Object.freeze({
38 suffix: "helmet",
39 slot: "head",
40 label: "helmet",
41 idKey: "Helmet",
42 leatherQty: 2,
43 clothQty: 0,
44 pieceKey: "helmet"
45 })
46]);
47
48function buildLeatherArmourItemIds ()
49{
50 const ids = {};
51 let nextId = 512;
52 for (const tier of LEATHER_TIER_ORDER)
53 {
54 for (const piece of LEATHER_ARMOUR_PIECES)
55 {
56 ids[`${tier}${piece.idKey}`] = nextId++;
57 }
58 }
59 return Object.freeze(ids);
60}
61
62export const LeatherArmourItemId = buildLeatherArmourItemIds();
63
64export function leatherArmourItemIdForTier (tier, idKey)
65{
66 return LeatherArmourItemId[`${tier}${idKey}`] ?? null;
67}
68
69function leatherArmourDef (itemId, tier, piece)
70{
71 const name = LEATHER_DISPLAY_NAME[tier] ?? tier;
72 const clothTier = clothTierForLeather(tier);
73 const prefix = tier === LeatherTier.softLeather
74 ? "soft-leather"
75 : tier.replace(/([A-Z])/g, "-$1").toLowerCase();
76 const tightFit = piece.suffix === "chestguard" || piece.suffix === "chausses";
77 return Object.freeze({
78 itemId,
79 key: `${prefix}-${piece.suffix}`,
80 displayName: `${name} ${piece.label}`,
81 description: `Sturdy ${name.toLowerCase()} ${piece.label}, lined for long marches.`,
82 seedValue: 10,
83 stackable: false,
84 maxStackSize: 1,
85 uniqueInstance: false,
86 category: ItemCategory.finished,
87 iconKey: "leatherarmour",
88 defaultState: piece.suffix,
89 tier,
90 leatherTier: tier,
91 clothTier,
92 dualTintLeatherCloth: true,
93 dualTintFromTier: true,
94 ...(tightFit ? { tightFit: true } : {}),
95 equipment: Object.freeze({
96 slot: piece.slot,
97 tier,
98 kind: EquipmentKind.leatherArmour,
99 minSkillLevel: tierMinSkillLevel(tier),
100 dualTintFromTier: true,
101 equipSprite: equipImageName("item", "leatherarmour", piece.suffix)
102 })
103 });
104}
105
106function buildLeatherArmourDefinitions ()
107{
108 const defs = {};
109 for (const tier of LEATHER_TIER_ORDER)
110 {
111 for (const piece of LEATHER_ARMOUR_PIECES)
112 {
113 const prop = `${tier}${piece.idKey}`;
114 const itemId = LeatherArmourItemId[prop];
115 if (itemId == null)
116 { throw new Error(`Missing LeatherArmourItemId for ${prop}`); }
117 defs[itemId] = leatherArmourDef(itemId, tier, piece);
118 }
119 }
120 return Object.freeze(defs);
121}
122
123export const LEATHER_ARMOUR_ITEM_DEFINITIONS = buildLeatherArmourDefinitions();
124
125/** Leatherworking station recipes for chestguard, chausses, and helmet. */
126export function leatherArmourRecipes ()
127{
128 return LEATHER_TIER_ORDER.flatMap((leatherTier) =>
129 LEATHER_ARMOUR_PIECES.map((piece) =>
130 {
131 const leatherId = leatherMaterialItemId(leatherTier);
132 const outputId = leatherArmourItemIdForTier(leatherTier, piece.idKey);
133 if (leatherId == null || outputId == null)
134 { throw new Error(`Missing leather armour recipe ids for ${leatherTier} ${piece.suffix}`); }
135 const inputs = [{ itemId: leatherId, quantity: piece.leatherQty }];
136 if (piece.clothQty > 0)
137 {
138 const clothId = wovenClothItemId(clothTierForLeather(leatherTier));
139 if (clothId == null)
140 { throw new Error(`Missing cloth for ${leatherTier} ${piece.suffix}`); }
141 inputs.push({ itemId: clothId, quantity: piece.clothQty });
142 }
143 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
144 return Object.freeze({
145 recipeId: `leather-${piece.suffix}-${leatherTier}`,
146 craftGroup: `leather-${piece.suffix}`,
147 craftGroupLabel: label,
148 stationId: CraftingStationId.leatherworkingStation,
149 output: { itemId: outputId, quantity: 1 },
150 inputs,
151 minSkillLevel: tierCraftSkillLevel(leatherTier),
152 skillId: "leatherworking",
153 xpMaterial: leatherTier
154 });
155 }));
156}
157
158export { tierMinSkillLevel, tierCraftSkillLevel };