BlueGit

timfa questward

Files

questward / shared / definitions / spellItems.js

spellItems.js

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