BlueGit

timfa questward

Files

questward / shared / definitions / wizardItems.js

wizardItems.js

wizardItems.js 4.7 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import { EquipmentKind } from "./equipmentKinds.js";
3import { equipImageName } from "./tileSprites.js";
4import
5{
6 ClothTier,
7 CLOTH_TIER_ORDER,
8 CLOTH_DISPLAY_NAME,
9 leatherTierForCloth,
10 tierMinSkillLevel
11} from "./materialTiers.js";
12
13export const WIZARD_PIECES = Object.freeze([
14 Object.freeze({
15 templateId: "wizard-hat",
16 suffix: "hat",
17 slot: "head",
18 label: "hat",
19 idKey: "Hat",
20 pieceKey: "hat",
21 clothQty: 2,
22 leatherQty: 1,
23 dualTint: true
24 }),
25 Object.freeze({
26 templateId: "wizard-robetop",
27 suffix: "robetop",
28 slot: "chest",
29 label: "robe top",
30 idKey: "RobeTop",
31 pieceKey: "robetop",
32 clothQty: 5,
33 leatherQty: 1,
34 dualTint: true
35 }),
36 Object.freeze({
37 templateId: "wizard-robebottoms",
38 suffix: "robebottoms",
39 slot: "legs",
40 label: "robe bottoms",
41 idKey: "RobeBottoms",
42 pieceKey: "robebottoms",
43 clothQty: 4,
44 leatherQty: 0,
45 dualTint: false
46 }),
47 Object.freeze({
48 templateId: "wizard-shoes",
49 suffix: "shoes",
50 slot: "boots",
51 label: "shoes",
52 idKey: "Shoes",
53 pieceKey: "shoes",
54 clothQty: 1,
55 leatherQty: 1,
56 dualTint: true
57 })
58]);
59
60function buildWizardItemIds ()
61{
62 const ids = {};
63 let nextId = 533;
64 for (const tier of CLOTH_TIER_ORDER)
65 {
66 for (const piece of WIZARD_PIECES)
67 {
68 ids[`${tier}${piece.idKey}`] = nextId++;
69 }
70 }
71 return Object.freeze(ids);
72}
73
74export const WizardItemId = buildWizardItemIds();
75
76export function wizardItemIdForTier (clothTier, idKey)
77{
78 return WizardItemId[`${clothTier}${idKey}`] ?? null;
79}
80
81function wizardPieceDef (itemId, clothTier, piece)
82{
83 const name = CLOTH_DISPLAY_NAME[clothTier] ?? clothTier;
84 const leatherTier = leatherTierForCloth(clothTier);
85 const tierSlug = clothTier === ClothTier.cotton
86 ? "cotton"
87 : clothTier.replace(/([A-Z])/g, "-$1").toLowerCase();
88 const def = {
89 itemId,
90 key: `${tierSlug}-wizard-${piece.suffix}`,
91 displayName: `${name} ${piece.label}`,
92 description: piece.suffix === "hat"
93 ? `A pointed ${name.toLowerCase()} hat, cut for study and spellcraft.`
94 : piece.suffix === "robetop"
95 ? `A long ${name.toLowerCase()} robe top, loose enough for gestures and runes.`
96 : piece.suffix === "robebottoms"
97 ? `Flowing ${name.toLowerCase()} robe bottoms that brush the ground when you walk.`
98 : `Soft ${name.toLowerCase()} shoes, quiet on stone floors.`,
99 seedValue: 8,
100 stackable: false,
101 maxStackSize: 1,
102 uniqueInstance: false,
103 category: ItemCategory.finished,
104 iconKey: "magicrobes",
105 defaultState: piece.suffix,
106 tier: clothTier,
107 equipment: Object.freeze({
108 slot: piece.slot,
109 tier: clothTier,
110 kind: EquipmentKind.wizardCloth,
111 minSkillLevel: tierMinSkillLevel(clothTier),
112 equipSprite: equipImageName("item", "magicrobes", piece.suffix)
113 })
114 };
115 if (piece.dualTint)
116 {
117 def.leatherTier = leatherTier;
118 def.clothTier = clothTier;
119 def.dualTintLeatherCloth = true;
120 def.dualTintFromTier = true;
121 def.equipment = Object.freeze({
122 ...def.equipment,
123 dualTintFromTier: true
124 });
125 }
126 else
127 {
128 def.tintFromTier = true;
129 def.equipment = Object.freeze({
130 ...def.equipment,
131 tintFromTier: true
132 });
133 }
134 return Object.freeze(def);
135}
136
137function buildWizardDefinitions ()
138{
139 const defs = {};
140 for (const tier of CLOTH_TIER_ORDER)
141 {
142 for (const piece of WIZARD_PIECES)
143 {
144 const prop = `${tier}${piece.idKey}`;
145 const itemId = WizardItemId[prop];
146 if (itemId == null)
147 { throw new Error(`Missing WizardItemId for ${prop}`); }
148 defs[itemId] = wizardPieceDef(itemId, tier, piece);
149 }
150 }
151 return Object.freeze(defs);
152}
153
154export const WIZARD_ITEM_DEFINITIONS = buildWizardDefinitions();
155
156/** Tailor bench templates for wizard robes. */
157export const WIZARD_TEMPLATES = Object.freeze(
158 Object.fromEntries(WIZARD_PIECES.map((piece) =>
159 {
160 const inputs = [{ kind: "cloth", quantity: piece.clothQty }];
161 if (piece.leatherQty > 0)
162 { inputs.push({ kind: "leather", quantity: piece.leatherQty }); }
163 return [piece.templateId, Object.freeze({
164 templateId: piece.templateId,
165 displayName: piece.label.charAt(0).toUpperCase() + piece.label.slice(1),
166 slot: piece.slot,
167 inputs: Object.freeze(inputs),
168 outputItemIdForTier: (tier) => wizardItemIdForTier(tier, piece.idKey),
169 minSkillLevel: 1
170 })];
171 }))
172);
173
174export function wizardTemplate (templateId)
175{
176 return WIZARD_TEMPLATES[templateId] ?? null;
177}
178
179export function listWizardTemplates ()
180{
181 return Object.values(WIZARD_TEMPLATES);
182}
183
184export function wizardHatItemId (tier) { return wizardItemIdForTier(tier, "Hat"); }
185export function wizardRobeTopItemId (tier) { return wizardItemIdForTier(tier, "RobeTop"); }
186export function wizardRobeBottomsItemId (tier) { return wizardItemIdForTier(tier, "RobeBottoms"); }
187export function wizardShoesItemId (tier) { return wizardItemIdForTier(tier, "Shoes"); }