BlueGit

timfa questward

Files

questward / shared / definitions / spellItems.js

spellItems.js

spellItems.js 2.9 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js";
3
4/**
5 * Stable spellbook item ids.
6 * Legacy spark spellbook (134) is retired — id kept unused so saves do not collide.
7 */
8const SPELLBOOK_ID_BY_SPELL = Object.freeze({
9 [SpellId.dark]: 391,
10 [SpellId.firebolt]: 392,
11 [SpellId.fireball]: 393,
12 [SpellId.blaze]: 394,
13 [SpellId.inferno]: 395,
14 [SpellId.hellfire]: 396,
15 [SpellId.poison]: 397,
16 [SpellId.drain]: 398,
17 [SpellId.tinders]: 399,
18 [SpellId.shade]: 400,
19 [SpellId.revitalize]: 401,
20 // Water tree
21 [SpellId.waterbolt]: 431,
22 [SpellId.waterspout]: 432,
23 [SpellId.torrent]: 433,
24 [SpellId.deluge]: 434,
25 [SpellId.maelstrom]: 435,
26 // Air tree
27 [SpellId.airbolt]: 436,
28 [SpellId.gale]: 437,
29 [SpellId.cyclone]: 438,
30 [SpellId.tempest]: 439,
31 [SpellId.hurricane]: 440,
32 // Earth tree
33 [SpellId.earthbolt]: 441,
34 [SpellId.boulder]: 442,
35 [SpellId.quake]: 443,
36 [SpellId.landslide]: 444,
37 [SpellId.cataclysm]: 445,
38 // Light tree
39 [SpellId.lightbolt]: 446,
40 [SpellId.radiance]: 447,
41 [SpellId.flare]: 448,
42 [SpellId.sunbeam]: 449,
43 [SpellId.judgment]: 450,
44 // Dark tree
45 [SpellId.darkbolt]: 451,
46 [SpellId.gloom]: 452,
47 [SpellId.voidlance]: 453,
48 [SpellId.eclipse]: 454,
49 [SpellId.oblivion]: 455,
50 // Poison tree
51 [SpellId.poisonbolt]: 456,
52 [SpellId.toxinburst]: 457,
53 [SpellId.venomcloud]: 458,
54 [SpellId.plague]: 459,
55 [SpellId.blight]: 460
56});
57
58export const SpellbookItemId = Object.freeze(
59 Object.fromEntries(
60 Object.entries(SPELLBOOK_ID_BY_SPELL).map(([spellId, itemId]) =>
61 {
62 const key = `${spellId}Spellbook`;
63 return [key, itemId];
64 })
65 )
66);
67
68export function spellbookInstance (spellId)
69{
70 const def = spellDefinition(spellId);
71 if (!def)
72 { return null; }
73 return Object.freeze({
74 kind: "spellbook",
75 spellId,
76 displayName: `${def.displayName} spellbook`
77 });
78}
79
80function buildSpellbookDefinitions ()
81{
82 const out = {};
83 for (const spellId of learnableSpellIds())
84 {
85 const itemId = SPELLBOOK_ID_BY_SPELL[spellId];
86 const spell = spellDefinition(spellId);
87 if (itemId == null || !spell)
88 { continue; }
89 out[itemId] = Object.freeze({
90 itemId,
91 key: `spellbook-${spellId}`,
92 displayName: `Spellbook: ${spell.displayName}`,
93 description: `A worn volume of sigils. Study it carefully to learn ${spell.displayName}.`,
94 seedValue: 20 + (spell.tier | 0) * 10,
95 stackable: false,
96 maxStackSize: 1,
97 uniqueInstance: true,
98 category: ItemCategory.finished,
99 iconKey: "spellbook",
100 defaultState: "spark",
101 consumableSpellId: spellId
102 });
103 }
104 return out;
105}
106
107/** @type {Record<number, object>} */
108export const SPELLBOOK_ITEM_DEFINITIONS = Object.freeze(buildSpellbookDefinitions());
109
110export function spellbookItemForSpell (spellId)
111{
112 for (const def of Object.values(SPELLBOOK_ITEM_DEFINITIONS))
113 {
114 if (def.consumableSpellId === spellId)
115 { return def; }
116 }
117 return null;
118}
119
120export function spellbookItemIdForSpell (spellId)
121{
122 return SPELLBOOK_ID_BY_SPELL[spellId] ?? null;
123}