BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

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