BlueGit

timfa questward

Files

questward / shared / definitions / spellItems.js

spellItems.js

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