BlueGit

timfa questward

Files

questward / shared / definitions / leatherArmourItems.js

leatherArmourItems.js

leatherArmourItems.js 4.3 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 return Object.freeze({
77 itemId,
78 key: `${prefix}-${piece.suffix}`,
79 displayName: `${name} ${piece.label}`,
80 description: `Sturdy ${name.toLowerCase()} ${piece.label}, lined for long marches.`,
81 seedValue: 10,
82 stackable: false,
83 maxStackSize: 1,
84 uniqueInstance: false,
85 category: ItemCategory.finished,
86 iconKey: "leatherarmour",
87 defaultState: piece.suffix,
88 tier,
89 leatherTier: tier,
90 clothTier,
91 dualTintLeatherCloth: true,
92 dualTintFromTier: true,
93 equipment: Object.freeze({
94 slot: piece.slot,
95 tier,
96 kind: EquipmentKind.leatherArmour,
97 minSkillLevel: tierMinSkillLevel(tier),
98 dualTintFromTier: true,
99 equipSprite: equipImageName("item", "leatherarmour", piece.suffix)
100 })
101 });
102}
103
104function buildLeatherArmourDefinitions ()
105{
106 const defs = {};
107 for (const tier of LEATHER_TIER_ORDER)
108 {
109 for (const piece of LEATHER_ARMOUR_PIECES)
110 {
111 const prop = `${tier}${piece.idKey}`;
112 const itemId = LeatherArmourItemId[prop];
113 if (itemId == null)
114 { throw new Error(`Missing LeatherArmourItemId for ${prop}`); }
115 defs[itemId] = leatherArmourDef(itemId, tier, piece);
116 }
117 }
118 return Object.freeze(defs);
119}
120
121export const LEATHER_ARMOUR_ITEM_DEFINITIONS = buildLeatherArmourDefinitions();
122
123/** Leatherworking station recipes for chestguard, chausses, and helmet. */
124export function leatherArmourRecipes ()
125{
126 return LEATHER_TIER_ORDER.flatMap((leatherTier) =>
127 LEATHER_ARMOUR_PIECES.map((piece) =>
128 {
129 const leatherId = leatherMaterialItemId(leatherTier);
130 const outputId = leatherArmourItemIdForTier(leatherTier, piece.idKey);
131 if (leatherId == null || outputId == null)
132 { throw new Error(`Missing leather armour recipe ids for ${leatherTier} ${piece.suffix}`); }
133 const inputs = [{ itemId: leatherId, quantity: piece.leatherQty }];
134 if (piece.clothQty > 0)
135 {
136 const clothId = wovenClothItemId(clothTierForLeather(leatherTier));
137 if (clothId == null)
138 { throw new Error(`Missing cloth for ${leatherTier} ${piece.suffix}`); }
139 inputs.push({ itemId: clothId, quantity: piece.clothQty });
140 }
141 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
142 return Object.freeze({
143 recipeId: `leather-${piece.suffix}-${leatherTier}`,
144 craftGroup: `leather-${piece.suffix}`,
145 craftGroupLabel: label,
146 stationId: CraftingStationId.leatherworkingStation,
147 output: { itemId: outputId, quantity: 1 },
148 inputs,
149 minSkillLevel: tierCraftSkillLevel(leatherTier),
150 skillId: "leatherworking",
151 xpMaterial: leatherTier
152 });
153 }));
154}
155
156export { tierMinSkillLevel, tierCraftSkillLevel };