| 1 | import { spellDifficultyFromTier } from "../spells/constants.js"; |
| 2 | |
| 3 | /** |
| 4 | * @typedef {object} SpellDefinition |
| 5 | * @property {string} spellId |
| 6 | * @property {string} displayName |
| 7 | * @property {number} tier Spell tier (sets difficulty and cast flash radius) |
| 8 | * @property {import("../combat/magic.js").SpellElement} [element] |
| 9 | * @property {"tile"|"entity"} target |
| 10 | * @property {boolean} [autoRepeat] Auto-cast repeats while target stays in range |
| 11 | * @property {number} [minMagicLevel] Minimum Magic level to cast / favourite |
| 12 | * @property {string} description In-world spell description |
| 13 | * @property {string} [projectileSprite] fx:projectile:spell-* base name |
| 14 | * @property {string} [effect] Server impact kind (defaults to spellId) |
| 15 | * @property {boolean} [starter] Known by default; no spellbook required |
| 16 | */ |
| 17 | |
| 18 | export const SpellId = Object.freeze({ |
| 19 | light: "light", |
| 20 | dark: "dark", |
| 21 | spark: "spark", |
| 22 | firebolt: "firebolt", |
| 23 | fireball: "fireball", |
| 24 | blaze: "blaze", |
| 25 | inferno: "inferno", |
| 26 | hellfire: "hellfire", |
| 27 | poison: "poison", |
| 28 | drain: "drain", |
| 29 | tinders: "tinders", |
| 30 | shade: "shade", |
| 31 | revitalize: "revitalize" |
| 32 | }); |
| 33 | |
| 34 | /** @type {Record<string, SpellDefinition>} */ |
| 35 | export const SPELL_DEFINITIONS = Object.freeze({ |
| 36 | [SpellId.light]: Object.freeze({ |
| 37 | spellId: SpellId.light, |
| 38 | displayName: "Light", |
| 39 | tier: 1, |
| 40 | element: "none", |
| 41 | target: "tile", |
| 42 | autoRepeat: false, |
| 43 | minMagicLevel: 1, |
| 44 | starter: true, |
| 45 | projectileSprite: "fx:projectile:spell-light", |
| 46 | effect: "light", |
| 47 | description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while." |
| 48 | }), |
| 49 | [SpellId.dark]: Object.freeze({ |
| 50 | spellId: SpellId.dark, |
| 51 | displayName: "Dark", |
| 52 | tier: 2, |
| 53 | element: "dark", |
| 54 | target: "tile", |
| 55 | autoRepeat: false, |
| 56 | minMagicLevel: 2, |
| 57 | projectileSprite: "fx:projectile:spell-light", |
| 58 | effect: "dark", |
| 59 | description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim." |
| 60 | }), |
| 61 | [SpellId.spark]: Object.freeze({ |
| 62 | spellId: SpellId.spark, |
| 63 | displayName: "Spark", |
| 64 | tier: 2, |
| 65 | element: "fire", |
| 66 | target: "entity", |
| 67 | autoRepeat: true, |
| 68 | minMagicLevel: 2, |
| 69 | projectileSprite: "fx:projectile:spell-spark", |
| 70 | effect: "damage", |
| 71 | description: "A snapping mote of flame that leaps at a foe and bites on arrival." |
| 72 | }), |
| 73 | [SpellId.firebolt]: Object.freeze({ |
| 74 | spellId: SpellId.firebolt, |
| 75 | displayName: "Firebolt", |
| 76 | tier: 3, |
| 77 | element: "fire", |
| 78 | target: "entity", |
| 79 | autoRepeat: true, |
| 80 | minMagicLevel: 3, |
| 81 | projectileSprite: "fx:projectile:spell-spark", |
| 82 | effect: "damage", |
| 83 | description: "A fierce bolt of fire that streaks toward a foe and scorches on impact." |
| 84 | }), |
| 85 | [SpellId.fireball]: Object.freeze({ |
| 86 | spellId: SpellId.fireball, |
| 87 | displayName: "Fireball", |
| 88 | tier: 4, |
| 89 | element: "fire", |
| 90 | target: "entity", |
| 91 | autoRepeat: true, |
| 92 | minMagicLevel: 4, |
| 93 | projectileSprite: "fx:projectile:spell-spark", |
| 94 | effect: "damage", |
| 95 | description: "A roaring sphere of flame that bursts against whatever it strikes." |
| 96 | }), |
| 97 | [SpellId.blaze]: Object.freeze({ |
| 98 | spellId: SpellId.blaze, |
| 99 | displayName: "Blaze", |
| 100 | tier: 5, |
| 101 | element: "fire", |
| 102 | target: "entity", |
| 103 | autoRepeat: true, |
| 104 | minMagicLevel: 5, |
| 105 | projectileSprite: "fx:projectile:spell-spark", |
| 106 | effect: "damage", |
| 107 | description: "A searing tongue of fire that clings to flesh and armour alike." |
| 108 | }), |
| 109 | [SpellId.inferno]: Object.freeze({ |
| 110 | spellId: SpellId.inferno, |
| 111 | displayName: "Inferno", |
| 112 | tier: 6, |
| 113 | element: "fire", |
| 114 | target: "entity", |
| 115 | autoRepeat: true, |
| 116 | minMagicLevel: 6, |
| 117 | projectileSprite: "fx:projectile:spell-spark", |
| 118 | effect: "damage", |
| 119 | description: "A storm of fire that overwhelms a foe in a rush of heat and ash." |
| 120 | }), |
| 121 | [SpellId.hellfire]: Object.freeze({ |
| 122 | spellId: SpellId.hellfire, |
| 123 | displayName: "Hellfire", |
| 124 | tier: 7, |
| 125 | element: "fire", |
| 126 | target: "entity", |
| 127 | autoRepeat: true, |
| 128 | minMagicLevel: 7, |
| 129 | projectileSprite: "fx:projectile:spell-spark", |
| 130 | effect: "damage", |
| 131 | description: "The deepest flame, white-hot and merciless, called down upon a single mark." |
| 132 | }), |
| 133 | [SpellId.poison]: Object.freeze({ |
| 134 | spellId: SpellId.poison, |
| 135 | displayName: "Poison", |
| 136 | tier: 3, |
| 137 | element: "earth", |
| 138 | target: "entity", |
| 139 | autoRepeat: true, |
| 140 | minMagicLevel: 3, |
| 141 | projectileSprite: "fx:projectile:spell-spark", |
| 142 | effect: "poison", |
| 143 | description: "A venomous curse that sinks in without a wound, then eats at the body over time." |
| 144 | }), |
| 145 | [SpellId.drain]: Object.freeze({ |
| 146 | spellId: SpellId.drain, |
| 147 | displayName: "Drain", |
| 148 | tier: 4, |
| 149 | element: "dark", |
| 150 | target: "entity", |
| 151 | autoRepeat: true, |
| 152 | minMagicLevel: 4, |
| 153 | projectileSprite: "fx:projectile:spell-light", |
| 154 | effect: "drain", |
| 155 | description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover." |
| 156 | }), |
| 157 | [SpellId.tinders]: Object.freeze({ |
| 158 | spellId: SpellId.tinders, |
| 159 | displayName: "Tinders", |
| 160 | tier: 3, |
| 161 | element: "fire", |
| 162 | target: "tile", |
| 163 | autoRepeat: false, |
| 164 | minMagicLevel: 3, |
| 165 | projectileSprite: "fx:projectile:spell-spark", |
| 166 | effect: "tinders", |
| 167 | description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would." |
| 168 | }), |
| 169 | [SpellId.shade]: Object.freeze({ |
| 170 | spellId: SpellId.shade, |
| 171 | displayName: "Shade", |
| 172 | tier: 6, |
| 173 | element: "dark", |
| 174 | target: "tile", |
| 175 | autoRepeat: false, |
| 176 | minMagicLevel: 6, |
| 177 | projectileSprite: "fx:projectile:spell-light", |
| 178 | effect: "shade", |
| 179 | description: "A summoned shadow that fights beside you until the magic frays." |
| 180 | }), |
| 181 | [SpellId.revitalize]: Object.freeze({ |
| 182 | spellId: SpellId.revitalize, |
| 183 | displayName: "Revitalize", |
| 184 | tier: 5, |
| 185 | element: "holy", |
| 186 | target: "entity", |
| 187 | autoRepeat: false, |
| 188 | minMagicLevel: 5, |
| 189 | projectileSprite: "fx:projectile:spell-light", |
| 190 | effect: "revitalize", |
| 191 | description: "A gentle current of life that mends wounds one breath at a time." |
| 192 | }) |
| 193 | }); |
| 194 | |
| 195 | export function spellDefinition (spellId) |
| 196 | { |
| 197 | return SPELL_DEFINITIONS[spellId] ?? null; |
| 198 | } |
| 199 | |
| 200 | export function spellDifficulty (spellDef) |
| 201 | { |
| 202 | return spellDifficultyFromTier(spellDef?.tier ?? 1); |
| 203 | } |
| 204 | |
| 205 | /** Spells that are not starter knowledge and need a spellbook to learn. */ |
| 206 | export function learnableSpellIds () |
| 207 | { |
| 208 | return Object.values(SPELL_DEFINITIONS) |
| 209 | .filter((def) => !def.starter) |
| 210 | .map((def) => def.spellId); |
| 211 | } |