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.
@@ -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 @@ import14
import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";14
import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";15
import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";15
import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";16
import { mobDamageAffinities } from "../../../shared/combat/magic.js";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
import18
import19
{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. */328
function resolveAttackDamageType (ecs, attackerHandle, profile)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);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
}@@ -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: [],@@ -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
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
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);