Retune skull tint to white→black→red with world-setting thresholds
Skull score now lerps white→black up to skullBlackMax (default 500); red (and town-guard hostility) starts strictly above that, to skullRedMax. Guard aggro from a bounty kill clears when the killer dies. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -3366,7 +3366,7 @@ export class WorldView
3366
3366
entity.skullMarker = null;
3367
3367
return;
3368
3368
}
3369
const tint = skullTintColor(entity.skullValue | 0);
3369
const tint = skullTintColor(entity.skullValue | 0, this.settings);
3370
3370
if (!tint)
3371
3371
{
3372
3372
entity.skullMarker?.destroy();
@@ -3366,7 +3366,7 @@ export class WorldView3366
entity.skullMarker = null;3366
entity.skullMarker = null;3367
return;3367
return;3368
}3368
}3369
const tint = skullTintColor(entity.skullValue | 0);3369
const tint = skullTintColor(entity.skullValue | 0, this.settings);3370
if (!tint)3370
if (!tint)3371
{3371
{3372
entity.skullMarker?.destroy();3372
entity.skullMarker?.destroy();@@ -917,7 +917,7 @@ function pickAggressionTargetForTownGuard (world, entity, range)
917
917
}
918
918
for (const player of world.ecs.query(Component.character, Component.position))
919
919
{
920
if (!skullAttractsTownGuards(player.character?.skullValue))
920
if (!skullAttractsTownGuards(player.character?.skullValue, world.settings))
921
921
{ continue; }
922
922
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);
923
923
if (dist != null && dist < bestDist)
@@ -917,7 +917,7 @@ function pickAggressionTargetForTownGuard (world, entity, range)917
}917
}918
for (const player of world.ecs.query(Component.character, Component.position))918
for (const player of world.ecs.query(Component.character, Component.position))919
{919
{920
if (!skullAttractsTownGuards(player.character?.skullValue))920
if (!skullAttractsTownGuards(player.character?.skullValue, world.settings))921
{ continue; }921
{ continue; }922
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);922
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);923
if (dist != null && dist < bestDist)923
if (dist != null && dist < bestDist)@@ -627,9 +627,9 @@ test("town guards aggro players whose skull tint lerps toward red", () =>
627
627
try
628
628
{
629
629
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
630
harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());
630
harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS + 1, harness.now());
631
631
const playerId = harness.simulation.spawnCharacter(1, character);
632
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);
632
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS + 1);
633
633
634
634
const guardId = harness.simulation.spawnEntity(mobComponents({
635
635
tileX: 10,
@@ -652,6 +652,35 @@ test("town guards aggro players whose skull tint lerps toward red", () =>
652
652
{ harness.close(); }
653
653
});
654
654
655
test("town guards ignore players at black-max skull (not yet red)", () =>
656
{
657
const harness = makeSimulation({ workerCount: 1 });
658
try
659
{
660
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
661
harness.stateDb.setKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());
662
const playerId = harness.simulation.spawnCharacter(1, character);
663
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);
664
665
const guardId = harness.simulation.spawnEntity(mobComponents({
666
tileX: 10,
667
tileY: 8,
668
mobTypeId: MobId.townGuard,
669
spawnerId: "0:0:guard",
670
originTileX: 10,
671
originTileY: 8,
672
wanderRangeTiles: 8,
673
level: 10
674
}));
675
676
harness.simulation.step();
677
assert.equal(componentsOf(harness.simulation, guardId).combat?.targetEntityId, null);
678
assert.equal(componentsOf(harness.simulation, playerId).combat?.targetEntityId, null);
679
}
680
finally
681
{ harness.close(); }
682
});
683
655
684
test("town guards ignore players with white-only skull", () =>
656
685
{
657
686
const harness = makeSimulation({ workerCount: 1 });
@@ -627,9 +627,9 @@ test("town guards aggro players whose skull tint lerps toward red", () =>627
try627
try628
{628
{629
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });629
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });630
harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());630
harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS + 1, harness.now());631
const playerId = harness.simulation.spawnCharacter(1, character);631
const playerId = harness.simulation.spawnCharacter(1, character);632
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);632
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS + 1);633
633
634
const guardId = harness.simulation.spawnEntity(mobComponents({634
const guardId = harness.simulation.spawnEntity(mobComponents({635
tileX: 10,635
tileX: 10,@@ -652,6 +652,35 @@ test("town guards aggro players whose skull tint lerps toward red", () =>652
{ harness.close(); }652
{ harness.close(); }653
});653
});654
654
655
test("town guards ignore players at black-max skull (not yet red)", () =>656
{657
const harness = makeSimulation({ workerCount: 1 });658
try659
{660
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });661
harness.stateDb.setKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());662
const playerId = harness.simulation.spawnCharacter(1, character);663
assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);664
665
const guardId = harness.simulation.spawnEntity(mobComponents({666
tileX: 10,667
tileY: 8,668
mobTypeId: MobId.townGuard,669
spawnerId: "0:0:guard",670
originTileX: 10,671
originTileY: 8,672
wanderRangeTiles: 8,673
level: 10674
}));675
676
harness.simulation.step();677
assert.equal(componentsOf(harness.simulation, guardId).combat?.targetEntityId, null);678
assert.equal(componentsOf(harness.simulation, playerId).combat?.targetEntityId, null);679
}680
finally681
{ harness.close(); }682
});683
655
test("town guards ignore players with white-only skull", () =>684
test("town guards ignore players with white-only skull", () =>656
{685
{657
const harness = makeSimulation({ workerCount: 1 });686
const harness = makeSimulation({ workerCount: 1 });@@ -5,11 +5,13 @@ import
5
5
skullValue,
6
6
skullTintColor,
7
7
skullAttractsTownGuards,
8
resolveSkullThresholds,
8
9
decayKillCounter,
9
10
SKULL_PURE_RED_VALUE,
10
11
SKULL_DARK_RED_VALUE,
11
12
SKULL_KILL_BONUS,
12
SKULL_RED_LERP_START
13
SKULL_BLACK_MAX_DEFAULT,
14
SKULL_RED_MAX_DEFAULT
13
15
} from "../../shared/combat/skull.js";
14
16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
15
17
import { Component } from "../src/ecs/components.js";
@@ -58,10 +60,12 @@ test("kill counter decays one point per second", () =>
58
60
assert.deepEqual(decayKillCounter(2, 10_000), { killCounter: 0, consumedMs: 2000 });
59
61
});
60
62
61
test("skull tint: invisible, white, red, dark red", () =>
63
test("skull tint: invisible, white→black, black→red, dark red", () =>
62
64
{
63
65
assert.equal(skullTintColor(0), null);
64
assert.deepEqual(skullTintColor(1), { r: 1, g: 1, b: 1 });
66
const nearWhite = skullTintColor(1);
67
assert.ok(nearWhite.r > 0.99 && nearWhite.g > 0.99 && nearWhite.b > 0.99);
68
assert.deepEqual(skullTintColor(SKULL_BLACK_MAX_DEFAULT), { r: 0, g: 0, b: 0 });
65
69
assert.deepEqual(skullTintColor(SKULL_PURE_RED_VALUE), { r: 1, g: 0, b: 0 });
66
70
const dark = skullTintColor(SKULL_DARK_RED_VALUE);
67
71
assert.ok(Math.abs(dark.r - 128 / 255) < 1e-9);
@@ -69,12 +73,27 @@ test("skull tint: invisible, white, red, dark red", () =>
69
73
assert.equal(dark.b, 0);
70
74
});
71
75
72
test("skull attracts town guards once tint starts lerping red", () =>
76
test("skull thresholds honour world settings", () =>
77
{
78
const custom = { skullBlackMax: 100, skullRedMax: 1000 };
79
assert.deepEqual(resolveSkullThresholds(custom), {
80
blackMax: 100,
81
redMax: 1000,
82
darkRedMax: 2000
83
});
84
assert.deepEqual(skullTintColor(100, custom), { r: 0, g: 0, b: 0 });
85
assert.deepEqual(skullTintColor(1000, custom), { r: 1, g: 0, b: 0 });
86
assert.equal(skullAttractsTownGuards(100, custom), false);
87
assert.equal(skullAttractsTownGuards(101, custom), true);
88
assert.equal(SKULL_RED_MAX_DEFAULT, SKULL_PURE_RED_VALUE);
89
});
90
91
test("skull attracts town guards once past black max (red lerp)", () =>
73
92
{
74
93
assert.equal(skullAttractsTownGuards(0), false);
75
assert.equal(skullAttractsTownGuards(SKULL_RED_LERP_START), false);
76
assert.equal(skullAttractsTownGuards(SKULL_RED_LERP_START + 1), true);
77
assert.equal(skullAttractsTownGuards(SKULL_KILL_BONUS), true);
94
assert.equal(skullAttractsTownGuards(SKULL_BLACK_MAX_DEFAULT), false);
95
assert.equal(skullAttractsTownGuards(SKULL_BLACK_MAX_DEFAULT + 1), true);
96
assert.equal(skullAttractsTownGuards(SKULL_KILL_BONUS), false);
78
97
});
79
98
80
99
test("PvP kill awards temporary skull points that replicate", () =>
@@ -5,11 +5,13 @@ import5
skullValue,5
skullValue,6
skullTintColor,6
skullTintColor,7
skullAttractsTownGuards,7
skullAttractsTownGuards,8
resolveSkullThresholds,8
decayKillCounter,9
decayKillCounter,9
SKULL_PURE_RED_VALUE,10
SKULL_PURE_RED_VALUE,10
SKULL_DARK_RED_VALUE,11
SKULL_DARK_RED_VALUE,11
SKULL_KILL_BONUS,12
SKULL_KILL_BONUS,12
SKULL_RED_LERP_START13
SKULL_BLACK_MAX_DEFAULT,14
SKULL_RED_MAX_DEFAULT13
} from "../../shared/combat/skull.js";15
} from "../../shared/combat/skull.js";14
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";15
import { Component } from "../src/ecs/components.js";17
import { Component } from "../src/ecs/components.js";@@ -58,10 +60,12 @@ test("kill counter decays one point per second", () =>58
assert.deepEqual(decayKillCounter(2, 10_000), { killCounter: 0, consumedMs: 2000 });60
assert.deepEqual(decayKillCounter(2, 10_000), { killCounter: 0, consumedMs: 2000 });59
});61
});60
62
61
test("skull tint: invisible, white, red, dark red", () =>63
test("skull tint: invisible, white→black, black→red, dark red", () =>62
{64
{63
assert.equal(skullTintColor(0), null);65
assert.equal(skullTintColor(0), null);64
assert.deepEqual(skullTintColor(1), { r: 1, g: 1, b: 1 });66
const nearWhite = skullTintColor(1);67
assert.ok(nearWhite.r > 0.99 && nearWhite.g > 0.99 && nearWhite.b > 0.99);68
assert.deepEqual(skullTintColor(SKULL_BLACK_MAX_DEFAULT), { r: 0, g: 0, b: 0 });65
assert.deepEqual(skullTintColor(SKULL_PURE_RED_VALUE), { r: 1, g: 0, b: 0 });69
assert.deepEqual(skullTintColor(SKULL_PURE_RED_VALUE), { r: 1, g: 0, b: 0 });66
const dark = skullTintColor(SKULL_DARK_RED_VALUE);70
const dark = skullTintColor(SKULL_DARK_RED_VALUE);67
assert.ok(Math.abs(dark.r - 128 / 255) < 1e-9);71
assert.ok(Math.abs(dark.r - 128 / 255) < 1e-9);@@ -69,12 +73,27 @@ test("skull tint: invisible, white, red, dark red", () =>69
assert.equal(dark.b, 0);73
assert.equal(dark.b, 0);70
});74
});71
75
72
test("skull attracts town guards once tint starts lerping red", () =>76
test("skull thresholds honour world settings", () =>77
{78
const custom = { skullBlackMax: 100, skullRedMax: 1000 };79
assert.deepEqual(resolveSkullThresholds(custom), {80
blackMax: 100,81
redMax: 1000,82
darkRedMax: 200083
});84
assert.deepEqual(skullTintColor(100, custom), { r: 0, g: 0, b: 0 });85
assert.deepEqual(skullTintColor(1000, custom), { r: 1, g: 0, b: 0 });86
assert.equal(skullAttractsTownGuards(100, custom), false);87
assert.equal(skullAttractsTownGuards(101, custom), true);88
assert.equal(SKULL_RED_MAX_DEFAULT, SKULL_PURE_RED_VALUE);89
});90
91
test("skull attracts town guards once past black max (red lerp)", () =>73
{92
{74
assert.equal(skullAttractsTownGuards(0), false);93
assert.equal(skullAttractsTownGuards(0), false);75
assert.equal(skullAttractsTownGuards(SKULL_RED_LERP_START), false);94
assert.equal(skullAttractsTownGuards(SKULL_BLACK_MAX_DEFAULT), false);76
assert.equal(skullAttractsTownGuards(SKULL_RED_LERP_START + 1), true);95
assert.equal(skullAttractsTownGuards(SKULL_BLACK_MAX_DEFAULT + 1), true);77
assert.equal(skullAttractsTownGuards(SKULL_KILL_BONUS), true);96
assert.equal(skullAttractsTownGuards(SKULL_KILL_BONUS), false);78
});97
});79
98
80
test("PvP kill awards temporary skull points that replicate", () =>99
test("PvP kill awards temporary skull points that replicate", () =>@@ -15,7 +15,7 @@ import { mobComponents } from "../src/simulation/spawners.js";
15
15
import { Component } from "../src/ecs/components.js";
16
16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
17
17
import { ItemId } from "../../shared/definitions/items.js";
18
import { attackProfileOf } from "../src/combat/service.js";
18
import { attackProfileOf, applyDamageAndKill } from "../src/combat/service.js";
19
19
import { installDamagingCombatRng } from "./helpers/combatRng.js";
20
20
21
21
test("spawner config defaults bounty 0 and level 1", () =>
@@ -264,6 +264,22 @@ test("killing a bounty mob awards player bounty and can wake town guards", () =>
264
264
const guardHandle = worker.world.ecs.handleOf(guardId);
265
265
const guardCombat = worker.world.ecs.get(guardHandle, Component.combat);
266
266
assert.equal(guardCombat?.targetEntityId, playerId);
267
268
const playerHandle = worker.world.ecs.handleOf(playerId);
269
worker.world.ecs.get(playerHandle, Component.health).current = 1;
270
applyDamageAndKill(worker.world, guardId, playerId, 999, Date.now());
271
assert.ok(worker.world.ecs.has(playerHandle, Component.dead));
272
assert.equal(
273
worker.world.ecs.get(guardHandle, Component.combat)?.targetEntityId ?? null,
274
null,
275
"guard must drop the bounty-killer when they die"
276
);
277
harness.simulation.step();
278
assert.equal(
279
worker.world.ecs.get(guardHandle, Component.combat)?.targetEntityId ?? null,
280
null,
281
"guard must not re-aggro a dead player"
282
);
267
283
}
268
284
finally
269
285
{
@@ -15,7 +15,7 @@ import { mobComponents } from "../src/simulation/spawners.js";15
import { Component } from "../src/ecs/components.js";15
import { Component } from "../src/ecs/components.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";17
import { ItemId } from "../../shared/definitions/items.js";17
import { ItemId } from "../../shared/definitions/items.js";18
import { attackProfileOf } from "../src/combat/service.js";18
import { attackProfileOf, applyDamageAndKill } from "../src/combat/service.js";19
import { installDamagingCombatRng } from "./helpers/combatRng.js";19
import { installDamagingCombatRng } from "./helpers/combatRng.js";20
20
21
test("spawner config defaults bounty 0 and level 1", () =>21
test("spawner config defaults bounty 0 and level 1", () =>@@ -264,6 +264,22 @@ test("killing a bounty mob awards player bounty and can wake town guards", () =>264
const guardHandle = worker.world.ecs.handleOf(guardId);264
const guardHandle = worker.world.ecs.handleOf(guardId);265
const guardCombat = worker.world.ecs.get(guardHandle, Component.combat);265
const guardCombat = worker.world.ecs.get(guardHandle, Component.combat);266
assert.equal(guardCombat?.targetEntityId, playerId);266
assert.equal(guardCombat?.targetEntityId, playerId);267
268
const playerHandle = worker.world.ecs.handleOf(playerId);269
worker.world.ecs.get(playerHandle, Component.health).current = 1;270
applyDamageAndKill(worker.world, guardId, playerId, 999, Date.now());271
assert.ok(worker.world.ecs.has(playerHandle, Component.dead));272
assert.equal(273
worker.world.ecs.get(guardHandle, Component.combat)?.targetEntityId ?? null,274
null,275
"guard must drop the bounty-killer when they die"276
);277
harness.simulation.step();278
assert.equal(279
worker.world.ecs.get(guardHandle, Component.combat)?.targetEntityId ?? null,280
null,281
"guard must not re-aggro a dead player"282
);267
}283
}268
finally284
finally269
{285
{