Shade own sprites, hostile spawners, and fixed summon expiry.
Body is static with a 2-frame bloom like sprites; spawners are aggressive while spell summons keep companion targeting. Drop Int32 truncation on summon expiresAt.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -2400,6 +2400,7 @@ export class WorldView
2400
2400
const bloom = new GameObject(0, 0, bloomImage, SORT_ENTITY);
2401
2401
bloom.renderer.layer = RENDER_LAYER_BLOOM;
2402
2402
this.#markUnlit(bloom);
2403
this.#startIdleAnimation(bloom);
2403
2404
this.scene.addObject(bloom);
2404
2405
entity.bloomOverlays.push(bloom);
2405
2406
entity.bloomOverlayTints.push(entity.bodyTint);
@@ -2516,11 +2517,18 @@ export class WorldView
2516
2517
this.#setRendererVisible(overlay, this.bloomEnabled);
2517
2518
if (!this.bloomEnabled)
2518
2519
{ continue; }
2519
/** Body bloom must share the base sprite's animation frame (e.g. elemental sprites). */
2520
/** Multi-frame body bloom locks to the base sprite; static bodies leave bloom free to animate. */
2520
2521
if (entity.bloomBody && index === 0 && entity.object?.renderer)
2521
2522
{
2522
overlay.renderer.cycle = null;
2523
overlay.renderer.subImage = entity.object.renderer.subImage | 0;
2523
const bodySprite = entity.object.renderer.sprite;
2524
const bloomSprite = overlay.renderer.sprite;
2525
const bodyFrames = Number(bodySprite?.subImages) || Number(bodySprite?.subImgTotal) || 1;
2526
const bloomFrames = Number(bloomSprite?.subImages) || Number(bloomSprite?.subImgTotal) || 1;
2527
if (bodyFrames > 1 && bloomFrames === bodyFrames)
2528
{
2529
overlay.renderer.cycle = null;
2530
overlay.renderer.subImage = entity.object.renderer.subImage | 0;
2531
}
2524
2532
}
2525
2533
overlay.transform.rotation = walkTilt;
2526
2534
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;
@@ -2530,7 +2538,7 @@ export class WorldView
2530
2538
else if (bloomTint)
2531
2539
{ this.#syncUnlitTintSprite(overlay, bloomTint); }
2532
2540
else
2533
{ this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2541
{ this.#markUnlit(overlay); }
2534
2542
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);
2535
2543
}
2536
2544
this.#placeHpBar(entity, pivotX, pivotY);
@@ -2400,6 +2400,7 @@ export class WorldView2400
const bloom = new GameObject(0, 0, bloomImage, SORT_ENTITY);2400
const bloom = new GameObject(0, 0, bloomImage, SORT_ENTITY);2401
bloom.renderer.layer = RENDER_LAYER_BLOOM;2401
bloom.renderer.layer = RENDER_LAYER_BLOOM;2402
this.#markUnlit(bloom);2402
this.#markUnlit(bloom);2403
this.#startIdleAnimation(bloom);2403
this.scene.addObject(bloom);2404
this.scene.addObject(bloom);2404
entity.bloomOverlays.push(bloom);2405
entity.bloomOverlays.push(bloom);2405
entity.bloomOverlayTints.push(entity.bodyTint);2406
entity.bloomOverlayTints.push(entity.bodyTint);@@ -2516,11 +2517,18 @@ export class WorldView2516
this.#setRendererVisible(overlay, this.bloomEnabled);2517
this.#setRendererVisible(overlay, this.bloomEnabled);2517
if (!this.bloomEnabled)2518
if (!this.bloomEnabled)2518
{ continue; }2519
{ continue; }2519
/** Body bloom must share the base sprite's animation frame (e.g. elemental sprites). */2520
/** Multi-frame body bloom locks to the base sprite; static bodies leave bloom free to animate. */2520
if (entity.bloomBody && index === 0 && entity.object?.renderer)2521
if (entity.bloomBody && index === 0 && entity.object?.renderer)2521
{2522
{2522
overlay.renderer.cycle = null;2523
const bodySprite = entity.object.renderer.sprite;2523
overlay.renderer.subImage = entity.object.renderer.subImage | 0;2524
const bloomSprite = overlay.renderer.sprite;2525
const bodyFrames = Number(bodySprite?.subImages) || Number(bodySprite?.subImgTotal) || 1;2526
const bloomFrames = Number(bloomSprite?.subImages) || Number(bloomSprite?.subImgTotal) || 1;2527
if (bodyFrames > 1 && bloomFrames === bodyFrames)2528
{2529
overlay.renderer.cycle = null;2530
overlay.renderer.subImage = entity.object.renderer.subImage | 0;2531
}2524
}2532
}2525
overlay.transform.rotation = walkTilt;2533
overlay.transform.rotation = walkTilt;2526
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;2534
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;@@ -2530,7 +2538,7 @@ export class WorldView2530
else if (bloomTint)2538
else if (bloomTint)2531
{ this.#syncUnlitTintSprite(overlay, bloomTint); }2539
{ this.#syncUnlitTintSprite(overlay, bloomTint); }2532
else2540
else2533
{ this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }2541
{ this.#markUnlit(overlay); }2534
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);2542
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);2535
}2543
}2536
this.#placeHpBar(entity, pivotX, pivotY);2544
this.#placeHpBar(entity, pivotX, pivotY);@@ -173,7 +173,7 @@ function mobScanDefs ()
173
173
{
174
174
if (def.usePlayerBody)
175
175
{ continue; }
176
// spriteKey reuses another mob's art folder (e.g. Shade → rat).
176
// spriteKey reuses another mob's art folder when set.
177
177
const key = def.spriteKey ?? def.key ?? def.mobTypeId;
178
178
if (defs[key])
179
179
{ continue; }
@@ -183,6 +183,9 @@ function mobScanDefs ()
183
183
frames: def.frames ?? 1,
184
184
framesPerRow: def.framesPerRow ?? 1,
185
185
animationSpeed: def.animationSpeed ?? 0,
186
bloomFrames: def.bloomFrames ?? null,
187
bloomFramesPerRow: def.bloomFramesPerRow ?? null,
188
bloomAnimationSpeed: def.bloomAnimationSpeed ?? null,
186
189
assetFolder: def.assetFolder ?? "mobs"
187
190
};
188
191
}
@@ -401,10 +404,16 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
401
404
});
402
405
if (blooms[state])
403
406
{
407
const bloomFrames = Math.max(1, def.bloomFrames ?? frames);
408
const bloomPerRow = Math.max(1, def.bloomFramesPerRow ?? framesPerRow);
409
const bloomSpeed = Math.max(0, def.bloomAnimationSpeed ?? animationSpeed);
404
410
images.push({
405
411
name: bloomImageName(layer, def.key, state),
406
412
url: `/assets/${urlFolder}/${def.key}/${state}-bloom.png`,
407
...sheet
413
subImgTotal: bloomFrames,
414
perRow: bloomPerRow,
415
loop: bloomSpeed > 0,
416
animationSpeed: bloomSpeed
408
417
});
409
418
}
410
419
/** Worn/gather overlays are always single-frame (inventory sheets may differ). */
@@ -173,7 +173,7 @@ function mobScanDefs ()173
{173
{174
if (def.usePlayerBody)174
if (def.usePlayerBody)175
{ continue; }175
{ continue; }176
// spriteKey reuses another mob's art folder (e.g. Shade → rat).176
// spriteKey reuses another mob's art folder when set.177
const key = def.spriteKey ?? def.key ?? def.mobTypeId;177
const key = def.spriteKey ?? def.key ?? def.mobTypeId;178
if (defs[key])178
if (defs[key])179
{ continue; }179
{ continue; }@@ -183,6 +183,9 @@ function mobScanDefs ()183
frames: def.frames ?? 1,183
frames: def.frames ?? 1,184
framesPerRow: def.framesPerRow ?? 1,184
framesPerRow: def.framesPerRow ?? 1,185
animationSpeed: def.animationSpeed ?? 0,185
animationSpeed: def.animationSpeed ?? 0,186
bloomFrames: def.bloomFrames ?? null,187
bloomFramesPerRow: def.bloomFramesPerRow ?? null,188
bloomAnimationSpeed: def.bloomAnimationSpeed ?? null,186
assetFolder: def.assetFolder ?? "mobs"189
assetFolder: def.assetFolder ?? "mobs"187
};190
};188
}191
}@@ -401,10 +404,16 @@ function scanLayer (layerDir, definitions, layer, urlFolder)401
});404
});402
if (blooms[state])405
if (blooms[state])403
{406
{407
const bloomFrames = Math.max(1, def.bloomFrames ?? frames);408
const bloomPerRow = Math.max(1, def.bloomFramesPerRow ?? framesPerRow);409
const bloomSpeed = Math.max(0, def.bloomAnimationSpeed ?? animationSpeed);404
images.push({410
images.push({405
name: bloomImageName(layer, def.key, state),411
name: bloomImageName(layer, def.key, state),406
url: `/assets/${urlFolder}/${def.key}/${state}-bloom.png`,412
url: `/assets/${urlFolder}/${def.key}/${state}-bloom.png`,407
...sheet413
subImgTotal: bloomFrames,414
perRow: bloomPerRow,415
loop: bloomSpeed > 0,416
animationSpeed: bloomSpeed408
});417
});409
}418
}410
/** Worn/gather overlays are always single-frame (inventory sheets may differ). */419
/** Worn/gather overlays are always single-frame (inventory sheets may differ). */@@ -531,6 +531,8 @@ export function stepAggression (world, now = Date.now())
531
531
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
532
532
{ continue; }
533
533
const def = mobDefinition(entity.creature.mobTypeId);
534
if (world.ecs.get(entity.handle, Component.summon))
535
{ continue; }
534
536
const origin = world.ecs.get(entity.handle, Component.spawnOrigin);
535
537
const aggressive = origin
536
538
? !!origin.aggressive
@@ -531,6 +531,8 @@ export function stepAggression (world, now = Date.now())531
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))531
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))532
{ continue; }532
{ continue; }533
const def = mobDefinition(entity.creature.mobTypeId);533
const def = mobDefinition(entity.creature.mobTypeId);534
if (world.ecs.get(entity.handle, Component.summon))535
{ continue; }534
const origin = world.ecs.get(entity.handle, Component.spawnOrigin);536
const origin = world.ecs.get(entity.handle, Component.spawnOrigin);535
const aggressive = origin537
const aggressive = origin536
? !!origin.aggressive538
? !!origin.aggressive@@ -271,6 +271,8 @@ export function mobComponents (request)
271
271
appearance.lastName = "";
272
272
}
273
273
}
274
else if (def.bloomBody)
275
{ appearance.bloomBody = true; }
274
276
275
277
const maxHp = mobHealthForLevel(def, level);
276
278
const components = {
@@ -271,6 +271,8 @@ export function mobComponents (request)271
appearance.lastName = "";271
appearance.lastName = "";272
}272
}273
}273
}274
else if (def.bloomBody)275
{ appearance.bloomBody = true; }274
276
275
const maxHp = mobHealthForLevel(def, level);277
const maxHp = mobHealthForLevel(def, level);276
const components = {278
const components = {@@ -23,7 +23,7 @@ export function stepSummons (world, now = Date.now())
23
23
for (const entity of world.ecs.query(Component.summon, Component.creature, Component.position))
24
24
{
25
25
const { handle, entityId, summon, position } = entity;
26
if (now >= (summon.expiresAt | 0))
26
if (now >= Number(summon.expiresAt || 0))
27
27
{
28
28
despawnIds.push(entityId);
29
29
continue;
@@ -23,7 +23,7 @@ export function stepSummons (world, now = Date.now())23
for (const entity of world.ecs.query(Component.summon, Component.creature, Component.position))23
for (const entity of world.ecs.query(Component.summon, Component.creature, Component.position))24
{24
{25
const { handle, entityId, summon, position } = entity;25
const { handle, entityId, summon, position } = entity;26
if (now >= (summon.expiresAt | 0))26
if (now >= Number(summon.expiresAt || 0))27
{27
{28
despawnIds.push(entityId);28
despawnIds.push(entityId);29
continue;29
continue;@@ -0,0 +1,109 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { dirname, join } from "node:path";
4
import { fileURLToPath } from "node:url";
5
import { MobId, mobDefinition, mobSpriteName } from "../../shared/definitions/mobs.js";
6
import { mobIsAggressive } from "../../shared/definitions/mobCombat.js";
7
import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
8
import { mobComponents } from "../src/simulation/spawners.js";
9
import { shadeSummonComponents, stepSummons } from "../src/spells/summons.js";
10
import { stepAggression } from "../src/combat/service.js";
11
import { Component } from "../src/ecs/components.js";
12
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
13
14
const ASSET_ROOT = join(dirname(fileURLToPath(import.meta.url)), "../../client/assets");
15
16
function workerOf (simulation, entityId)
17
{
18
const record = simulation.entityRecord(entityId);
19
assert.ok(record, "entity must be remembered");
20
return simulation.workers[record.workerId];
21
}
22
23
test("shade uses own static body and animated bloom sprites", () =>
24
{
25
const shade = mobDefinition(MobId.shade);
26
assert.equal(shade.spriteKey, undefined);
27
assert.equal(mobSpriteName(MobId.shade), "mob:shade:shade");
28
assert.equal(shade.bloomBody, true);
29
assert.equal(shade.frames, 1);
30
assert.equal(shade.bloomFrames, 2);
31
assert.equal(shade.bloomAnimationSpeed, 0.5);
32
assert.equal(shade.aggressive, true);
33
assert.equal(mobIsAggressive(shade), true);
34
35
const catalog = buildSpriteCatalog(ASSET_ROOT);
36
const body = catalog.images.find((entry) => entry.name === "mob:shade:shade");
37
const bloom = catalog.images.find((entry) => entry.name === "mob:shade:shade:bloom");
38
assert.ok(body, "shade body catalog entry");
39
assert.ok(bloom, "shade bloom catalog entry");
40
assert.equal(body.subImgTotal, 1);
41
assert.equal(body.animationSpeed, 0);
42
assert.equal(bloom.subImgTotal, 2);
43
assert.equal(bloom.perRow, 2);
44
assert.equal(bloom.animationSpeed, 0.5);
45
46
const components = mobComponents({
47
tileX: 8,
48
tileY: 8,
49
mobTypeId: MobId.shade,
50
spawnerId: "0:0:1",
51
originTileX: 8,
52
originTileY: 8
53
});
54
assert.equal(components.appearance.bloomBody, true);
55
assert.equal(components.appearance.tint, undefined);
56
assert.equal(components.appearance.dualTint, undefined);
57
assert.equal(components.spawnOrigin.aggressive, true);
58
assert.equal(components.summon, undefined);
59
});
60
61
test("summoned shade uses companion targeting, not player aggro", () =>
62
{
63
const harness = makeSimulation({ workerCount: 1 });
64
try
65
{
66
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
67
const playerId = harness.simulation.spawnCharacter(1, character);
68
const components = shadeSummonComponents({
69
tileX: 10,
70
tileY: 8,
71
level: 10,
72
ownerEntityId: playerId,
73
expiresAt: Date.now() + 60_000
74
});
75
assert.ok(components.summon);
76
assert.equal(components.spawnOrigin, undefined);
77
assert.equal(components.appearance.bloomBody, true);
78
79
const shadeId = harness.simulation.spawnEntity(components);
80
const worker = workerOf(harness.simulation, shadeId);
81
const world = worker.world;
82
const shadeHandle = world.ecs.handleOf(shadeId);
83
84
stepAggression(world, Date.now());
85
assert.equal(
86
world.ecs.get(shadeHandle, Component.combat)?.targetEntityId ?? null,
87
null,
88
"summoned shade must not auto-aggro the owner/player"
89
);
90
91
const ratId = harness.simulation.spawnEntity(mobComponents({
92
tileX: 12,
93
tileY: 8,
94
mobTypeId: MobId.rat,
95
spawnerId: "0:0:2",
96
originTileX: 12,
97
originTileY: 8,
98
aggressive: true
99
}));
100
stepSummons(world, Date.now());
101
assert.equal(
102
world.ecs.get(shadeHandle, Component.combat)?.targetEntityId,
103
ratId,
104
"summoned shade should pick nearby aggressive hostiles"
105
);
106
}
107
finally
108
{ harness.close(); }
109
});
@@ -0,0 +1,109 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { dirname, join } from "node:path";4
import { fileURLToPath } from "node:url";5
import { MobId, mobDefinition, mobSpriteName } from "../../shared/definitions/mobs.js";6
import { mobIsAggressive } from "../../shared/definitions/mobCombat.js";7
import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";8
import { mobComponents } from "../src/simulation/spawners.js";9
import { shadeSummonComponents, stepSummons } from "../src/spells/summons.js";10
import { stepAggression } from "../src/combat/service.js";11
import { Component } from "../src/ecs/components.js";12
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";13
14
const ASSET_ROOT = join(dirname(fileURLToPath(import.meta.url)), "../../client/assets");15
16
function workerOf (simulation, entityId)17
{18
const record = simulation.entityRecord(entityId);19
assert.ok(record, "entity must be remembered");20
return simulation.workers[record.workerId];21
}22
23
test("shade uses own static body and animated bloom sprites", () =>24
{25
const shade = mobDefinition(MobId.shade);26
assert.equal(shade.spriteKey, undefined);27
assert.equal(mobSpriteName(MobId.shade), "mob:shade:shade");28
assert.equal(shade.bloomBody, true);29
assert.equal(shade.frames, 1);30
assert.equal(shade.bloomFrames, 2);31
assert.equal(shade.bloomAnimationSpeed, 0.5);32
assert.equal(shade.aggressive, true);33
assert.equal(mobIsAggressive(shade), true);34
35
const catalog = buildSpriteCatalog(ASSET_ROOT);36
const body = catalog.images.find((entry) => entry.name === "mob:shade:shade");37
const bloom = catalog.images.find((entry) => entry.name === "mob:shade:shade:bloom");38
assert.ok(body, "shade body catalog entry");39
assert.ok(bloom, "shade bloom catalog entry");40
assert.equal(body.subImgTotal, 1);41
assert.equal(body.animationSpeed, 0);42
assert.equal(bloom.subImgTotal, 2);43
assert.equal(bloom.perRow, 2);44
assert.equal(bloom.animationSpeed, 0.5);45
46
const components = mobComponents({47
tileX: 8,48
tileY: 8,49
mobTypeId: MobId.shade,50
spawnerId: "0:0:1",51
originTileX: 8,52
originTileY: 853
});54
assert.equal(components.appearance.bloomBody, true);55
assert.equal(components.appearance.tint, undefined);56
assert.equal(components.appearance.dualTint, undefined);57
assert.equal(components.spawnOrigin.aggressive, true);58
assert.equal(components.summon, undefined);59
});60
61
test("summoned shade uses companion targeting, not player aggro", () =>62
{63
const harness = makeSimulation({ workerCount: 1 });64
try65
{66
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });67
const playerId = harness.simulation.spawnCharacter(1, character);68
const components = shadeSummonComponents({69
tileX: 10,70
tileY: 8,71
level: 10,72
ownerEntityId: playerId,73
expiresAt: Date.now() + 60_00074
});75
assert.ok(components.summon);76
assert.equal(components.spawnOrigin, undefined);77
assert.equal(components.appearance.bloomBody, true);78
79
const shadeId = harness.simulation.spawnEntity(components);80
const worker = workerOf(harness.simulation, shadeId);81
const world = worker.world;82
const shadeHandle = world.ecs.handleOf(shadeId);83
84
stepAggression(world, Date.now());85
assert.equal(86
world.ecs.get(shadeHandle, Component.combat)?.targetEntityId ?? null,87
null,88
"summoned shade must not auto-aggro the owner/player"89
);90
91
const ratId = harness.simulation.spawnEntity(mobComponents({92
tileX: 12,93
tileY: 8,94
mobTypeId: MobId.rat,95
spawnerId: "0:0:2",96
originTileX: 12,97
originTileY: 8,98
aggressive: true99
}));100
stepSummons(world, Date.now());101
assert.equal(102
world.ecs.get(shadeHandle, Component.combat)?.targetEntityId,103
ratId,104
"summoned shade should pick nearby aggressive hostiles"105
);106
}107
finally108
{ harness.close(); }109
});