BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

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