Fade mobs out as a red silhouette on death instead of vanishing.
Killing blows still flash and knock back; the corpse then holds a full red tint while alpha drains over 0.5s so the hit reads before removal.
@@ -67,6 +67,8 @@ const GATHER_TOOL_HOLD_MS = 1100;
67
67
const DAMAGE_FLASH_MS = 180;
68
68
const FLASH_COLOR_DAMAGE = Object.freeze([1.0, 0.12, 0.12]);
69
69
const FLASH_COLOR_BLOCK = Object.freeze([1.0, 1.0, 1.0]);
70
/** Mob death: full red silhouette fades to transparent after the killing blow. */
71
const DEATH_FADE_MS = 500;
70
72
const DAMAGE_FLOAT_MS = 900;
71
73
const SKILL_LEVEL_FLOAT_MS = 2800;
72
74
/** Projectiles spawn this many sprite-pixels below the caster sprite top. */
@@ -604,7 +606,7 @@ export class WorldView
604
606
{
605
607
if (id === this.localEntityId)
606
608
{ continue; }
607
this.despawnEntity(id);
609
this.despawnEntity(id, { immediate: true });
608
610
}
609
611
for (const [id] of [...this.groundItems.entries()])
610
612
{ this.despawnGroundItem(id); }
@@ -626,7 +628,7 @@ export class WorldView
626
628
this.removeChunk(chunkX, chunkY);
627
629
}
628
630
for (const [id] of [...this.entities.entries()])
629
{ this.despawnEntity(id); }
631
{ this.despawnEntity(id, { immediate: true }); }
630
632
for (const [id] of [...this.groundItems.entries()])
631
633
{ this.despawnGroundItem(id); }
632
634
}
@@ -693,7 +695,7 @@ export class WorldView
693
695
{ continue; }
694
696
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX
695
697
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)
696
{ this.despawnEntity(id); }
698
{ this.despawnEntity(id, { immediate: true }); }
697
699
}
698
700
}
699
701
@@ -735,7 +737,7 @@ export class WorldView
735
737
{ continue; }
736
738
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX
737
739
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)
738
{ this.despawnEntity(id); }
740
{ this.despawnEntity(id, { immediate: true }); }
739
741
}
740
742
this.#rebuildAllEdges();
741
743
}
@@ -796,12 +798,35 @@ export class WorldView
796
798
{ this.#notePlayerTile(payload.tileX, payload.tileY); }
797
799
}
798
800
799
despawnEntity (entityId)
801
despawnEntity (entityId, { immediate = false } = {})
800
802
{
801
this.cancelDeferredCombatHits(entityId);
802
803
const existing = this.entities.get(entityId);
803
804
if (!existing)
804
805
{ return; }
806
if (existing.dying)
807
{
808
if (immediate)
809
{ this.#finishDeathDissolve(entityId); }
810
return;
811
}
812
// Players use the death UI / immediate remove; mobs dissolve so the killing
813
// blow flash and knockback remain visible (unless the caller forces immediate).
814
if (
815
immediate
816
|| existing.characterId
817
|| entityId === this.localEntityId
818
)
819
{
820
this.cancelDeferredCombatHits(entityId);
821
this.#destroyEntityVisuals(existing);
822
this.entities.delete(entityId);
823
return;
824
}
825
this.#beginDeathDissolve(existing);
826
}
827
828
#destroyEntityVisuals (existing)
829
{
805
830
existing.object?.destroy();
806
831
existing.hpBar?.destroy();
807
832
existing.skullMarker?.destroy();
@@ -809,13 +834,38 @@ export class WorldView
809
834
{ overlay.destroy(); }
810
835
for (const overlay of existing.bloomOverlays ?? [])
811
836
{ overlay.destroy(); }
837
}
838
839
#beginDeathDissolve (entity)
840
{
841
const now = performance.now();
842
entity.dying = true;
843
entity.untargetable = true;
844
entity.deathFadeStarted = now;
845
// Keep a full red silhouette for the whole fade (hit flash may already be running).
846
entity.damageFlashUntil = now + DEATH_FADE_MS;
847
entity.damageFlashColor = FLASH_COLOR_DAMAGE;
848
entity.hpBar?.destroy();
849
entity.hpBar = null;
850
entity.skullMarker?.destroy();
851
entity.skullMarker = null;
852
// Leave deferred projectile impacts queued so knockback / float still play on arrival.
853
}
854
855
#finishDeathDissolve (entityId)
856
{
857
this.cancelDeferredCombatHits(entityId);
858
const existing = this.entities.get(entityId);
859
if (!existing)
860
{ return; }
861
this.#destroyEntityVisuals(existing);
812
862
this.entities.delete(entityId);
813
863
}
814
864
815
865
/**
816
866
* Drop queued combat-hit/block presentation for a target.
817
867
* Killing blows often defer health=0 until a projectile lands; if the
818
* target already despawned or respawned, that stale apply must not run.
868
* target already finished dissolving or respawned, that stale apply must not run.
819
869
*/
820
870
cancelDeferredCombatHits (targetId)
821
871
{
@@ -847,7 +897,7 @@ export class WorldView
847
897
updateEntityHealth (entityId, health, maxHealth)
848
898
{
849
899
const entity = this.entities.get(entityId);
850
if (!entity)
900
if (!entity || entity.dying)
851
901
{ return; }
852
902
entity.health = health;
853
903
entity.maxHealth = maxHealth;
@@ -1496,7 +1546,7 @@ export class WorldView
1496
1546
const byTile = new Map();
1497
1547
for (const entity of this.entities.values())
1498
1548
{
1499
if (entity.freeFlight)
1549
if (entity.freeFlight || entity.dying)
1500
1550
{
1501
1551
entity.stackTargetX = 0;
1502
1552
entity.stackTargetY = 0;
@@ -2361,6 +2411,11 @@ export class WorldView
2361
2411
const size = this.tileSize();
2362
2412
const pivot = tilePivot(payload.tileX, payload.tileY, size);
2363
2413
let entity = this.entities.get(payload.entityId);
2414
if (entity?.dying)
2415
{
2416
this.#finishDeathDissolve(payload.entityId);
2417
entity = null;
2418
}
2364
2419
if (!entity)
2365
2420
{
2366
2421
const spriteName = payload.layers?.[0]?.sprite
@@ -2602,14 +2657,29 @@ export class WorldView
2602
2657
const tilt = entity.gait === GAIT.run ? RUN_TILT_DEG : WALK_TILT_DEG;
2603
2658
walkTilt = Math.sin(cycles) * tilt;
2604
2659
}
2605
const flashStrength = (entity.damageFlashUntil ?? 0) > now
2660
let flashStrength = (entity.damageFlashUntil ?? 0) > now
2606
2661
? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
2607
2662
: 0;
2663
let deathAlpha = 1;
2664
if (entity.dying)
2665
{
2666
const fadeT = (now - (entity.deathFadeStarted ?? now)) / DEATH_FADE_MS;
2667
if (fadeT >= 1)
2668
{
2669
this.#finishDeathDissolve(entity.entityId);
2670
return;
2671
}
2672
// Full red silhouette while dissolving; alpha drains over DEATH_FADE_MS.
2673
flashStrength = 1;
2674
deathAlpha = Math.max(0, 1 - fadeT);
2675
}
2608
2676
const flashColor = entity.damageFlashColor ?? FLASH_COLOR_DAMAGE;
2609
2677
const tileShade = this.#entityShadeAlpha(entity, now);
2610
2678
const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2611
2679
2612
2680
entity.object.transform.rotation = walkTilt;
2681
if (entity.object.renderer)
2682
{ entity.object.renderer.alpha = deathAlpha; }
2613
2683
if (entity.bodyDualTint)
2614
2684
{
2615
2685
this.#syncDualTintLitSprite(
@@ -2632,6 +2702,8 @@ export class WorldView
2632
2702
const overlay = entity.overlays[index];
2633
2703
const overlaySort = Math.min(SORT_HP_BAR - 2, SORT_ENTITY + 1 + index);
2634
2704
overlay.transform.rotation = walkTilt;
2705
if (overlay.renderer)
2706
{ overlay.renderer.alpha = deathAlpha; }
2635
2707
const dualTint = entity.overlayDualTints?.[index] ?? null;
2636
2708
if (dualTint)
2637
2709
{
@@ -2658,7 +2730,7 @@ export class WorldView
2658
2730
for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2659
2731
{
2660
2732
const overlay = entity.bloomOverlays[index];
2661
this.#setRendererVisible(overlay, this.bloomEnabled);
2733
this.#setRendererVisible(overlay, this.bloomEnabled && deathAlpha > 0.02);
2662
2734
if (!this.bloomEnabled)
2663
2735
{ continue; }
2664
2736
/** Multi-frame body bloom locks to the base sprite; static bodies leave bloom free to animate. */
@@ -2675,6 +2747,8 @@ export class WorldView
2675
2747
}
2676
2748
}
2677
2749
overlay.transform.rotation = walkTilt;
2750
if (overlay.renderer)
2751
{ overlay.renderer.alpha = deathAlpha; }
2678
2752
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;
2679
2753
const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;
2680
2754
if (bloomDual)
@@ -2685,8 +2759,11 @@ export class WorldView
2685
2759
{ this.#markUnlit(overlay); }
2686
2760
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);
2687
2761
}
2688
this.#placeHpBar(entity, pivotX, pivotY);
2689
this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
2762
if (!entity.dying)
2763
{
2764
this.#placeHpBar(entity, pivotX, pivotY);
2765
this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);
2766
}
2690
2767
}
2691
2768
2692
2769
#markUnlit (object)
@@ -67,6 +67,8 @@ const GATHER_TOOL_HOLD_MS = 1100;67
const DAMAGE_FLASH_MS = 180;67
const DAMAGE_FLASH_MS = 180;68
const FLASH_COLOR_DAMAGE = Object.freeze([1.0, 0.12, 0.12]);68
const FLASH_COLOR_DAMAGE = Object.freeze([1.0, 0.12, 0.12]);69
const FLASH_COLOR_BLOCK = Object.freeze([1.0, 1.0, 1.0]);69
const FLASH_COLOR_BLOCK = Object.freeze([1.0, 1.0, 1.0]);70
/** Mob death: full red silhouette fades to transparent after the killing blow. */71
const DEATH_FADE_MS = 500;70
const DAMAGE_FLOAT_MS = 900;72
const DAMAGE_FLOAT_MS = 900;71
const SKILL_LEVEL_FLOAT_MS = 2800;73
const SKILL_LEVEL_FLOAT_MS = 2800;72
/** Projectiles spawn this many sprite-pixels below the caster sprite top. */74
/** Projectiles spawn this many sprite-pixels below the caster sprite top. */@@ -604,7 +606,7 @@ export class WorldView604
{606
{605
if (id === this.localEntityId)607
if (id === this.localEntityId)606
{ continue; }608
{ continue; }607
this.despawnEntity(id);609
this.despawnEntity(id, { immediate: true });608
}610
}609
for (const [id] of [...this.groundItems.entries()])611
for (const [id] of [...this.groundItems.entries()])610
{ this.despawnGroundItem(id); }612
{ this.despawnGroundItem(id); }@@ -626,7 +628,7 @@ export class WorldView626
this.removeChunk(chunkX, chunkY);628
this.removeChunk(chunkX, chunkY);627
}629
}628
for (const [id] of [...this.entities.entries()])630
for (const [id] of [...this.entities.entries()])629
{ this.despawnEntity(id); }631
{ this.despawnEntity(id, { immediate: true }); }630
for (const [id] of [...this.groundItems.entries()])632
for (const [id] of [...this.groundItems.entries()])631
{ this.despawnGroundItem(id); }633
{ this.despawnGroundItem(id); }632
}634
}@@ -693,7 +695,7 @@ export class WorldView693
{ continue; }695
{ continue; }694
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX696
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX695
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)697
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)696
{ this.despawnEntity(id); }698
{ this.despawnEntity(id, { immediate: true }); }697
}699
}698
}700
}699
701
@@ -735,7 +737,7 @@ export class WorldView735
{ continue; }737
{ continue; }736
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX738
if (Math.floor(entity.tileX / CHUNK_SIZE) === chunkX737
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)739
&& Math.floor(entity.tileY / CHUNK_SIZE) === chunkY)738
{ this.despawnEntity(id); }740
{ this.despawnEntity(id, { immediate: true }); }739
}741
}740
this.#rebuildAllEdges();742
this.#rebuildAllEdges();741
}743
}@@ -796,12 +798,35 @@ export class WorldView796
{ this.#notePlayerTile(payload.tileX, payload.tileY); }798
{ this.#notePlayerTile(payload.tileX, payload.tileY); }797
}799
}798
800
799
despawnEntity (entityId)801
despawnEntity (entityId, { immediate = false } = {})800
{802
{801
this.cancelDeferredCombatHits(entityId);802
const existing = this.entities.get(entityId);803
const existing = this.entities.get(entityId);803
if (!existing)804
if (!existing)804
{ return; }805
{ return; }806
if (existing.dying)807
{808
if (immediate)809
{ this.#finishDeathDissolve(entityId); }810
return;811
}812
// Players use the death UI / immediate remove; mobs dissolve so the killing813
// blow flash and knockback remain visible (unless the caller forces immediate).814
if (815
immediate816
|| existing.characterId817
|| entityId === this.localEntityId818
)819
{820
this.cancelDeferredCombatHits(entityId);821
this.#destroyEntityVisuals(existing);822
this.entities.delete(entityId);823
return;824
}825
this.#beginDeathDissolve(existing);826
}827
828
#destroyEntityVisuals (existing)829
{805
existing.object?.destroy();830
existing.object?.destroy();806
existing.hpBar?.destroy();831
existing.hpBar?.destroy();807
existing.skullMarker?.destroy();832
existing.skullMarker?.destroy();@@ -809,13 +834,38 @@ export class WorldView809
{ overlay.destroy(); }834
{ overlay.destroy(); }810
for (const overlay of existing.bloomOverlays ?? [])835
for (const overlay of existing.bloomOverlays ?? [])811
{ overlay.destroy(); }836
{ overlay.destroy(); }837
}838
839
#beginDeathDissolve (entity)840
{841
const now = performance.now();842
entity.dying = true;843
entity.untargetable = true;844
entity.deathFadeStarted = now;845
// Keep a full red silhouette for the whole fade (hit flash may already be running).846
entity.damageFlashUntil = now + DEATH_FADE_MS;847
entity.damageFlashColor = FLASH_COLOR_DAMAGE;848
entity.hpBar?.destroy();849
entity.hpBar = null;850
entity.skullMarker?.destroy();851
entity.skullMarker = null;852
// Leave deferred projectile impacts queued so knockback / float still play on arrival.853
}854
855
#finishDeathDissolve (entityId)856
{857
this.cancelDeferredCombatHits(entityId);858
const existing = this.entities.get(entityId);859
if (!existing)860
{ return; }861
this.#destroyEntityVisuals(existing);812
this.entities.delete(entityId);862
this.entities.delete(entityId);813
}863
}814
864
815
/**865
/**816
* Drop queued combat-hit/block presentation for a target.866
* Drop queued combat-hit/block presentation for a target.817
* Killing blows often defer health=0 until a projectile lands; if the867
* Killing blows often defer health=0 until a projectile lands; if the818
* target already despawned or respawned, that stale apply must not run.868
* target already finished dissolving or respawned, that stale apply must not run.819
*/869
*/820
cancelDeferredCombatHits (targetId)870
cancelDeferredCombatHits (targetId)821
{871
{@@ -847,7 +897,7 @@ export class WorldView847
updateEntityHealth (entityId, health, maxHealth)897
updateEntityHealth (entityId, health, maxHealth)848
{898
{849
const entity = this.entities.get(entityId);899
const entity = this.entities.get(entityId);850
if (!entity)900
if (!entity || entity.dying)851
{ return; }901
{ return; }852
entity.health = health;902
entity.health = health;853
entity.maxHealth = maxHealth;903
entity.maxHealth = maxHealth;@@ -1496,7 +1546,7 @@ export class WorldView1496
const byTile = new Map();1546
const byTile = new Map();1497
for (const entity of this.entities.values())1547
for (const entity of this.entities.values())1498
{1548
{1499
if (entity.freeFlight)1549
if (entity.freeFlight || entity.dying)1500
{1550
{1501
entity.stackTargetX = 0;1551
entity.stackTargetX = 0;1502
entity.stackTargetY = 0;1552
entity.stackTargetY = 0;@@ -2361,6 +2411,11 @@ export class WorldView2361
const size = this.tileSize();2411
const size = this.tileSize();2362
const pivot = tilePivot(payload.tileX, payload.tileY, size);2412
const pivot = tilePivot(payload.tileX, payload.tileY, size);2363
let entity = this.entities.get(payload.entityId);2413
let entity = this.entities.get(payload.entityId);2414
if (entity?.dying)2415
{2416
this.#finishDeathDissolve(payload.entityId);2417
entity = null;2418
}2364
if (!entity)2419
if (!entity)2365
{2420
{2366
const spriteName = payload.layers?.[0]?.sprite2421
const spriteName = payload.layers?.[0]?.sprite@@ -2602,14 +2657,29 @@ export class WorldView2602
const tilt = entity.gait === GAIT.run ? RUN_TILT_DEG : WALK_TILT_DEG;2657
const tilt = entity.gait === GAIT.run ? RUN_TILT_DEG : WALK_TILT_DEG;2603
walkTilt = Math.sin(cycles) * tilt;2658
walkTilt = Math.sin(cycles) * tilt;2604
}2659
}2605
const flashStrength = (entity.damageFlashUntil ?? 0) > now2660
let flashStrength = (entity.damageFlashUntil ?? 0) > now2606
? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS2661
? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS2607
: 0;2662
: 0;2663
let deathAlpha = 1;2664
if (entity.dying)2665
{2666
const fadeT = (now - (entity.deathFadeStarted ?? now)) / DEATH_FADE_MS;2667
if (fadeT >= 1)2668
{2669
this.#finishDeathDissolve(entity.entityId);2670
return;2671
}2672
// Full red silhouette while dissolving; alpha drains over DEATH_FADE_MS.2673
flashStrength = 1;2674
deathAlpha = Math.max(0, 1 - fadeT);2675
}2608
const flashColor = entity.damageFlashColor ?? FLASH_COLOR_DAMAGE;2676
const flashColor = entity.damageFlashColor ?? FLASH_COLOR_DAMAGE;2609
const tileShade = this.#entityShadeAlpha(entity, now);2677
const tileShade = this.#entityShadeAlpha(entity, now);2610
const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);2678
const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);2611
2679
2612
entity.object.transform.rotation = walkTilt;2680
entity.object.transform.rotation = walkTilt;2681
if (entity.object.renderer)2682
{ entity.object.renderer.alpha = deathAlpha; }2613
if (entity.bodyDualTint)2683
if (entity.bodyDualTint)2614
{2684
{2615
this.#syncDualTintLitSprite(2685
this.#syncDualTintLitSprite(@@ -2632,6 +2702,8 @@ export class WorldView2632
const overlay = entity.overlays[index];2702
const overlay = entity.overlays[index];2633
const overlaySort = Math.min(SORT_HP_BAR - 2, SORT_ENTITY + 1 + index);2703
const overlaySort = Math.min(SORT_HP_BAR - 2, SORT_ENTITY + 1 + index);2634
overlay.transform.rotation = walkTilt;2704
overlay.transform.rotation = walkTilt;2705
if (overlay.renderer)2706
{ overlay.renderer.alpha = deathAlpha; }2635
const dualTint = entity.overlayDualTints?.[index] ?? null;2707
const dualTint = entity.overlayDualTints?.[index] ?? null;2636
if (dualTint)2708
if (dualTint)2637
{2709
{@@ -2658,7 +2730,7 @@ export class WorldView2658
for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)2730
for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)2659
{2731
{2660
const overlay = entity.bloomOverlays[index];2732
const overlay = entity.bloomOverlays[index];2661
this.#setRendererVisible(overlay, this.bloomEnabled);2733
this.#setRendererVisible(overlay, this.bloomEnabled && deathAlpha > 0.02);2662
if (!this.bloomEnabled)2734
if (!this.bloomEnabled)2663
{ continue; }2735
{ continue; }2664
/** Multi-frame body bloom locks to the base sprite; static bodies leave bloom free to animate. */2736
/** Multi-frame body bloom locks to the base sprite; static bodies leave bloom free to animate. */@@ -2675,6 +2747,8 @@ export class WorldView2675
}2747
}2676
}2748
}2677
overlay.transform.rotation = walkTilt;2749
overlay.transform.rotation = walkTilt;2750
if (overlay.renderer)2751
{ overlay.renderer.alpha = deathAlpha; }2678
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;2752
const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;2679
const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;2753
const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;2680
if (bloomDual)2754
if (bloomDual)@@ -2685,8 +2759,11 @@ export class WorldView2685
{ this.#markUnlit(overlay); }2759
{ this.#markUnlit(overlay); }2686
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);2760
this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1, flight);2687
}2761
}2688
this.#placeHpBar(entity, pivotX, pivotY);2762
if (!entity.dying)2689
this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);2763
{2764
this.#placeHpBar(entity, pivotX, pivotY);2765
this.#placeSkullMarker(entity, pivotX, pivotY, tileShade);2766
}2690
}2767
}2691
2768
2692
#markUnlit (object)2769
#markUnlit (object)