| 1 | import { spellDifficultyFromTier } from "../spells/constants.js"; |
| 2 | import { MagicElement } from "./attackTypes.js"; |
| 3 | |
| 4 | /** |
| 5 | * @typedef {object} SpellDefinition |
| 6 | * @property {string} spellId |
| 7 | * @property {string} displayName |
| 8 | * @property {number} tier Spell tier (sets difficulty and cast flash radius) |
| 9 | * @property {import("../combat/magic.js").SpellElement} [element] |
| 10 | * @property {"tile"|"entity"} target |
| 11 | * @property {boolean} [autoRepeat] Auto-cast repeats while target stays in range |
| 12 | * @property {number} [minMagicLevel] Minimum Magic level to cast / favourite |
| 13 | * @property {string} description In-world spell description |
| 14 | * @property {string} [projectileSprite] fx:projectile:spell-* base name |
| 15 | * @property {string} [effect] Server impact kind (defaults to spellId) |
| 16 | * @property {boolean} [starter] Known by default; no spellbook required |
| 17 | * @property {boolean} [mobOnly] Not offered on player spellbooks |
| 18 | * @property {boolean} [damageTree] Part of an elemental damage progression |
| 19 | */ |
| 20 | |
| 21 | /** |
| 22 | * Elemental damage trees (tiers 3–7), plus utility / special spells. |
| 23 | * Legacy `spark` was removed — unknown ids are dropped on load/normalize. |
| 24 | */ |
| 25 | export const SpellId = Object.freeze({ |
| 26 | light: "light", |
| 27 | dark: "dark", |
| 28 | // Fire damage tree |
| 29 | firebolt: "firebolt", |
| 30 | fireball: "fireball", |
| 31 | blaze: "blaze", |
| 32 | inferno: "inferno", |
| 33 | hellfire: "hellfire", |
| 34 | // Water damage tree |
| 35 | waterbolt: "waterbolt", |
| 36 | waterspout: "waterspout", |
| 37 | torrent: "torrent", |
| 38 | deluge: "deluge", |
| 39 | maelstrom: "maelstrom", |
| 40 | // Air damage tree |
| 41 | airbolt: "airbolt", |
| 42 | gale: "gale", |
| 43 | cyclone: "cyclone", |
| 44 | tempest: "tempest", |
| 45 | hurricane: "hurricane", |
| 46 | // Earth damage tree |
| 47 | earthbolt: "earthbolt", |
| 48 | boulder: "boulder", |
| 49 | quake: "quake", |
| 50 | landslide: "landslide", |
| 51 | cataclysm: "cataclysm", |
| 52 | // Light damage tree |
| 53 | lightbolt: "lightbolt", |
| 54 | radiance: "radiance", |
| 55 | flare: "flare", |
| 56 | sunbeam: "sunbeam", |
| 57 | judgment: "judgment", |
| 58 | // Dark damage tree |
| 59 | darkbolt: "darkbolt", |
| 60 | gloom: "gloom", |
| 61 | voidlance: "voidlance", |
| 62 | eclipse: "eclipse", |
| 63 | oblivion: "oblivion", |
| 64 | // Poison damage tree |
| 65 | poisonbolt: "poisonbolt", |
| 66 | toxinburst: "toxinburst", |
| 67 | venomcloud: "venomcloud", |
| 68 | plague: "plague", |
| 69 | blight: "blight", |
| 70 | // Utility / special |
| 71 | poison: "poison", |
| 72 | drain: "drain", |
| 73 | tinders: "tinders", |
| 74 | shade: "shade", |
| 75 | revitalize: "revitalize", |
| 76 | /** Sprite elemental bolts (mob-only; not player spellbooks). */ |
| 77 | spriteBoltFire: "sprite-bolt-fire", |
| 78 | spriteBoltWater: "sprite-bolt-water", |
| 79 | spriteBoltAir: "sprite-bolt-air", |
| 80 | spriteBoltEarth: "sprite-bolt-earth", |
| 81 | spriteBoltLight: "sprite-bolt-light", |
| 82 | spriteBoltDark: "sprite-bolt-dark", |
| 83 | spriteBoltPoison: "sprite-bolt-poison" |
| 84 | }); |
| 85 | |
| 86 | /** Shared projectile art for damage bolts (tinted by element on cast later if needed). */ |
| 87 | const BOLT_PROJECTILE = "fx:projectile:spell-spark"; |
| 88 | const LIGHT_PROJECTILE = "fx:projectile:spell-light"; |
| 89 | |
| 90 | /** |
| 91 | * Damage progression per element — mirrors the fire ladder (tiers 3–7). |
| 92 | * @type {ReadonlyArray<{ element: string, spells: ReadonlyArray<{ id: string, name: string, description: string }> }>} |
| 93 | */ |
| 94 | const ELEMENT_DAMAGE_TREES = Object.freeze([ |
| 95 | Object.freeze({ |
| 96 | element: MagicElement.fire, |
| 97 | spells: Object.freeze([ |
| 98 | Object.freeze({ |
| 99 | id: SpellId.firebolt, |
| 100 | name: "Firebolt", |
| 101 | description: "A fierce bolt of fire that streaks toward a foe and scorches on impact." |
| 102 | }), |
| 103 | Object.freeze({ |
| 104 | id: SpellId.fireball, |
| 105 | name: "Fireball", |
| 106 | description: "A roaring sphere of flame that bursts against whatever it strikes." |
| 107 | }), |
| 108 | Object.freeze({ |
| 109 | id: SpellId.blaze, |
| 110 | name: "Blaze", |
| 111 | description: "A searing tongue of fire that clings to flesh and armour alike." |
| 112 | }), |
| 113 | Object.freeze({ |
| 114 | id: SpellId.inferno, |
| 115 | name: "Inferno", |
| 116 | description: "A storm of fire that overwhelms a foe in a rush of heat and ash." |
| 117 | }), |
| 118 | Object.freeze({ |
| 119 | id: SpellId.hellfire, |
| 120 | name: "Hellfire", |
| 121 | description: "The deepest flame, white-hot and merciless, called down upon a single mark." |
| 122 | }) |
| 123 | ]) |
| 124 | }), |
| 125 | Object.freeze({ |
| 126 | element: MagicElement.water, |
| 127 | spells: Object.freeze([ |
| 128 | Object.freeze({ |
| 129 | id: SpellId.waterbolt, |
| 130 | name: "Waterbolt", |
| 131 | description: "A hard lance of water that strikes like a thrown spear." |
| 132 | }), |
| 133 | Object.freeze({ |
| 134 | id: SpellId.waterspout, |
| 135 | name: "Waterspout", |
| 136 | description: "A rising column of water that hammers a foe from below." |
| 137 | }), |
| 138 | Object.freeze({ |
| 139 | id: SpellId.torrent, |
| 140 | name: "Torrent", |
| 141 | description: "A rushing flood aimed at one mark, crushing and cold." |
| 142 | }), |
| 143 | Object.freeze({ |
| 144 | id: SpellId.deluge, |
| 145 | name: "Deluge", |
| 146 | description: "A cascade of heavy water that batters a foe without mercy." |
| 147 | }), |
| 148 | Object.freeze({ |
| 149 | id: SpellId.maelstrom, |
| 150 | name: "Maelstrom", |
| 151 | description: "A whirling abyss of water that pulls and pounds a single enemy." |
| 152 | }) |
| 153 | ]) |
| 154 | }), |
| 155 | Object.freeze({ |
| 156 | element: MagicElement.air, |
| 157 | spells: Object.freeze([ |
| 158 | Object.freeze({ |
| 159 | id: SpellId.airbolt, |
| 160 | name: "Airbolt", |
| 161 | description: "A compressed dart of wind that cuts the air toward a foe." |
| 162 | }), |
| 163 | Object.freeze({ |
| 164 | id: SpellId.gale, |
| 165 | name: "Gale", |
| 166 | description: "A violent gust that slams into a mark with sudden force." |
| 167 | }), |
| 168 | Object.freeze({ |
| 169 | id: SpellId.cyclone, |
| 170 | name: "Cyclone", |
| 171 | description: "A spinning funnel of air that tears at whatever it catches." |
| 172 | }), |
| 173 | Object.freeze({ |
| 174 | id: SpellId.tempest, |
| 175 | name: "Tempest", |
| 176 | description: "A howling blast that batters a foe with storm-born fury." |
| 177 | }), |
| 178 | Object.freeze({ |
| 179 | id: SpellId.hurricane, |
| 180 | name: "Hurricane", |
| 181 | description: "The full wrath of the sky, focused into one devastating strike." |
| 182 | }) |
| 183 | ]) |
| 184 | }), |
| 185 | Object.freeze({ |
| 186 | element: MagicElement.earth, |
| 187 | spells: Object.freeze([ |
| 188 | Object.freeze({ |
| 189 | id: SpellId.earthbolt, |
| 190 | name: "Earthbolt", |
| 191 | description: "A shard of stone flung hard enough to crack bone." |
| 192 | }), |
| 193 | Object.freeze({ |
| 194 | id: SpellId.boulder, |
| 195 | name: "Boulder", |
| 196 | description: "A mass of rock that crashes into a foe with crushing weight." |
| 197 | }), |
| 198 | Object.freeze({ |
| 199 | id: SpellId.quake, |
| 200 | name: "Quake", |
| 201 | description: "The ground itself heaves beneath a mark, shaking them to pieces." |
| 202 | }), |
| 203 | Object.freeze({ |
| 204 | id: SpellId.landslide, |
| 205 | name: "Landslide", |
| 206 | description: "A surge of earth and rubble that buries a single enemy." |
| 207 | }), |
| 208 | Object.freeze({ |
| 209 | id: SpellId.cataclysm, |
| 210 | name: "Cataclysm", |
| 211 | description: "The deepest earth answers, shattering stone and foe alike." |
| 212 | }) |
| 213 | ]) |
| 214 | }), |
| 215 | Object.freeze({ |
| 216 | element: MagicElement.light, |
| 217 | spells: Object.freeze([ |
| 218 | Object.freeze({ |
| 219 | id: SpellId.lightbolt, |
| 220 | name: "Lightbolt", |
| 221 | description: "A bright lance of radiance that burns where it lands." |
| 222 | }), |
| 223 | Object.freeze({ |
| 224 | id: SpellId.radiance, |
| 225 | name: "Radiance", |
| 226 | description: "A flare of pure light that sears a foe in a white flash." |
| 227 | }), |
| 228 | Object.freeze({ |
| 229 | id: SpellId.flare, |
| 230 | name: "Flare", |
| 231 | description: "A brilliant burst that blinds and burns in the same breath." |
| 232 | }), |
| 233 | Object.freeze({ |
| 234 | id: SpellId.sunbeam, |
| 235 | name: "Sunbeam", |
| 236 | description: "A column of daylight called down upon a single mark." |
| 237 | }), |
| 238 | Object.freeze({ |
| 239 | id: SpellId.judgment, |
| 240 | name: "Judgment", |
| 241 | description: "The fiercest light, pitiless and absolute, cast upon one enemy." |
| 242 | }) |
| 243 | ]) |
| 244 | }), |
| 245 | Object.freeze({ |
| 246 | element: MagicElement.dark, |
| 247 | spells: Object.freeze([ |
| 248 | Object.freeze({ |
| 249 | id: SpellId.darkbolt, |
| 250 | name: "Darkbolt", |
| 251 | description: "A bolt of shadow that bites colder than steel." |
| 252 | }), |
| 253 | Object.freeze({ |
| 254 | id: SpellId.gloom, |
| 255 | name: "Gloom", |
| 256 | description: "A smothering cloud of dark that clings to a foe and drains them." |
| 257 | }), |
| 258 | Object.freeze({ |
| 259 | id: SpellId.voidlance, |
| 260 | name: "Voidlance", |
| 261 | description: "A spear of emptiness that pierces flesh and spirit alike." |
| 262 | }), |
| 263 | Object.freeze({ |
| 264 | id: SpellId.eclipse, |
| 265 | name: "Eclipse", |
| 266 | description: "A sudden night falls on one mark, crushing them in shadow." |
| 267 | }), |
| 268 | Object.freeze({ |
| 269 | id: SpellId.oblivion, |
| 270 | name: "Oblivion", |
| 271 | description: "The deepest dark, called to unmake a single enemy." |
| 272 | }) |
| 273 | ]) |
| 274 | }), |
| 275 | Object.freeze({ |
| 276 | element: MagicElement.poison, |
| 277 | spells: Object.freeze([ |
| 278 | Object.freeze({ |
| 279 | id: SpellId.poisonbolt, |
| 280 | name: "Poisonbolt", |
| 281 | description: "A green-tinged dart that strikes with toxic force." |
| 282 | }), |
| 283 | Object.freeze({ |
| 284 | id: SpellId.toxinburst, |
| 285 | name: "Toxinburst", |
| 286 | description: "A burst of virulent fluid that spatters a foe on impact." |
| 287 | }), |
| 288 | Object.freeze({ |
| 289 | id: SpellId.venomcloud, |
| 290 | name: "Venomcloud", |
| 291 | description: "A choking haze of venom that settles on a single mark." |
| 292 | }), |
| 293 | Object.freeze({ |
| 294 | id: SpellId.plague, |
| 295 | name: "Plague", |
| 296 | description: "A virulent curse that hammers a foe with sickening power." |
| 297 | }), |
| 298 | Object.freeze({ |
| 299 | id: SpellId.blight, |
| 300 | name: "Blight", |
| 301 | description: "The foulest poison, concentrated into one merciless strike." |
| 302 | }) |
| 303 | ]) |
| 304 | }) |
| 305 | ]); |
| 306 | |
| 307 | function buildDamageTreeDefinitions () |
| 308 | { |
| 309 | const out = {}; |
| 310 | for (const tree of ELEMENT_DAMAGE_TREES) |
| 311 | { |
| 312 | tree.spells.forEach((entry, index) => |
| 313 | { |
| 314 | const tier = 3 + index; |
| 315 | out[entry.id] = Object.freeze({ |
| 316 | spellId: entry.id, |
| 317 | displayName: entry.name, |
| 318 | tier, |
| 319 | element: tree.element, |
| 320 | target: "entity", |
| 321 | autoRepeat: true, |
| 322 | minMagicLevel: tier, |
| 323 | projectileSprite: BOLT_PROJECTILE, |
| 324 | effect: "damage", |
| 325 | damageTree: true, |
| 326 | description: entry.description |
| 327 | }); |
| 328 | }); |
| 329 | } |
| 330 | return out; |
| 331 | } |
| 332 | |
| 333 | /** @type {Record<string, SpellDefinition>} */ |
| 334 | export const SPELL_DEFINITIONS = Object.freeze({ |
| 335 | [SpellId.light]: Object.freeze({ |
| 336 | spellId: SpellId.light, |
| 337 | displayName: "Light", |
| 338 | tier: 1, |
| 339 | element: "none", |
| 340 | target: "tile", |
| 341 | autoRepeat: false, |
| 342 | minMagicLevel: 1, |
| 343 | starter: true, |
| 344 | projectileSprite: LIGHT_PROJECTILE, |
| 345 | effect: "light", |
| 346 | description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while." |
| 347 | }), |
| 348 | [SpellId.dark]: Object.freeze({ |
| 349 | spellId: SpellId.dark, |
| 350 | displayName: "Dark", |
| 351 | tier: 2, |
| 352 | element: MagicElement.dark, |
| 353 | target: "tile", |
| 354 | autoRepeat: false, |
| 355 | minMagicLevel: 2, |
| 356 | projectileSprite: LIGHT_PROJECTILE, |
| 357 | effect: "dark", |
| 358 | description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim." |
| 359 | }), |
| 360 | ...buildDamageTreeDefinitions(), |
| 361 | [SpellId.poison]: Object.freeze({ |
| 362 | spellId: SpellId.poison, |
| 363 | displayName: "Poison", |
| 364 | tier: 3, |
| 365 | element: MagicElement.earth, |
| 366 | target: "entity", |
| 367 | autoRepeat: true, |
| 368 | minMagicLevel: 3, |
| 369 | projectileSprite: BOLT_PROJECTILE, |
| 370 | effect: "poison", |
| 371 | description: "A venomous curse that sinks in without a wound, then eats at the body over time." |
| 372 | }), |
| 373 | [SpellId.drain]: Object.freeze({ |
| 374 | spellId: SpellId.drain, |
| 375 | displayName: "Drain", |
| 376 | tier: 4, |
| 377 | element: MagicElement.dark, |
| 378 | target: "entity", |
| 379 | autoRepeat: true, |
| 380 | minMagicLevel: 4, |
| 381 | projectileSprite: LIGHT_PROJECTILE, |
| 382 | effect: "drain", |
| 383 | description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover." |
| 384 | }), |
| 385 | [SpellId.tinders]: Object.freeze({ |
| 386 | spellId: SpellId.tinders, |
| 387 | displayName: "Tinders", |
| 388 | tier: 3, |
| 389 | element: MagicElement.fire, |
| 390 | target: "tile", |
| 391 | autoRepeat: false, |
| 392 | minMagicLevel: 3, |
| 393 | projectileSprite: BOLT_PROJECTILE, |
| 394 | effect: "tinders", |
| 395 | description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would." |
| 396 | }), |
| 397 | [SpellId.shade]: Object.freeze({ |
| 398 | spellId: SpellId.shade, |
| 399 | displayName: "Shade", |
| 400 | tier: 6, |
| 401 | element: MagicElement.dark, |
| 402 | target: "tile", |
| 403 | autoRepeat: false, |
| 404 | minMagicLevel: 6, |
| 405 | projectileSprite: LIGHT_PROJECTILE, |
| 406 | effect: "shade", |
| 407 | description: "A summoned shadow that fights beside you until the magic frays." |
| 408 | }), |
| 409 | [SpellId.revitalize]: Object.freeze({ |
| 410 | spellId: SpellId.revitalize, |
| 411 | displayName: "Revitalize", |
| 412 | tier: 5, |
| 413 | element: "holy", |
| 414 | target: "entity", |
| 415 | autoRepeat: false, |
| 416 | minMagicLevel: 5, |
| 417 | projectileSprite: LIGHT_PROJECTILE, |
| 418 | effect: "revitalize", |
| 419 | description: "A gentle current of life that mends wounds one breath at a time." |
| 420 | }), |
| 421 | [SpellId.spriteBoltFire]: spriteBoltDef(SpellId.spriteBoltFire, "Fire spark", MagicElement.fire), |
| 422 | [SpellId.spriteBoltWater]: spriteBoltDef(SpellId.spriteBoltWater, "Water spark", MagicElement.water), |
| 423 | [SpellId.spriteBoltAir]: spriteBoltDef(SpellId.spriteBoltAir, "Air spark", MagicElement.air), |
| 424 | [SpellId.spriteBoltEarth]: spriteBoltDef(SpellId.spriteBoltEarth, "Earth spark", MagicElement.earth), |
| 425 | [SpellId.spriteBoltLight]: spriteBoltDef(SpellId.spriteBoltLight, "Light spark", MagicElement.light), |
| 426 | [SpellId.spriteBoltDark]: spriteBoltDef(SpellId.spriteBoltDark, "Dark spark", MagicElement.dark), |
| 427 | [SpellId.spriteBoltPoison]: spriteBoltDef(SpellId.spriteBoltPoison, "Poison spark", MagicElement.poison) |
| 428 | }); |
| 429 | |
| 430 | function spriteBoltDef (spellId, displayName, element) |
| 431 | { |
| 432 | return Object.freeze({ |
| 433 | spellId, |
| 434 | displayName, |
| 435 | tier: 2, |
| 436 | element, |
| 437 | target: "entity", |
| 438 | autoRepeat: true, |
| 439 | minMagicLevel: 1, |
| 440 | projectileSprite: BOLT_PROJECTILE, |
| 441 | effect: "damage", |
| 442 | mobOnly: true, |
| 443 | description: `A flickering ${element} mote cast by a sprite.` |
| 444 | }); |
| 445 | } |
| 446 | |
| 447 | export const SPRITE_BOLT_SPELL_BY_ELEMENT = Object.freeze({ |
| 448 | [MagicElement.fire]: SpellId.spriteBoltFire, |
| 449 | [MagicElement.water]: SpellId.spriteBoltWater, |
| 450 | [MagicElement.air]: SpellId.spriteBoltAir, |
| 451 | [MagicElement.earth]: SpellId.spriteBoltEarth, |
| 452 | [MagicElement.light]: SpellId.spriteBoltLight, |
| 453 | [MagicElement.dark]: SpellId.spriteBoltDark, |
| 454 | [MagicElement.poison]: SpellId.spriteBoltPoison |
| 455 | }); |
| 456 | |
| 457 | /** Damage-tree spell ids grouped by element (for UI / editors). */ |
| 458 | export function damageTreeSpellIds (element = null) |
| 459 | { |
| 460 | const ids = []; |
| 461 | for (const tree of ELEMENT_DAMAGE_TREES) |
| 462 | { |
| 463 | if (element && tree.element !== element) |
| 464 | { continue; } |
| 465 | for (const spell of tree.spells) |
| 466 | { ids.push(spell.id); } |
| 467 | } |
| 468 | return ids; |
| 469 | } |
| 470 | |
| 471 | export function spellDefinition (spellId) |
| 472 | { |
| 473 | return SPELL_DEFINITIONS[spellId] ?? null; |
| 474 | } |
| 475 | |
| 476 | export function spellDifficulty (spellDef) |
| 477 | { |
| 478 | return spellDifficultyFromTier(spellDef?.tier ?? 1); |
| 479 | } |
| 480 | |
| 481 | /** Spells that are not starter knowledge and need a spellbook to learn. */ |
| 482 | export function learnableSpellIds () |
| 483 | { |
| 484 | return Object.values(SPELL_DEFINITIONS) |
| 485 | .filter((def) => !def.starter && !def.mobOnly) |
| 486 | .map((def) => def.spellId); |
| 487 | } |