import { spellDifficultyFromTier } from "../spells/constants.js"; import { MATERIAL_TIER_ORDER, tierStatBonus, tierMinSkillLevel } from "./materialTiers.js"; import { MagicElement } from "./attackTypes.js"; /** * @typedef {object} SpellDefinition * @property {string} spellId * @property {string} displayName * @property {number} tier Spell tier (sets difficulty and cast flash radius) * @property {import("../combat/magic.js").SpellElement} [element] * @property {"tile"|"entity"} target * @property {boolean} [autoRepeat] Auto-cast repeats while target stays in range * @property {number} [minMagicLevel] Minimum Magic level to cast / favourite * @property {string} description In-world spell description * @property {string} [projectileSprite] fx:projectile:spell-* base name * @property {string} [effect] Server impact kind (defaults to spellId) * @property {boolean} [starter] Known by default; no spellbook required * @property {boolean} [mobOnly] Not offered on player spellbooks * @property {boolean} [damageTree] Part of an elemental damage progression */ /** * Elemental damage trees (tiers 3–7), plus utility / special spells. * Legacy `spark` was removed — unknown ids are dropped on load/normalize. */ export const SpellId = Object.freeze({ light: "light", manaBullet: "mana-bullet", dark: "dark", magicMissile: "magic-missile", // Fire damage tree firebolt: "firebolt", fireball: "fireball", blaze: "blaze", inferno: "inferno", hellfire: "hellfire", // Water damage tree waterbolt: "waterbolt", waterspout: "waterspout", torrent: "torrent", deluge: "deluge", maelstrom: "maelstrom", // Air damage tree airbolt: "airbolt", gale: "gale", cyclone: "cyclone", tempest: "tempest", hurricane: "hurricane", // Earth damage tree earthbolt: "earthbolt", boulder: "boulder", quake: "quake", landslide: "landslide", cataclysm: "cataclysm", // Light damage tree lightbolt: "lightbolt", radiance: "radiance", flare: "flare", sunbeam: "sunbeam", judgment: "judgment", // Dark damage tree darkbolt: "darkbolt", gloom: "gloom", voidlance: "voidlance", eclipse: "eclipse", oblivion: "oblivion", // Poison damage tree poisonbolt: "poisonbolt", toxinburst: "toxinburst", venomcloud: "venomcloud", plague: "plague", blight: "blight", // Utility / special poison: "poison", drain: "drain", tinders: "tinders", shade: "shade", revitalize: "revitalize", /** Sprite elemental bolts (mob-only; not player spellbooks). */ spriteBoltFire: "sprite-bolt-fire", spriteBoltWater: "sprite-bolt-water", spriteBoltAir: "sprite-bolt-air", spriteBoltEarth: "sprite-bolt-earth", spriteBoltLight: "sprite-bolt-light", spriteBoltDark: "sprite-bolt-dark", spriteBoltPoison: "sprite-bolt-poison" }); /** Shared projectile art for damage bolts (tinted by element on cast later if needed). */ const BOLT_PROJECTILE = "fx:projectile:spell-spark"; const LIGHT_PROJECTILE = "fx:projectile:spell-light"; /** * Damage progression per element — mirrors the fire ladder (tiers 3–7). * @type {ReadonlyArray<{ element: string, spells: ReadonlyArray<{ id: string, name: string, description: string }> }>} */ const ELEMENT_DAMAGE_TREES = Object.freeze([ Object.freeze({ element: MagicElement.fire, spells: Object.freeze([ Object.freeze({ id: SpellId.firebolt, name: "Firebolt", description: "A fierce bolt of fire that streaks toward a foe and scorches on impact." }), Object.freeze({ id: SpellId.fireball, name: "Fireball", description: "A roaring sphere of flame that bursts against whatever it strikes." }), Object.freeze({ id: SpellId.blaze, name: "Blaze", description: "A searing tongue of fire that clings to flesh and armour alike." }), Object.freeze({ id: SpellId.inferno, name: "Inferno", description: "A storm of fire that overwhelms a foe in a rush of heat and ash." }), Object.freeze({ id: SpellId.hellfire, name: "Hellfire", description: "The deepest flame, white-hot and merciless, called down upon a single mark." }) ]) }), Object.freeze({ element: MagicElement.water, spells: Object.freeze([ Object.freeze({ id: SpellId.waterbolt, name: "Waterbolt", description: "A hard lance of water that strikes like a thrown spear." }), Object.freeze({ id: SpellId.waterspout, name: "Waterspout", description: "A rising column of water that hammers a foe from below." }), Object.freeze({ id: SpellId.torrent, name: "Torrent", description: "A rushing flood aimed at one mark, crushing and cold." }), Object.freeze({ id: SpellId.deluge, name: "Deluge", description: "A cascade of heavy water that batters a foe without mercy." }), Object.freeze({ id: SpellId.maelstrom, name: "Maelstrom", description: "A whirling abyss of water that pulls and pounds a single enemy." }) ]) }), Object.freeze({ element: MagicElement.air, spells: Object.freeze([ Object.freeze({ id: SpellId.airbolt, name: "Airbolt", description: "A compressed dart of wind that cuts the air toward a foe." }), Object.freeze({ id: SpellId.gale, name: "Gale", description: "A violent gust that slams into a mark with sudden force." }), Object.freeze({ id: SpellId.cyclone, name: "Cyclone", description: "A spinning funnel of air that tears at whatever it catches." }), Object.freeze({ id: SpellId.tempest, name: "Tempest", description: "A howling blast that batters a foe with storm-born fury." }), Object.freeze({ id: SpellId.hurricane, name: "Hurricane", description: "The full wrath of the sky, focused into one devastating strike." }) ]) }), Object.freeze({ element: MagicElement.earth, spells: Object.freeze([ Object.freeze({ id: SpellId.earthbolt, name: "Earthbolt", description: "A shard of stone flung hard enough to crack bone." }), Object.freeze({ id: SpellId.boulder, name: "Boulder", description: "A mass of rock that crashes into a foe with crushing weight." }), Object.freeze({ id: SpellId.quake, name: "Quake", description: "The ground itself heaves beneath a mark, shaking them to pieces." }), Object.freeze({ id: SpellId.landslide, name: "Landslide", description: "A surge of earth and rubble that buries a single enemy." }), Object.freeze({ id: SpellId.cataclysm, name: "Cataclysm", description: "The deepest earth answers, shattering stone and foe alike." }) ]) }), Object.freeze({ element: MagicElement.light, spells: Object.freeze([ Object.freeze({ id: SpellId.lightbolt, name: "Lightbolt", description: "A bright lance of radiance that burns where it lands." }), Object.freeze({ id: SpellId.radiance, name: "Radiance", description: "A flare of pure light that sears a foe in a white flash." }), Object.freeze({ id: SpellId.flare, name: "Flare", description: "A brilliant burst that blinds and burns in the same breath." }), Object.freeze({ id: SpellId.sunbeam, name: "Sunbeam", description: "A column of daylight called down upon a single mark." }), Object.freeze({ id: SpellId.judgment, name: "Judgment", description: "The fiercest light, pitiless and absolute, cast upon one enemy." }) ]) }), Object.freeze({ element: MagicElement.dark, spells: Object.freeze([ Object.freeze({ id: SpellId.darkbolt, name: "Darkbolt", description: "A bolt of shadow that bites colder than steel." }), Object.freeze({ id: SpellId.gloom, name: "Gloom", description: "A smothering cloud of dark that clings to a foe and drains them." }), Object.freeze({ id: SpellId.voidlance, name: "Voidlance", description: "A spear of emptiness that pierces flesh and spirit alike." }), Object.freeze({ id: SpellId.eclipse, name: "Eclipse", description: "A sudden night falls on one mark, crushing them in shadow." }), Object.freeze({ id: SpellId.oblivion, name: "Oblivion", description: "The deepest dark, called to unmake a single enemy." }) ]) }), Object.freeze({ element: MagicElement.poison, spells: Object.freeze([ Object.freeze({ id: SpellId.poisonbolt, name: "Poisonbolt", description: "A green-tinged dart that strikes with toxic force." }), Object.freeze({ id: SpellId.toxinburst, name: "Toxinburst", description: "A burst of virulent fluid that spatters a foe on impact." }), Object.freeze({ id: SpellId.venomcloud, name: "Venomcloud", description: "A choking haze of venom that settles on a single mark." }), Object.freeze({ id: SpellId.plague, name: "Plague", description: "A virulent curse that hammers a foe with sickening power." }), Object.freeze({ id: SpellId.blight, name: "Blight", description: "The foulest poison, concentrated into one merciless strike." }) ]) }) ]); /** * Minimum Magic skill to cast a spell of this tier — same 7-gate curve as gear * (1 / 10 / 20 / 35 / 50 / 70 / 90). * @param {number} tier */ export function spellMinMagicLevelFromTier (tier) { const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1))); return tierMinSkillLevel(MATERIAL_TIER_ORDER[rank - 1]); } /** * Authoritative Magic level gate for a spell def (explicit min or tier curve). * @param {SpellDefinition|null|undefined} spellDef */ export function spellMinMagicLevel (spellDef) { if (spellDef?.minMagicLevel != null) { return Math.max(1, spellDef.minMagicLevel | 0); } return spellMinMagicLevelFromTier(spellDef?.tier ?? 1); } function buildDamageTreeDefinitions () { const out = {}; for (const tree of ELEMENT_DAMAGE_TREES) { tree.spells.forEach((entry, index) => { const tier = 3 + index; out[entry.id] = Object.freeze({ spellId: entry.id, displayName: entry.name, tier, element: tree.element, target: "entity", autoRepeat: true, minMagicLevel: spellMinMagicLevelFromTier(tier), projectileSprite: BOLT_PROJECTILE, effect: "damage", damageTree: true, description: entry.description }); }); } return out; } /** @type {Record} */ export const SPELL_DEFINITIONS = Object.freeze({ [SpellId.light]: Object.freeze({ spellId: SpellId.light, displayName: "Light", tier: 1, element: "none", target: "tile", autoRepeat: false, minMagicLevel: spellMinMagicLevelFromTier(1), starter: true, projectileSprite: LIGHT_PROJECTILE, effect: "light", description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while." }), [SpellId.manaBullet]: Object.freeze({ spellId: SpellId.manaBullet, displayName: "Mana Bullet", tier: 1, element: "none", target: "entity", autoRepeat: true, minMagicLevel: spellMinMagicLevelFromTier(1), projectileSprite: BOLT_PROJECTILE, effect: "damage", description: "A small shot of raw mana, swift and simple, for those just learning to strike." }), [SpellId.dark]: Object.freeze({ spellId: SpellId.dark, displayName: "Dark", tier: 2, element: MagicElement.dark, target: "tile", autoRepeat: false, minMagicLevel: spellMinMagicLevelFromTier(2), projectileSprite: LIGHT_PROJECTILE, effect: "dark", description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim." }), [SpellId.magicMissile]: Object.freeze({ spellId: SpellId.magicMissile, displayName: "Magic Missile", tier: 2, element: "none", target: "entity", autoRepeat: true, minMagicLevel: spellMinMagicLevelFromTier(2), projectileSprite: BOLT_PROJECTILE, effect: "damage", description: "A plain dart of force that flies true and strikes without favour of the elements." }), ...buildDamageTreeDefinitions(), [SpellId.poison]: Object.freeze({ spellId: SpellId.poison, displayName: "Poison", tier: 3, element: MagicElement.earth, target: "entity", autoRepeat: true, minMagicLevel: spellMinMagicLevelFromTier(3), projectileSprite: BOLT_PROJECTILE, effect: "poison", description: "A venomous curse that sinks in without a wound, then eats at the body over time." }), [SpellId.drain]: Object.freeze({ spellId: SpellId.drain, displayName: "Drain", tier: 4, element: MagicElement.dark, target: "entity", autoRepeat: true, minMagicLevel: spellMinMagicLevelFromTier(4), projectileSprite: LIGHT_PROJECTILE, effect: "drain", description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover." }), [SpellId.tinders]: Object.freeze({ spellId: SpellId.tinders, displayName: "Tinders", tier: 3, element: MagicElement.fire, target: "tile", autoRepeat: false, minMagicLevel: spellMinMagicLevelFromTier(3), projectileSprite: BOLT_PROJECTILE, effect: "tinders", description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would." }), [SpellId.shade]: Object.freeze({ spellId: SpellId.shade, displayName: "Shade", tier: 6, element: MagicElement.dark, target: "tile", autoRepeat: false, minMagicLevel: spellMinMagicLevelFromTier(6), projectileSprite: LIGHT_PROJECTILE, effect: "shade", description: "A summoned shadow that fights beside you until the magic frays." }), [SpellId.revitalize]: Object.freeze({ spellId: SpellId.revitalize, displayName: "Revitalize", tier: 5, element: "holy", target: "entity", autoRepeat: false, minMagicLevel: spellMinMagicLevelFromTier(5), projectileSprite: LIGHT_PROJECTILE, effect: "revitalize", description: "A gentle current of life that mends wounds one breath at a time." }), [SpellId.spriteBoltFire]: spriteBoltDef(SpellId.spriteBoltFire, "Fire spark", MagicElement.fire), [SpellId.spriteBoltWater]: spriteBoltDef(SpellId.spriteBoltWater, "Water spark", MagicElement.water), [SpellId.spriteBoltAir]: spriteBoltDef(SpellId.spriteBoltAir, "Air spark", MagicElement.air), [SpellId.spriteBoltEarth]: spriteBoltDef(SpellId.spriteBoltEarth, "Earth spark", MagicElement.earth), [SpellId.spriteBoltLight]: spriteBoltDef(SpellId.spriteBoltLight, "Light spark", MagicElement.light), [SpellId.spriteBoltDark]: spriteBoltDef(SpellId.spriteBoltDark, "Dark spark", MagicElement.dark), [SpellId.spriteBoltPoison]: spriteBoltDef(SpellId.spriteBoltPoison, "Poison spark", MagicElement.poison) }); function spriteBoltDef (spellId, displayName, element) { return Object.freeze({ spellId, displayName, tier: 2, element, target: "entity", autoRepeat: true, minMagicLevel: 1, projectileSprite: BOLT_PROJECTILE, effect: "damage", mobOnly: true, description: `A flickering ${element} mote cast by a sprite.` }); } export const SPRITE_BOLT_SPELL_BY_ELEMENT = Object.freeze({ [MagicElement.fire]: SpellId.spriteBoltFire, [MagicElement.water]: SpellId.spriteBoltWater, [MagicElement.air]: SpellId.spriteBoltAir, [MagicElement.earth]: SpellId.spriteBoltEarth, [MagicElement.light]: SpellId.spriteBoltLight, [MagicElement.dark]: SpellId.spriteBoltDark, [MagicElement.poison]: SpellId.spriteBoltPoison }); /** Damage-tree spell ids grouped by element (for UI / editors). */ export function damageTreeSpellIds (element = null) { const ids = []; for (const tree of ELEMENT_DAMAGE_TREES) { if (element && tree.element !== element) { continue; } for (const spell of tree.spells) { ids.push(spell.id); } } return ids; } export function spellDefinition (spellId) { return SPELL_DEFINITIONS[spellId] ?? null; } export function spellDifficulty (spellDef) { return spellDifficultyFromTier(spellDef?.tier ?? 1); } /** * Display Mind power rating for a spell tier (same numeric curve as gear tier bonuses). * @param {number} tier */ export function spellMindPowerFromTier (tier) { const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1))); return tierStatBonus(MATERIAL_TIER_ORDER[rank - 1]); } /** Spells that are not starter knowledge and need a spellbook to learn. */ export function learnableSpellIds () { return Object.values(SPELL_DEFINITIONS) .filter((def) => !def.starter && !def.mobOnly) .map((def) => def.spellId); }