BlueGit

timfa questward

Files

questward / shared / definitions / spells.js

spells.js

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