import { ItemCategory } from "./itemCategories.js"; import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js"; /** Stable ids for spellbooks (spark keeps legacy 134). */ const SPELLBOOK_ID_BY_SPELL = Object.freeze({ [SpellId.spark]: 134, [SpellId.dark]: 391, [SpellId.firebolt]: 392, [SpellId.fireball]: 393, [SpellId.blaze]: 394, [SpellId.inferno]: 395, [SpellId.hellfire]: 396, [SpellId.poison]: 397, [SpellId.drain]: 398, [SpellId.tinders]: 399, [SpellId.shade]: 400, [SpellId.revitalize]: 401 }); export const SpellbookItemId = Object.freeze( Object.fromEntries( Object.entries(SPELLBOOK_ID_BY_SPELL).map(([spellId, itemId]) => { const key = `${spellId}Spellbook`; return [key, itemId]; }) ) ); export function spellbookInstance (spellId) { const def = spellDefinition(spellId); if (!def) { return null; } return Object.freeze({ kind: "spellbook", spellId, displayName: `${def.displayName} spellbook` }); } function buildSpellbookDefinitions () { const out = {}; for (const spellId of learnableSpellIds()) { const itemId = SPELLBOOK_ID_BY_SPELL[spellId]; const spell = spellDefinition(spellId); if (itemId == null || !spell) { continue; } out[itemId] = Object.freeze({ itemId, key: `spellbook-${spellId}`, displayName: `Spellbook: ${spell.displayName}`, description: `A worn volume of sigils. Study it carefully to learn ${spell.displayName}.`, seedValue: 20 + (spell.tier | 0) * 10, stackable: false, maxStackSize: 1, uniqueInstance: true, category: ItemCategory.finished, iconKey: "spellbook", defaultState: spellId === SpellId.spark ? "spark" : "spark", consumableSpellId: spellId }); } return out; } /** @type {Record} */ export const SPELLBOOK_ITEM_DEFINITIONS = Object.freeze(buildSpellbookDefinitions()); export function spellbookItemForSpell (spellId) { for (const def of Object.values(SPELLBOOK_ITEM_DEFINITIONS)) { if (def.consumableSpellId === spellId) { return def; } } return null; } export function spellbookItemIdForSpell (spellId) { return SPELLBOOK_ID_BY_SPELL[spellId] ?? null; }