BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

spells.js 15.2 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 // 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
308/**
309 * Minimum Magic skill to cast a spell of this tier — same 7-gate curve as gear
310 * (1 / 10 / 20 / 35 / 50 / 70 / 90).
311 * @param {number} tier
312 */
313export function spellMinMagicLevelFromTier (tier)
314{
315 const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1)));
316 return tierMinSkillLevel(MATERIAL_TIER_ORDER[rank - 1]);
317}
318
319/**
320 * Authoritative Magic level gate for a spell def (explicit min or tier curve).
321 * @param {SpellDefinition|null|undefined} spellDef
322 */
323export function spellMinMagicLevel (spellDef)
324{
325 if (spellDef?.minMagicLevel != null)
326 { return Math.max(1, spellDef.minMagicLevel | 0); }
327 return spellMinMagicLevelFromTier(spellDef?.tier ?? 1);
328}
329
330function buildDamageTreeDefinitions ()
331{
332 const out = {};
333 for (const tree of ELEMENT_DAMAGE_TREES)
334 {
335 tree.spells.forEach((entry, index) =>
336 {
337 const tier = 3 + index;
338 out[entry.id] = Object.freeze({
339 spellId: entry.id,
340 displayName: entry.name,
341 tier,
342 element: tree.element,
343 target: "entity",
344 autoRepeat: true,
345 minMagicLevel: spellMinMagicLevelFromTier(tier),
346 projectileSprite: BOLT_PROJECTILE,
347 effect: "damage",
348 damageTree: true,
349 description: entry.description
350 });
351 });
352 }
353 return out;
354}
355
356/** @type {Record<string, SpellDefinition>} */
357export const SPELL_DEFINITIONS = Object.freeze({
358 [SpellId.light]: Object.freeze({
359 spellId: SpellId.light,
360 displayName: "Light",
361 tier: 1,
362 element: "none",
363 target: "tile",
364 autoRepeat: false,
365 minMagicLevel: spellMinMagicLevelFromTier(1),
366 starter: true,
367 projectileSprite: LIGHT_PROJECTILE,
368 effect: "light",
369 description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while."
370 }),
371 [SpellId.dark]: Object.freeze({
372 spellId: SpellId.dark,
373 displayName: "Dark",
374 tier: 2,
375 element: MagicElement.dark,
376 target: "tile",
377 autoRepeat: false,
378 minMagicLevel: spellMinMagicLevelFromTier(2),
379 projectileSprite: LIGHT_PROJECTILE,
380 effect: "dark",
381 description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim."
382 }),
383 ...buildDamageTreeDefinitions(),
384 [SpellId.poison]: Object.freeze({
385 spellId: SpellId.poison,
386 displayName: "Poison",
387 tier: 3,
388 element: MagicElement.earth,
389 target: "entity",
390 autoRepeat: true,
391 minMagicLevel: spellMinMagicLevelFromTier(3),
392 projectileSprite: BOLT_PROJECTILE,
393 effect: "poison",
394 description: "A venomous curse that sinks in without a wound, then eats at the body over time."
395 }),
396 [SpellId.drain]: Object.freeze({
397 spellId: SpellId.drain,
398 displayName: "Drain",
399 tier: 4,
400 element: MagicElement.dark,
401 target: "entity",
402 autoRepeat: true,
403 minMagicLevel: spellMinMagicLevelFromTier(4),
404 projectileSprite: LIGHT_PROJECTILE,
405 effect: "drain",
406 description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover."
407 }),
408 [SpellId.tinders]: Object.freeze({
409 spellId: SpellId.tinders,
410 displayName: "Tinders",
411 tier: 3,
412 element: MagicElement.fire,
413 target: "tile",
414 autoRepeat: false,
415 minMagicLevel: spellMinMagicLevelFromTier(3),
416 projectileSprite: BOLT_PROJECTILE,
417 effect: "tinders",
418 description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would."
419 }),
420 [SpellId.shade]: Object.freeze({
421 spellId: SpellId.shade,
422 displayName: "Shade",
423 tier: 6,
424 element: MagicElement.dark,
425 target: "tile",
426 autoRepeat: false,
427 minMagicLevel: spellMinMagicLevelFromTier(6),
428 projectileSprite: LIGHT_PROJECTILE,
429 effect: "shade",
430 description: "A summoned shadow that fights beside you until the magic frays."
431 }),
432 [SpellId.revitalize]: Object.freeze({
433 spellId: SpellId.revitalize,
434 displayName: "Revitalize",
435 tier: 5,
436 element: "holy",
437 target: "entity",
438 autoRepeat: false,
439 minMagicLevel: spellMinMagicLevelFromTier(5),
440 projectileSprite: LIGHT_PROJECTILE,
441 effect: "revitalize",
442 description: "A gentle current of life that mends wounds one breath at a time."
443 }),
444 [SpellId.spriteBoltFire]: spriteBoltDef(SpellId.spriteBoltFire, "Fire spark", MagicElement.fire),
445 [SpellId.spriteBoltWater]: spriteBoltDef(SpellId.spriteBoltWater, "Water spark", MagicElement.water),
446 [SpellId.spriteBoltAir]: spriteBoltDef(SpellId.spriteBoltAir, "Air spark", MagicElement.air),
447 [SpellId.spriteBoltEarth]: spriteBoltDef(SpellId.spriteBoltEarth, "Earth spark", MagicElement.earth),
448 [SpellId.spriteBoltLight]: spriteBoltDef(SpellId.spriteBoltLight, "Light spark", MagicElement.light),
449 [SpellId.spriteBoltDark]: spriteBoltDef(SpellId.spriteBoltDark, "Dark spark", MagicElement.dark),
450 [SpellId.spriteBoltPoison]: spriteBoltDef(SpellId.spriteBoltPoison, "Poison spark", MagicElement.poison)
451});
452
453function spriteBoltDef (spellId, displayName, element)
454{
455 return Object.freeze({
456 spellId,
457 displayName,
458 tier: 2,
459 element,
460 target: "entity",
461 autoRepeat: true,
462 minMagicLevel: 1,
463 projectileSprite: BOLT_PROJECTILE,
464 effect: "damage",
465 mobOnly: true,
466 description: `A flickering ${element} mote cast by a sprite.`
467 });
468}
469
470export const SPRITE_BOLT_SPELL_BY_ELEMENT = Object.freeze({
471 [MagicElement.fire]: SpellId.spriteBoltFire,
472 [MagicElement.water]: SpellId.spriteBoltWater,
473 [MagicElement.air]: SpellId.spriteBoltAir,
474 [MagicElement.earth]: SpellId.spriteBoltEarth,
475 [MagicElement.light]: SpellId.spriteBoltLight,
476 [MagicElement.dark]: SpellId.spriteBoltDark,
477 [MagicElement.poison]: SpellId.spriteBoltPoison
478});
479
480/** Damage-tree spell ids grouped by element (for UI / editors). */
481export function damageTreeSpellIds (element = null)
482{
483 const ids = [];
484 for (const tree of ELEMENT_DAMAGE_TREES)
485 {
486 if (element && tree.element !== element)
487 { continue; }
488 for (const spell of tree.spells)
489 { ids.push(spell.id); }
490 }
491 return ids;
492}
493
494export function spellDefinition (spellId)
495{
496 return SPELL_DEFINITIONS[spellId] ?? null;
497}
498
499export function spellDifficulty (spellDef)
500{
501 return spellDifficultyFromTier(spellDef?.tier ?? 1);
502}
503
504/**
505 * Display Mind power rating for a spell tier (same numeric curve as gear tier bonuses).
506 * @param {number} tier
507 */
508export function spellMindPowerFromTier (tier)
509{
510 const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1)));
511 return tierStatBonus(MATERIAL_TIER_ORDER[rank - 1]);
512}
513
514/** Spells that are not starter knowledge and need a spellbook to learn. */
515export function learnableSpellIds ()
516{
517 return Object.values(SPELL_DEFINITIONS)
518 .filter((def) => !def.starter && !def.mobOnly)
519 .map((def) => def.spellId);
520}