BlueGit

timfa questward

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>

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
a5f0a420b4367abd0c802f8704def8176b94abd3
Parent
5c6a7c14
8 files changed +168 −33
client/src/render/worldView.js +1 −1
@@ -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 WorldView
3366 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();
server/src/combat/service.js +1 −1
@@ -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)
server/tests/combat.test.js +31 −2
@@ -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 try
627 try
628 {
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
655test("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
655test("town guards ignore players with white-only skull", () =>
684test("town guards ignore players with white-only skull", () =>
656{
685{
657 const harness = makeSimulation({ workerCount: 1 });
686 const harness = makeSimulation({ workerCount: 1 });
server/tests/skull.test.js +26 −7
@@ -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 @@ import
5 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_START
13 SKULL_BLACK_MAX_DEFAULT,
14 SKULL_RED_MAX_DEFAULT
13 } from "../../shared/combat/skull.js";
15 } from "../../shared/combat/skull.js";
14import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
16import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
15import { Component } from "../src/ecs/components.js";
17import { 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
61test("skull tint: invisible, white, red, dark red", () =>
63test("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
72test("skull attracts town guards once tint starts lerping red", () =>
76test("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
91test("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
80test("PvP kill awards temporary skull points that replicate", () =>
99test("PvP kill awards temporary skull points that replicate", () =>
server/tests/spawner-bounty.test.js +17 −1
@@ -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";
15import { Component } from "../src/ecs/components.js";
15import { Component } from "../src/ecs/components.js";
16import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
16import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
17import { ItemId } from "../../shared/definitions/items.js";
17import { ItemId } from "../../shared/definitions/items.js";
18import { attackProfileOf } from "../src/combat/service.js";
18import { attackProfileOf, applyDamageAndKill } from "../src/combat/service.js";
19import { installDamagingCombatRng } from "./helpers/combatRng.js";
19import { installDamagingCombatRng } from "./helpers/combatRng.js";
20
20
21test("spawner config defaults bounty 0 and level 1", () =>
21test("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 finally
284 finally
269 {
285 {
shared/combat/skull.js +66 −21
@@ -2,18 +2,26 @@
2 2
3 3 export const SKULL_KILL_BONUS = 500;
4 4 export const SKULL_DECAY_PER_SECOND = 1;
5
5 6 /**
6 * Tint stays white at this value; above it, color lerps toward red.
7 * Town guards treat players above this as hostiles (same as aggressive mobs).
7 * Default skull value at pure black. White→black below this; red lerp (and
8 * town-guard hostility) start strictly above it.
9 * Overridable via world setting `skullBlackMax`.
8 10 */
9 export const SKULL_RED_LERP_START = 1;
10 /** Skull value at which tint is pure red. */
11 export const SKULL_PURE_RED_VALUE = 500_000;
11 export const SKULL_BLACK_MAX_DEFAULT = 500;
12 12 /**
13 * Past pure red, tint reaches dark red (128,0,0) at this value and clamps.
14 * Same span as white→red (500k).
13 * Default skull value at pure red. Black→red between black max and this;
14 * beyond it, tint leans toward dark red.
15 * Overridable via world setting `skullRedMax`.
15 16 */
16 export const SKULL_DARK_RED_VALUE = 1_000_000;
17 export const SKULL_RED_MAX_DEFAULT = 500_000;
18
19 /** @deprecated Use {@link SKULL_BLACK_MAX_DEFAULT}. */
20 export const SKULL_RED_LERP_START = SKULL_BLACK_MAX_DEFAULT;
21 /** @deprecated Use {@link SKULL_RED_MAX_DEFAULT}. */
22 export const SKULL_PURE_RED_VALUE = SKULL_RED_MAX_DEFAULT;
23 /** @deprecated Dark-red clamp is derived as 2× red max. */
24 export const SKULL_DARK_RED_VALUE = SKULL_RED_MAX_DEFAULT * 2;
17 25
18 26 /**
19 27 * @param {number} bountyCopper
@@ -24,10 +32,39 @@ export function skullValue (bountyCopper, killCounter)
24 32 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
25 33 }
26 34
27 /** True once the skull tint starts lerping from white toward red. */
28 export function skullAttractsTownGuards (value)
35 /**
36 * Resolve tint / guard thresholds from world settings (falls back to defaults).
37 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} settings
38 */
39 export function resolveSkullThresholds (settings = null)
29 40 {
30 return Math.max(0, Math.floor(Number(value) || 0)) > SKULL_RED_LERP_START;
41 const blackMax = Math.max(
42 1,
43 Math.floor(Number(settings?.skullBlackMax) || SKULL_BLACK_MAX_DEFAULT)
44 );
45 let redMax = Math.max(
46 1,
47 Math.floor(Number(settings?.skullRedMax) || SKULL_RED_MAX_DEFAULT)
48 );
49 if (redMax <= blackMax)
50 { redMax = blackMax + 1; }
51 return {
52 blackMax,
53 redMax,
54 darkRedMax: redMax * 2
55 };
56 }
57
58 /**
59 * True once the skull tint starts lerping from black toward red
60 * (skull value strictly above black max).
61 * @param {number} value
62 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} [settings]
63 */
64 export function skullAttractsTownGuards (value, settings = null)
65 {
66 const { blackMax } = resolveSkullThresholds(settings);
67 return Math.max(0, Math.floor(Number(value) || 0)) > blackMax;
31 68 }
32 69
33 70 /**
@@ -53,26 +90,34 @@ function lerp (a, b, t)
53 90
54 91 /**
55 92 * Magenta-tint target color for a skull value (0 = invisible / unused).
56 * 1 → white; … → pure red at 500_000; then → dark red (128,0,0) by 1_000_000.
93 * 1…blackMax → white→black; …→ pure red at redMax; then → dark red (128,0,0).
94 * @param {number} value
95 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} [settings]
57 96 * @returns {{ r: number, g: number, b: number } | null} 0–1 channels, or null if invisible
58 97 */
59 export function skullTintColor (value)
98 export function skullTintColor (value, settings = null)
60 99 {
61 100 const v = Math.max(0, Math.floor(Number(value) || 0));
62 101 if (v <= 0)
63 102 { return null; }
64 if (v <= SKULL_RED_LERP_START)
65 { return Object.freeze({ r: 1, g: 1, b: 1 }); }
66 if (v <= SKULL_PURE_RED_VALUE)
103 const { blackMax, redMax, darkRedMax } = resolveSkullThresholds(settings);
104 if (v <= blackMax)
105 {
106 const t = v / blackMax;
107 const c = lerp(1, 0, t);
108 return Object.freeze({ r: c, g: c, b: c });
109 }
110 if (v <= redMax)
67 111 {
68 const t = (v - SKULL_RED_LERP_START) / (SKULL_PURE_RED_VALUE - SKULL_RED_LERP_START);
112 // Black (0,0,0) → pure red (1,0,0).
113 const t = (v - blackMax) / (redMax - blackMax);
69 114 return Object.freeze({
70 r: 1,
71 g: lerp(1, 0, t),
72 b: lerp(1, 0, t)
115 r: lerp(0, 1, t),
116 g: 0,
117 b: 0
73 118 });
74 119 }
75 const t = Math.min(1, (v - SKULL_PURE_RED_VALUE) / (SKULL_DARK_RED_VALUE - SKULL_PURE_RED_VALUE));
120 const t = Math.min(1, (v - redMax) / (darkRedMax - redMax));
76 121 const dark = 128 / 255;
77 122 return Object.freeze({
78 123 r: lerp(1, dark, t),
@@ -2,18 +2,26 @@
2
2
3export const SKULL_KILL_BONUS = 500;
3export const SKULL_KILL_BONUS = 500;
4export const SKULL_DECAY_PER_SECOND = 1;
4export const SKULL_DECAY_PER_SECOND = 1;
5
5/**
6/**
6 * Tint stays white at this value; above it, color lerps toward red.
7 * Default skull value at pure black. White→black below this; red lerp (and
7 * Town guards treat players above this as hostiles (same as aggressive mobs).
8 * town-guard hostility) start strictly above it.
9 * Overridable via world setting `skullBlackMax`.
8 */
10 */
9export const SKULL_RED_LERP_START = 1;
11export const SKULL_BLACK_MAX_DEFAULT = 500;
10/** Skull value at which tint is pure red. */
11export const SKULL_PURE_RED_VALUE = 500_000;
12/**
12/**
13 * Past pure red, tint reaches dark red (128,0,0) at this value and clamps.
13 * Default skull value at pure red. Black→red between black max and this;
14 * Same span as white→red (500k).
14 * beyond it, tint leans toward dark red.
15 * Overridable via world setting `skullRedMax`.
15 */
16 */
16export const SKULL_DARK_RED_VALUE = 1_000_000;
17export const SKULL_RED_MAX_DEFAULT = 500_000;
18
19/** @deprecated Use {@link SKULL_BLACK_MAX_DEFAULT}. */
20export const SKULL_RED_LERP_START = SKULL_BLACK_MAX_DEFAULT;
21/** @deprecated Use {@link SKULL_RED_MAX_DEFAULT}. */
22export const SKULL_PURE_RED_VALUE = SKULL_RED_MAX_DEFAULT;
23/** @deprecated Dark-red clamp is derived as 2× red max. */
24export const SKULL_DARK_RED_VALUE = SKULL_RED_MAX_DEFAULT * 2;
17
25
18/**
26/**
19 * @param {number} bountyCopper
27 * @param {number} bountyCopper
@@ -24,10 +32,39 @@ export function skullValue (bountyCopper, killCounter)
24 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
32 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
25}
33}
26
34
27/** True once the skull tint starts lerping from white toward red. */
35/**
28export function skullAttractsTownGuards (value)
36 * Resolve tint / guard thresholds from world settings (falls back to defaults).
37 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} settings
38 */
39export function resolveSkullThresholds (settings = null)
29{
40{
30 return Math.max(0, Math.floor(Number(value) || 0)) > SKULL_RED_LERP_START;
41 const blackMax = Math.max(
42 1,
43 Math.floor(Number(settings?.skullBlackMax) || SKULL_BLACK_MAX_DEFAULT)
44 );
45 let redMax = Math.max(
46 1,
47 Math.floor(Number(settings?.skullRedMax) || SKULL_RED_MAX_DEFAULT)
48 );
49 if (redMax <= blackMax)
50 { redMax = blackMax + 1; }
51 return {
52 blackMax,
53 redMax,
54 darkRedMax: redMax * 2
55 };
56}
57
58/**
59 * True once the skull tint starts lerping from black toward red
60 * (skull value strictly above black max).
61 * @param {number} value
62 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} [settings]
63 */
64export function skullAttractsTownGuards (value, settings = null)
65{
66 const { blackMax } = resolveSkullThresholds(settings);
67 return Math.max(0, Math.floor(Number(value) || 0)) > blackMax;
31}
68}
32
69
33/**
70/**
@@ -53,26 +90,34 @@ function lerp (a, b, t)
53
90
54/**
91/**
55 * Magenta-tint target color for a skull value (0 = invisible / unused).
92 * Magenta-tint target color for a skull value (0 = invisible / unused).
56 * 1 → white; … → pure red at 500_000; then → dark red (128,0,0) by 1_000_000.
93 * 1…blackMax → white→black; …→ pure red at redMax; then → dark red (128,0,0).
94 * @param {number} value
95 * @param {{ skullBlackMax?: number, skullRedMax?: number } | null | undefined} [settings]
57 * @returns {{ r: number, g: number, b: number } | null} 0–1 channels, or null if invisible
96 * @returns {{ r: number, g: number, b: number } | null} 0–1 channels, or null if invisible
58 */
97 */
59export function skullTintColor (value)
98export function skullTintColor (value, settings = null)
60{
99{
61 const v = Math.max(0, Math.floor(Number(value) || 0));
100 const v = Math.max(0, Math.floor(Number(value) || 0));
62 if (v <= 0)
101 if (v <= 0)
63 { return null; }
102 { return null; }
64 if (v <= SKULL_RED_LERP_START)
103 const { blackMax, redMax, darkRedMax } = resolveSkullThresholds(settings);
65 { return Object.freeze({ r: 1, g: 1, b: 1 }); }
104 if (v <= blackMax)
66 if (v <= SKULL_PURE_RED_VALUE)
105 {
106 const t = v / blackMax;
107 const c = lerp(1, 0, t);
108 return Object.freeze({ r: c, g: c, b: c });
109 }
110 if (v <= redMax)
67 {
111 {
68 const t = (v - SKULL_RED_LERP_START) / (SKULL_PURE_RED_VALUE - SKULL_RED_LERP_START);
112 // Black (0,0,0) → pure red (1,0,0).
113 const t = (v - blackMax) / (redMax - blackMax);
69 return Object.freeze({
114 return Object.freeze({
70 r: 1,
115 r: lerp(0, 1, t),
71 g: lerp(1, 0, t),
116 g: 0,
72 b: lerp(1, 0, t)
117 b: 0
73 });
118 });
74 }
119 }
75 const t = Math.min(1, (v - SKULL_PURE_RED_VALUE) / (SKULL_DARK_RED_VALUE - SKULL_PURE_RED_VALUE));
120 const t = Math.min(1, (v - redMax) / (darkRedMax - redMax));
76 const dark = 128 / 255;
121 const dark = 128 / 255;
77 return Object.freeze({
122 return Object.freeze({
78 r: lerp(1, dark, t),
123 r: lerp(1, dark, t),
shared/definitions/worldSettings.js +22 −0
@@ -165,6 +165,28 @@ export const WORLD_SETTING_CATEGORIES = [
165 165 }
166 166 ]
167 167 },
168 {
169 id: "combat",
170 label: "Combat",
171 fields: [
172 {
173 key: "skullBlackMax",
174 label: "Skull black max",
175 hint: "Skull score at pure black. Below this, tint lerps white→black. Above this, town guards treat the player as hostile and tint lerps toward red.",
176 type: "number",
177 min: 1,
178 step: 1
179 },
180 {
181 key: "skullRedMax",
182 label: "Skull red max",
183 hint: "Skull score at pure red. Between black max and this, tint lerps black→red; beyond it, toward dark red (clamped at 2× this value).",
184 type: "number",
185 min: 1,
186 step: 1
187 }
188 ]
189 },
168 190 {
169 191 id: "starterEquipment",
170 192 label: "Starter Equipment",
@@ -165,6 +165,28 @@ export const WORLD_SETTING_CATEGORIES = [
165 }
165 }
166 ]
166 ]
167 },
167 },
168 {
169 id: "combat",
170 label: "Combat",
171 fields: [
172 {
173 key: "skullBlackMax",
174 label: "Skull black max",
175 hint: "Skull score at pure black. Below this, tint lerps white→black. Above this, town guards treat the player as hostile and tint lerps toward red.",
176 type: "number",
177 min: 1,
178 step: 1
179 },
180 {
181 key: "skullRedMax",
182 label: "Skull red max",
183 hint: "Skull score at pure red. Between black max and this, tint lerps black→red; beyond it, toward dark red (clamped at 2× this value).",
184 type: "number",
185 min: 1,
186 step: 1
187 }
188 ]
189 },
168 {
190 {
169 id: "starterEquipment",
191 id: "starterEquipment",
170 label: "Starter Equipment",
192 label: "Starter Equipment",
shared/protocol/constants.js +4 −0
@@ -66,6 +66,10 @@ export const DEFAULT_WORLD_SETTINGS = Object.freeze({
66 66 pigeonCruiseTilesPerSec: 8,
67 67 pigeonLandingTilesPerSec: 3,
68 68 pigeonPhaseTiles: 5,
69 /** Skull value at pure black (white→black below; guards aggro above). */
70 skullBlackMax: 500,
71 /** Skull value at pure red (black→red below; dark red beyond, up to 2×). */
72 skullRedMax: 500_000,
69 73 /** New characters only: equipment slot → itemId (or null). */
70 74 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
71 75 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */
@@ -66,6 +66,10 @@ export const DEFAULT_WORLD_SETTINGS = Object.freeze({
66 pigeonCruiseTilesPerSec: 8,
66 pigeonCruiseTilesPerSec: 8,
67 pigeonLandingTilesPerSec: 3,
67 pigeonLandingTilesPerSec: 3,
68 pigeonPhaseTiles: 5,
68 pigeonPhaseTiles: 5,
69 /** Skull value at pure black (white→black below; guards aggro above). */
70 skullBlackMax: 500,
71 /** Skull value at pure red (black→red below; dark red beyond, up to 2×). */
72 skullRedMax: 500_000,
69 /** New characters only: equipment slot → itemId (or null). */
73 /** New characters only: equipment slot → itemId (or null). */
70 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
74 starterEquipment: DEFAULT_STARTER_EQUIPMENT,
71 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */
75 /** New characters only: inventory stacks `{ itemId, quantity }[]`. */