BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

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