BlueGit

timfa questward

Fairy casts random-element sprite bolts instead of melee.

Prefer spell attacks like sprites, know every elemental spark, and pick one each cast without a fixed spawn tint.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
700600bf1991090a60637165b37785cf75b81ca3
Parent
952d6583
4 files changed +25 −23
server/src/combat/service.js +6 −17
@@ -14,7 +14,7 @@ import
14 14 import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
15 15 import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16 16 import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17 import { AttackType, MAGIC_ELEMENT_ORDER } from "../../../shared/definitions/attackTypes.js";
17 import { AttackType } from "../../../shared/definitions/attackTypes.js";
18 18 import
19 19 {
20 20 effectiveHitSkillInDarkness,
@@ -324,25 +324,14 @@ function arrowStackInOffhand (equipment)
324 324 return stack;
325 325 }
326 326
327 /** Physical attack type, tipped-arrow element, or per-swing random fairy element. */
327 /** Physical attack type, or tipped-arrow element for ranged shots. */
328 328 function resolveAttackDamageType (ecs, attackerHandle, profile)
329 329 {
330 if (attackerHandle != null)
330 if (attackerHandle != null && profile?.mode === "ranged")
331 331 {
332 const creature = ecs.get(attackerHandle, Component.creature);
333 const def = creature ? mobDefinition(creature.mobTypeId) : null;
334 if (def?.randomElementMelee)
335 {
336 return MAGIC_ELEMENT_ORDER[
337 Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)
338 ];
339 }
340 if (profile?.mode === "ranged")
341 {
342 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
343 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
344 { return stack.instance.element; }
345 }
332 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
333 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
334 { return stack.instance.element; }
346 335 }
347 336 return profile?.attackType ?? AttackType.blunt;
348 337 }
@@ -14,7 +14,7 @@ import
14import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
14import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16import { mobDamageAffinities } from "../../../shared/combat/magic.js";
16import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17import { AttackType, MAGIC_ELEMENT_ORDER } from "../../../shared/definitions/attackTypes.js";
17import { AttackType } from "../../../shared/definitions/attackTypes.js";
18import
18import
19 {
19 {
20 effectiveHitSkillInDarkness,
20 effectiveHitSkillInDarkness,
@@ -324,25 +324,14 @@ function arrowStackInOffhand (equipment)
324 return stack;
324 return stack;
325}
325}
326
326
327/** Physical attack type, tipped-arrow element, or per-swing random fairy element. */
327/** Physical attack type, or tipped-arrow element for ranged shots. */
328function resolveAttackDamageType (ecs, attackerHandle, profile)
328function resolveAttackDamageType (ecs, attackerHandle, profile)
329{
329{
330 if (attackerHandle != null)
330 if (attackerHandle != null && profile?.mode === "ranged")
331 {
331 {
332 const creature = ecs.get(attackerHandle, Component.creature);
332 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
333 const def = creature ? mobDefinition(creature.mobTypeId) : null;
333 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
334 if (def?.randomElementMelee)
334 { return stack.instance.element; }
335 {
336 return MAGIC_ELEMENT_ORDER[
337 Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)
338 ];
339 }
340 if (profile?.mode === "ranged")
341 {
342 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
343 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
344 { return stack.instance.element; }
345 }
346 }
335 }
347 return profile?.attackType ?? AttackType.blunt;
336 return profile?.attackType ?? AttackType.blunt;
348}
337}
server/src/simulation/spawners.js +11 −2
@@ -343,7 +343,16 @@ export function mobComponents (request)
343 343 }
344 344
345 345 const knownSpells = normalizeMobSpells(request.spells, level);
346 if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
346 if (def.randomElementSpell)
347 {
348 /** Fairies know every elemental sprite bolt and pick one at random each cast. */
349 for (const boltId of Object.values(SPRITE_BOLT_SPELL_BY_ELEMENT))
350 {
351 if (!knownSpells.some((entry) => entry.spellId === boltId))
352 { knownSpells.push({ spellId: boltId }); }
353 }
354 }
355 else if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
347 356 {
348 357 const boltId = SPRITE_BOLT_SPELL_BY_ELEMENT[element];
349 358 if (!knownSpells.some((entry) => entry.spellId === boltId))
@@ -351,7 +360,7 @@ export function mobComponents (request)
351 360 }
352 361 if (knownSpells.length)
353 362 {
354 const castChance = element ? 100 : mobSpellCastChancePercent(level);
363 const castChance = (element || def.randomElementSpell) ? 100 : mobSpellCastChancePercent(level);
355 364 components.spells = {
356 365 known: knownSpells.map((entry) => entry.spellId),
357 366 favorites: [],
@@ -343,7 +343,16 @@ export function mobComponents (request)
343 }
343 }
344
344
345 const knownSpells = normalizeMobSpells(request.spells, level);
345 const knownSpells = normalizeMobSpells(request.spells, level);
346 if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
346 if (def.randomElementSpell)
347 {
348 /** Fairies know every elemental sprite bolt and pick one at random each cast. */
349 for (const boltId of Object.values(SPRITE_BOLT_SPELL_BY_ELEMENT))
350 {
351 if (!knownSpells.some((entry) => entry.spellId === boltId))
352 { knownSpells.push({ spellId: boltId }); }
353 }
354 }
355 else if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
347 {
356 {
348 const boltId = SPRITE_BOLT_SPELL_BY_ELEMENT[element];
357 const boltId = SPRITE_BOLT_SPELL_BY_ELEMENT[element];
349 if (!knownSpells.some((entry) => entry.spellId === boltId))
358 if (!knownSpells.some((entry) => entry.spellId === boltId))
@@ -351,7 +360,7 @@ export function mobComponents (request)
351 }
360 }
352 if (knownSpells.length)
361 if (knownSpells.length)
353 {
362 {
354 const castChance = element ? 100 : mobSpellCastChancePercent(level);
363 const castChance = (element || def.randomElementSpell) ? 100 : mobSpellCastChancePercent(level);
355 components.spells = {
364 components.spells = {
356 known: knownSpells.map((entry) => entry.spellId),
365 known: knownSpells.map((entry) => entry.spellId),
357 favorites: [],
366 favorites: [],
server/tests/shearing.test.js +4 −2
@@ -111,14 +111,16 @@ test("sheep and cashmere goat are shearable with fleece/shorn sprites", () =>
111 111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
112 112 });
113 113
114 test("fairy uses own sprites, dual-channel kit, and random-element melee", () =>
114 test("fairy uses own sprites, dual-channel kit, and random-element spell bolts", () =>
115 115 {
116 116 const fairy = mobDefinition(MobId.fairy);
117 117 assert.equal(fairy.spriteKey, undefined);
118 118 assert.equal(mobSpriteName(MobId.fairy), "mob:fairy:fairy");
119 119 assert.equal(fairy.bloomBody, true);
120 120 assert.equal(fairy.dualChannelAppearance, true);
121 assert.equal(fairy.randomElementMelee, true);
121 assert.equal(fairy.preferSpellAttack, true);
122 assert.equal(fairy.randomElementSpell, true);
123 assert.equal(fairy.randomElementMelee, undefined);
122 124 assert.equal(fairy.lightRadiusTiles, 1);
123 125 assert.equal(fairy.frames, 2);
124 126 assert.equal(fairy.drops.length, 1);
@@ -111,14 +111,16 @@ test("sheep and cashmere goat are shearable with fleece/shorn sprites", () =>
111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
112});
112});
113
113
114test("fairy uses own sprites, dual-channel kit, and random-element melee", () =>
114test("fairy uses own sprites, dual-channel kit, and random-element spell bolts", () =>
115{
115{
116 const fairy = mobDefinition(MobId.fairy);
116 const fairy = mobDefinition(MobId.fairy);
117 assert.equal(fairy.spriteKey, undefined);
117 assert.equal(fairy.spriteKey, undefined);
118 assert.equal(mobSpriteName(MobId.fairy), "mob:fairy:fairy");
118 assert.equal(mobSpriteName(MobId.fairy), "mob:fairy:fairy");
119 assert.equal(fairy.bloomBody, true);
119 assert.equal(fairy.bloomBody, true);
120 assert.equal(fairy.dualChannelAppearance, true);
120 assert.equal(fairy.dualChannelAppearance, true);
121 assert.equal(fairy.randomElementMelee, true);
121 assert.equal(fairy.preferSpellAttack, true);
122 assert.equal(fairy.randomElementSpell, true);
123 assert.equal(fairy.randomElementMelee, undefined);
122 assert.equal(fairy.lightRadiusTiles, 1);
124 assert.equal(fairy.lightRadiusTiles, 1);
123 assert.equal(fairy.frames, 2);
125 assert.equal(fairy.frames, 2);
124 assert.equal(fairy.drops.length, 1);
126 assert.equal(fairy.drops.length, 1);
shared/definitions/mobs.js +4 −2
@@ -307,13 +307,15 @@ export const MOB_DEFINITIONS = Object.freeze({
307 307 untargetable: false,
308 308 aggressive: true,
309 309 aggroRangeTiles: 5,
310 /** Prefer sprite-style elemental bolts over melee. */
311 preferSpellAttack: true,
312 /** Cast a random-element sprite bolt each attack (no fixed spawn element). */
313 randomElementSpell: true,
310 314 /** Dimmer than elemental sprites (radius 2). */
311 315 lightRadiusTiles: 1,
312 316 bloomBody: true,
313 317 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
314 318 dualChannelAppearance: true,
315 /** Melee hits roll a fresh magic element each swing. */
316 randomElementMelee: true,
317 319 gait: "walk",
318 320 sex: "female",
319 321 frames: 2,
@@ -307,13 +307,15 @@ export const MOB_DEFINITIONS = Object.freeze({
307 untargetable: false,
307 untargetable: false,
308 aggressive: true,
308 aggressive: true,
309 aggroRangeTiles: 5,
309 aggroRangeTiles: 5,
310 /** Prefer sprite-style elemental bolts over melee. */
311 preferSpellAttack: true,
312 /** Cast a random-element sprite bolt each attack (no fixed spawn element). */
313 randomElementSpell: true,
310 /** Dimmer than elemental sprites (radius 2). */
314 /** Dimmer than elemental sprites (radius 2). */
311 lightRadiusTiles: 1,
315 lightRadiusTiles: 1,
312 bloomBody: true,
316 bloomBody: true,
313 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
317 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
314 dualChannelAppearance: true,
318 dualChannelAppearance: true,
315 /** Melee hits roll a fresh magic element each swing. */
316 randomElementMelee: true,
317 gait: "walk",
319 gait: "walk",
318 sex: "female",
320 sex: "female",
319 frames: 2,
321 frames: 2,