BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

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