BlueGit

timfa questward

Files

questward / shared / definitions / spellItems.js

spellItems.js

magics
timfa Tim Falken · pushed by timfa · 2 months ago
8b1a158b History
spellItems.js 2.1 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js";
3
4/** Stable ids for spellbooks (spark keeps legacy 134). */
5const SPELLBOOK_ID_BY_SPELL = Object.freeze({
6 [SpellId.spark]: 134,
7 [SpellId.dark]: 391,
8 [SpellId.firebolt]: 392,
9 [SpellId.fireball]: 393,
10 [SpellId.blaze]: 394,
11 [SpellId.inferno]: 395,
12 [SpellId.hellfire]: 396,
13 [SpellId.poison]: 397,
14 [SpellId.drain]: 398,
15 [SpellId.tinders]: 399,
16 [SpellId.shade]: 400,
17 [SpellId.revitalize]: 401
18});
19
20export const SpellbookItemId = Object.freeze(
21 Object.fromEntries(
22 Object.entries(SPELLBOOK_ID_BY_SPELL).map(([spellId, itemId]) =>
23 {
24 const key = `${spellId}Spellbook`;
25 return [key, itemId];
26 })
27 )
28);
29
30export function spellbookInstance (spellId)
31{
32 const def = spellDefinition(spellId);
33 if (!def)
34 { return null; }
35 return Object.freeze({
36 kind: "spellbook",
37 spellId,
38 displayName: `${def.displayName} spellbook`
39 });
40}
41
42function buildSpellbookDefinitions ()
43{
44 const out = {};
45 for (const spellId of learnableSpellIds())
46 {
47 const itemId = SPELLBOOK_ID_BY_SPELL[spellId];
48 const spell = spellDefinition(spellId);
49 if (itemId == null || !spell)
50 { continue; }
51 out[itemId] = Object.freeze({
52 itemId,
53 key: `spellbook-${spellId}`,
54 displayName: `Spellbook: ${spell.displayName}`,
55 description: `A worn volume of sigils. Study it carefully to learn ${spell.displayName}.`,
56 seedValue: 20 + (spell.tier | 0) * 10,
57 stackable: false,
58 maxStackSize: 1,
59 uniqueInstance: true,
60 category: ItemCategory.finished,
61 iconKey: "spellbook",
62 defaultState: spellId === SpellId.spark ? "spark" : "spark",
63 consumableSpellId: spellId
64 });
65 }
66 return out;
67}
68
69/** @type {Record<number, object>} */
70export const SPELLBOOK_ITEM_DEFINITIONS = Object.freeze(buildSpellbookDefinitions());
71
72export function spellbookItemForSpell (spellId)
73{
74 for (const def of Object.values(SPELLBOOK_ITEM_DEFINITIONS))
75 {
76 if (def.consumableSpellId === spellId)
77 { return def; }
78 }
79 return null;
80}
81
82export function spellbookItemIdForSpell (spellId)
83{
84 return SPELLBOOK_ID_BY_SPELL[spellId] ?? null;
85}