BlueGit

timfa questward

Make town guards auto-aggro players once skull tint lerps toward red.

timfa Tim Falken · pushed by timfa

Authored 2026-09-03 · 2 months ago

Hash
be99c31064c9ab53172e42700cec4c97cd018910
Parent
afc8cc08
7 files changed +134 −9
server/src/combat/service.js +20 −4
@@ -18,6 +18,7 @@ import {
18 18 playerOutlevelsMobAggression
19 19 } from "../../../shared/combat/combatLevel.js";
20 20 import { chunkPeaceAggressionImmunity } from "../../../shared/navigation/chunkPresence.js";
21 import { skullAttractsTownGuards } from "../../../shared/combat/skull.js";
21 22 import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
22 23 import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
23 24 import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
@@ -692,7 +693,8 @@ function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
692 693
693 694 /**
694 695 * Aggressive mobs auto-engage the nearest player or town guard within aggro range
695 * when they have line of sight. Town guards auto-engage aggressive creatures.
696 * when they have line of sight. Town guards auto-engage aggressive creatures and
697 * players whose skull tint has started lerping toward red.
696 698 * Does nothing while already engaged.
697 699 */
698 700 export function stepAggression (world, now = Date.now())
@@ -722,7 +724,7 @@ export function stepAggression (world, now = Date.now())
722 724
723 725 const range = mobAggroRangeTiles(def);
724 726 const bestId = townGuard
725 ? pickAggressionTargetAggressiveMob(world, entity, range)
727 ? pickAggressionTargetForTownGuard(world, entity, range)
726 728 : pickAggressionTargetPlayerOrGuard(world, entity, range, now);
727 729 if (bestId == null)
728 730 { continue; }
@@ -817,8 +819,11 @@ function playerIgnoresAggressiveMob (world, mobEntity, playerHandle, now)
817 819 );
818 820 }
819 821
820 /** Nearest aggressive hostile creature in range with LOS (for town guards). */
821 function pickAggressionTargetAggressiveMob (world, entity, range)
822 /**
823 * Nearest aggressive hostile creature or red-lerping skulled player in range
824 * with LOS (for town guards).
825 */
826 function pickAggressionTargetForTownGuard (world, entity, range)
822 827 {
823 828 let bestId = null;
824 829 let bestDist = Infinity;
@@ -837,6 +842,17 @@ function pickAggressionTargetAggressiveMob (world, entity, range)
837 842 bestId = other.entityId;
838 843 }
839 844 }
845 for (const player of world.ecs.query(Component.character, Component.position))
846 {
847 if (!skullAttractsTownGuards(player.character?.skullValue))
848 { continue; }
849 const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);
850 if (dist != null && dist < bestDist)
851 {
852 bestDist = dist;
853 bestId = player.entityId;
854 }
855 }
840 856 return bestId;
841 857 }
842 858
@@ -18,6 +18,7 @@ import {
18 playerOutlevelsMobAggression
18 playerOutlevelsMobAggression
19} from "../../../shared/combat/combatLevel.js";
19} from "../../../shared/combat/combatLevel.js";
20import { chunkPeaceAggressionImmunity } from "../../../shared/navigation/chunkPresence.js";
20import { chunkPeaceAggressionImmunity } from "../../../shared/navigation/chunkPresence.js";
21import { skullAttractsTownGuards } from "../../../shared/combat/skull.js";
21import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
22import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
22import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
23import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
23import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
24import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
@@ -692,7 +693,8 @@ function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
692
693
693/**
694/**
694 * Aggressive mobs auto-engage the nearest player or town guard within aggro range
695 * Aggressive mobs auto-engage the nearest player or town guard within aggro range
695 * when they have line of sight. Town guards auto-engage aggressive creatures.
696 * when they have line of sight. Town guards auto-engage aggressive creatures and
697 * players whose skull tint has started lerping toward red.
696 * Does nothing while already engaged.
698 * Does nothing while already engaged.
697 */
699 */
698export function stepAggression (world, now = Date.now())
700export function stepAggression (world, now = Date.now())
@@ -722,7 +724,7 @@ export function stepAggression (world, now = Date.now())
722
724
723 const range = mobAggroRangeTiles(def);
725 const range = mobAggroRangeTiles(def);
724 const bestId = townGuard
726 const bestId = townGuard
725 ? pickAggressionTargetAggressiveMob(world, entity, range)
727 ? pickAggressionTargetForTownGuard(world, entity, range)
726 : pickAggressionTargetPlayerOrGuard(world, entity, range, now);
728 : pickAggressionTargetPlayerOrGuard(world, entity, range, now);
727 if (bestId == null)
729 if (bestId == null)
728 { continue; }
730 { continue; }
@@ -817,8 +819,11 @@ function playerIgnoresAggressiveMob (world, mobEntity, playerHandle, now)
817 );
819 );
818}
820}
819
821
820/** Nearest aggressive hostile creature in range with LOS (for town guards). */
822/**
821function pickAggressionTargetAggressiveMob (world, entity, range)
823 * Nearest aggressive hostile creature or red-lerping skulled player in range
824 * with LOS (for town guards).
825 */
826function pickAggressionTargetForTownGuard (world, entity, range)
822{
827{
823 let bestId = null;
828 let bestId = null;
824 let bestDist = Infinity;
829 let bestDist = Infinity;
@@ -837,6 +842,17 @@ function pickAggressionTargetAggressiveMob (world, entity, range)
837 bestId = other.entityId;
842 bestId = other.entityId;
838 }
843 }
839 }
844 }
845 for (const player of world.ecs.query(Component.character, Component.position))
846 {
847 if (!skullAttractsTownGuards(player.character?.skullValue))
848 { continue; }
849 const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);
850 if (dist != null && dist < bestDist)
851 {
852 bestDist = dist;
853 bestId = player.entityId;
854 }
855 }
840 return bestId;
856 return bestId;
841}
857}
842
858
server/src/simulation/protocol.js +1 −0
@@ -42,6 +42,7 @@ export const WorkerMessage = Object.freeze({
42 42 stationExchangeClerk: "stationExchangeClerk",
43 43 releaseExchangeClerk: "releaseExchangeClerk",
44 44 applyAppearance: "applyAppearance",
45 applySkullValue: "applySkullValue",
45 46 engageTarget: "engageTarget",
46 47 listTownGuardsNear: "listTownGuardsNear",
47 48 pinDialogue: "pinDialogue",
@@ -42,6 +42,7 @@ export const WorkerMessage = Object.freeze({
42 stationExchangeClerk: "stationExchangeClerk",
42 stationExchangeClerk: "stationExchangeClerk",
43 releaseExchangeClerk: "releaseExchangeClerk",
43 releaseExchangeClerk: "releaseExchangeClerk",
44 applyAppearance: "applyAppearance",
44 applyAppearance: "applyAppearance",
45 applySkullValue: "applySkullValue",
45 engageTarget: "engageTarget",
46 engageTarget: "engageTarget",
46 listTownGuardsNear: "listTownGuardsNear",
47 listTownGuardsNear: "listTownGuardsNear",
47 pinDialogue: "pinDialogue",
48 pinDialogue: "pinDialogue",
server/src/simulation/simulation.js +14 −2
@@ -461,7 +461,8 @@ export class Simulation
461 461 },
462 462 character: {
463 463 characterId: character.character_id ?? row.character_id,
464 accountId: character.account_id ?? row.account_id
464 accountId: character.account_id ?? row.account_id,
465 skullValue: this.characterSkullValue(character.character_id ?? row.character_id)
465 466 },
466 467 networkIdentity: { sessionId },
467 468 chunkLoader: { ...DEFAULT_CHUNK_LOADER },
@@ -536,6 +537,11 @@ export class Simulation
536 537 if (!force && (record.skullValue | 0) === value)
537 538 { return null; }
538 539 record.skullValue = value;
540 this.workers[record.workerId]?.call({
541 type: WorkerMessage.applySkullValue,
542 entityId,
543 skullValue: value
544 });
539 545 const event = {
540 546 type: "entity-skull",
541 547 entityId,
@@ -553,7 +559,13 @@ export class Simulation
553 559 const record = this.directory.get(entityId);
554 560 if (!record)
555 561 { return; }
556 record.skullValue = this.characterSkullValue(characterId);
562 const value = this.characterSkullValue(characterId);
563 record.skullValue = value;
564 this.workers[record.workerId]?.call({
565 type: WorkerMessage.applySkullValue,
566 entityId,
567 skullValue: value
568 });
557 569 }
558 570
559 571 #stepSkullDecay ()
@@ -461,7 +461,8 @@ export class Simulation
461 },
461 },
462 character: {
462 character: {
463 characterId: character.character_id ?? row.character_id,
463 characterId: character.character_id ?? row.character_id,
464 accountId: character.account_id ?? row.account_id
464 accountId: character.account_id ?? row.account_id,
465 skullValue: this.characterSkullValue(character.character_id ?? row.character_id)
465 },
466 },
466 networkIdentity: { sessionId },
467 networkIdentity: { sessionId },
467 chunkLoader: { ...DEFAULT_CHUNK_LOADER },
468 chunkLoader: { ...DEFAULT_CHUNK_LOADER },
@@ -536,6 +537,11 @@ export class Simulation
536 if (!force && (record.skullValue | 0) === value)
537 if (!force && (record.skullValue | 0) === value)
537 { return null; }
538 { return null; }
538 record.skullValue = value;
539 record.skullValue = value;
540 this.workers[record.workerId]?.call({
541 type: WorkerMessage.applySkullValue,
542 entityId,
543 skullValue: value
544 });
539 const event = {
545 const event = {
540 type: "entity-skull",
546 type: "entity-skull",
541 entityId,
547 entityId,
@@ -553,7 +559,13 @@ export class Simulation
553 const record = this.directory.get(entityId);
559 const record = this.directory.get(entityId);
554 if (!record)
560 if (!record)
555 { return; }
561 { return; }
556 record.skullValue = this.characterSkullValue(characterId);
562 const value = this.characterSkullValue(characterId);
563 record.skullValue = value;
564 this.workers[record.workerId]?.call({
565 type: WorkerMessage.applySkullValue,
566 entityId,
567 skullValue: value
568 });
557 }
569 }
558
570
559 #stepSkullDecay ()
571 #stepSkullDecay ()
server/src/simulation/workerWorld.js +14 −0
@@ -176,6 +176,8 @@ export class WorkerWorld
176 176 return this.#applyBag(message.entityId, message.bag);
177 177 case WorkerMessage.applyAppearance:
178 178 return this.#applyAppearance(message.entityId, message.appearance);
179 case WorkerMessage.applySkullValue:
180 return this.#applySkullValue(message.entityId, message.skullValue);
179 181 case WorkerMessage.engageTarget:
180 182 return this.#engageTargetMessage(message);
181 183 case WorkerMessage.listTownGuardsNear:
@@ -845,6 +847,18 @@ export class WorkerWorld
845 847 return publicEntityView(this.ecs, entityId);
846 848 }
847 849
850 #applySkullValue (entityId, skullValue)
851 {
852 const handle = this.ecs.handleOf(entityId);
853 if (handle == null)
854 { return null; }
855 const character = this.ecs.get(handle, Component.character);
856 if (!character)
857 { return null; }
858 character.skullValue = Math.max(0, skullValue | 0);
859 return { ok: true, skullValue: character.skullValue };
860 }
861
848 862 #updateFlight (entityId, flightPatch, now = Date.now())
849 863 {
850 864 const handle = this.ecs.handleOf(entityId);
@@ -176,6 +176,8 @@ export class WorkerWorld
176 return this.#applyBag(message.entityId, message.bag);
176 return this.#applyBag(message.entityId, message.bag);
177 case WorkerMessage.applyAppearance:
177 case WorkerMessage.applyAppearance:
178 return this.#applyAppearance(message.entityId, message.appearance);
178 return this.#applyAppearance(message.entityId, message.appearance);
179 case WorkerMessage.applySkullValue:
180 return this.#applySkullValue(message.entityId, message.skullValue);
179 case WorkerMessage.engageTarget:
181 case WorkerMessage.engageTarget:
180 return this.#engageTargetMessage(message);
182 return this.#engageTargetMessage(message);
181 case WorkerMessage.listTownGuardsNear:
183 case WorkerMessage.listTownGuardsNear:
@@ -845,6 +847,18 @@ export class WorkerWorld
845 return publicEntityView(this.ecs, entityId);
847 return publicEntityView(this.ecs, entityId);
846 }
848 }
847
849
850 #applySkullValue (entityId, skullValue)
851 {
852 const handle = this.ecs.handleOf(entityId);
853 if (handle == null)
854 { return null; }
855 const character = this.ecs.get(handle, Component.character);
856 if (!character)
857 { return null; }
858 character.skullValue = Math.max(0, skullValue | 0);
859 return { ok: true, skullValue: character.skullValue };
860 }
861
848 #updateFlight (entityId, flightPatch, now = Date.now())
862 #updateFlight (entityId, flightPatch, now = Date.now())
849 {
863 {
850 const handle = this.ecs.handleOf(entityId);
864 const handle = this.ecs.handleOf(entityId);
server/tests/combat.test.js +61 −0
@@ -16,6 +16,7 @@ import { SpellId } from "../../shared/definitions/spells.js";
16 16 import { totalXpForLevel } from "../../shared/skills/progression.js";
17 17 import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";
18 18 import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
19 import { SKULL_KILL_BONUS } from "../../shared/combat/skull.js";
19 20 import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
20 21 import { withDamagingCombatRng, installDamagingCombatRng, installMissDodgeRng, installBlockRng } from "./helpers/combatRng.js";
21 22
@@ -589,6 +590,66 @@ test("aggressive mobs and town guards aggro each other", () =>
589 590 { harness.close(); }
590 591 });
591 592
593 test("town guards aggro players whose skull tint lerps toward red", () =>
594 {
595 const harness = makeSimulation({ workerCount: 1 });
596 try
597 {
598 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
599 harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());
600 const playerId = harness.simulation.spawnCharacter(1, character);
601 assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);
602
603 const guardId = harness.simulation.spawnEntity(mobComponents({
604 tileX: 10,
605 tileY: 8,
606 mobTypeId: MobId.townGuard,
607 spawnerId: "0:0:guard",
608 originTileX: 10,
609 originTileY: 8,
610 wanderRangeTiles: 8,
611 level: 10
612 }));
613
614 harness.simulation.step();
615 assert.equal(
616 componentsOf(harness.simulation, guardId).combat?.targetEntityId,
617 playerId
618 );
619 }
620 finally
621 { harness.close(); }
622 });
623
624 test("town guards ignore players with white-only skull", () =>
625 {
626 const harness = makeSimulation({ workerCount: 1 });
627 try
628 {
629 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
630 harness.stateDb.setKillCounter(character.character_id, 1, harness.now());
631 const playerId = harness.simulation.spawnCharacter(1, character);
632 assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, 1);
633
634 const guardId = harness.simulation.spawnEntity(mobComponents({
635 tileX: 10,
636 tileY: 8,
637 mobTypeId: MobId.townGuard,
638 spawnerId: "0:0:guard",
639 originTileX: 10,
640 originTileY: 8,
641 wanderRangeTiles: 8,
642 level: 10
643 }));
644
645 harness.simulation.step();
646 assert.equal(componentsOf(harness.simulation, guardId).combat?.targetEntityId, null);
647 assert.equal(componentsOf(harness.simulation, playerId).combat?.targetEntityId, null);
648 }
649 finally
650 { harness.close(); }
651 });
652
592 653 test("spawner mobs far from home path chunk-step toward the origin", () =>
593 654 {
594 655 const harness = makeSimulation({ workerCount: 1, maxChunkX: 5 });
@@ -16,6 +16,7 @@ import { SpellId } from "../../shared/definitions/spells.js";
16import { totalXpForLevel } from "../../shared/skills/progression.js";
16import { totalXpForLevel } from "../../shared/skills/progression.js";
17import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";
17import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";
18import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
18import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
19import { SKULL_KILL_BONUS } from "../../shared/combat/skull.js";
19import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
20import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
20import { withDamagingCombatRng, installDamagingCombatRng, installMissDodgeRng, installBlockRng } from "./helpers/combatRng.js";
21import { withDamagingCombatRng, installDamagingCombatRng, installMissDodgeRng, installBlockRng } from "./helpers/combatRng.js";
21
22
@@ -589,6 +590,66 @@ test("aggressive mobs and town guards aggro each other", () =>
589 { harness.close(); }
590 { harness.close(); }
590});
591});
591
592
593test("town guards aggro players whose skull tint lerps toward red", () =>
594{
595 const harness = makeSimulation({ workerCount: 1 });
596 try
597 {
598 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
599 harness.stateDb.addKillCounter(character.character_id, SKULL_KILL_BONUS, harness.now());
600 const playerId = harness.simulation.spawnCharacter(1, character);
601 assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, SKULL_KILL_BONUS);
602
603 const guardId = harness.simulation.spawnEntity(mobComponents({
604 tileX: 10,
605 tileY: 8,
606 mobTypeId: MobId.townGuard,
607 spawnerId: "0:0:guard",
608 originTileX: 10,
609 originTileY: 8,
610 wanderRangeTiles: 8,
611 level: 10
612 }));
613
614 harness.simulation.step();
615 assert.equal(
616 componentsOf(harness.simulation, guardId).combat?.targetEntityId,
617 playerId
618 );
619 }
620 finally
621 { harness.close(); }
622});
623
624test("town guards ignore players with white-only skull", () =>
625{
626 const harness = makeSimulation({ workerCount: 1 });
627 try
628 {
629 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
630 harness.stateDb.setKillCounter(character.character_id, 1, harness.now());
631 const playerId = harness.simulation.spawnCharacter(1, character);
632 assert.equal(componentsOf(harness.simulation, playerId).character?.skullValue, 1);
633
634 const guardId = harness.simulation.spawnEntity(mobComponents({
635 tileX: 10,
636 tileY: 8,
637 mobTypeId: MobId.townGuard,
638 spawnerId: "0:0:guard",
639 originTileX: 10,
640 originTileY: 8,
641 wanderRangeTiles: 8,
642 level: 10
643 }));
644
645 harness.simulation.step();
646 assert.equal(componentsOf(harness.simulation, guardId).combat?.targetEntityId, null);
647 assert.equal(componentsOf(harness.simulation, playerId).combat?.targetEntityId, null);
648 }
649 finally
650 { harness.close(); }
651});
652
592test("spawner mobs far from home path chunk-step toward the origin", () =>
653test("spawner mobs far from home path chunk-step toward the origin", () =>
593{
654{
594 const harness = makeSimulation({ workerCount: 1, maxChunkX: 5 });
655 const harness = makeSimulation({ workerCount: 1, maxChunkX: 5 });
server/tests/skull.test.js +11 −1
@@ -4,10 +4,12 @@ import
4 4 {
5 5 skullValue,
6 6 skullTintColor,
7 skullAttractsTownGuards,
7 8 decayKillCounter,
8 9 SKULL_PURE_RED_VALUE,
9 10 SKULL_DARK_RED_VALUE,
10 SKULL_KILL_BONUS
11 SKULL_KILL_BONUS,
12 SKULL_RED_LERP_START
11 13 } from "../../shared/combat/skull.js";
12 14 import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
13 15 import { Component } from "../src/ecs/components.js";
@@ -67,6 +69,14 @@ test("skull tint: invisible, white, red, dark red", () =>
67 69 assert.equal(dark.b, 0);
68 70 });
69 71
72 test("skull attracts town guards once tint starts lerping red", () =>
73 {
74 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);
78 });
79
70 80 test("PvP kill awards temporary skull points that replicate", () =>
71 81 {
72 82 const random = Math.random;
@@ -4,10 +4,12 @@ import
4 {
4 {
5 skullValue,
5 skullValue,
6 skullTintColor,
6 skullTintColor,
7 skullAttractsTownGuards,
7 decayKillCounter,
8 decayKillCounter,
8 SKULL_PURE_RED_VALUE,
9 SKULL_PURE_RED_VALUE,
9 SKULL_DARK_RED_VALUE,
10 SKULL_DARK_RED_VALUE,
10 SKULL_KILL_BONUS
11 SKULL_KILL_BONUS,
12 SKULL_RED_LERP_START
11 } from "../../shared/combat/skull.js";
13 } from "../../shared/combat/skull.js";
12import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
14import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
13import { Component } from "../src/ecs/components.js";
15import { Component } from "../src/ecs/components.js";
@@ -67,6 +69,14 @@ test("skull tint: invisible, white, red, dark red", () =>
67 assert.equal(dark.b, 0);
69 assert.equal(dark.b, 0);
68});
70});
69
71
72test("skull attracts town guards once tint starts lerping red", () =>
73{
74 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);
78});
79
70test("PvP kill awards temporary skull points that replicate", () =>
80test("PvP kill awards temporary skull points that replicate", () =>
71{
81{
72 const random = Math.random;
82 const random = Math.random;
shared/combat/skull.js +13 −2
@@ -2,6 +2,11 @@
2 2
3 3 export const SKULL_KILL_BONUS = 500;
4 4 export const SKULL_DECAY_PER_SECOND = 1;
5 /**
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).
8 */
9 export const SKULL_RED_LERP_START = 1;
5 10 /** Skull value at which tint is pure red. */
6 11 export const SKULL_PURE_RED_VALUE = 500_000;
7 12 /**
@@ -19,6 +24,12 @@ export function skullValue (bountyCopper, killCounter)
19 24 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
20 25 }
21 26
27 /** True once the skull tint starts lerping from white toward red. */
28 export function skullAttractsTownGuards (value)
29 {
30 return Math.max(0, Math.floor(Number(value) || 0)) > SKULL_RED_LERP_START;
31 }
32
22 33 /**
23 34 * Decay kill counter by elapsed wall time (1 point / second).
24 35 * @returns {{ killCounter: number, consumedMs: number }}
@@ -50,11 +61,11 @@ export function skullTintColor (value)
50 61 const v = Math.max(0, Math.floor(Number(value) || 0));
51 62 if (v <= 0)
52 63 { return null; }
53 if (v <= 1)
64 if (v <= SKULL_RED_LERP_START)
54 65 { return Object.freeze({ r: 1, g: 1, b: 1 }); }
55 66 if (v <= SKULL_PURE_RED_VALUE)
56 67 {
57 const t = (v - 1) / (SKULL_PURE_RED_VALUE - 1);
68 const t = (v - SKULL_RED_LERP_START) / (SKULL_PURE_RED_VALUE - SKULL_RED_LERP_START);
58 69 return Object.freeze({
59 70 r: 1,
60 71 g: lerp(1, 0, t),
@@ -2,6 +2,11 @@
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/**
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).
8 */
9export const SKULL_RED_LERP_START = 1;
5/** Skull value at which tint is pure red. */
10/** Skull value at which tint is pure red. */
6export const SKULL_PURE_RED_VALUE = 500_000;
11export const SKULL_PURE_RED_VALUE = 500_000;
7/**
12/**
@@ -19,6 +24,12 @@ export function skullValue (bountyCopper, killCounter)
19 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
24 return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0));
20}
25}
21
26
27/** True once the skull tint starts lerping from white toward red. */
28export function skullAttractsTownGuards (value)
29{
30 return Math.max(0, Math.floor(Number(value) || 0)) > SKULL_RED_LERP_START;
31}
32
22/**
33/**
23 * Decay kill counter by elapsed wall time (1 point / second).
34 * Decay kill counter by elapsed wall time (1 point / second).
24 * @returns {{ killCounter: number, consumedMs: number }}
35 * @returns {{ killCounter: number, consumedMs: number }}
@@ -50,11 +61,11 @@ export function skullTintColor (value)
50 const v = Math.max(0, Math.floor(Number(value) || 0));
61 const v = Math.max(0, Math.floor(Number(value) || 0));
51 if (v <= 0)
62 if (v <= 0)
52 { return null; }
63 { return null; }
53 if (v <= 1)
64 if (v <= SKULL_RED_LERP_START)
54 { return Object.freeze({ r: 1, g: 1, b: 1 }); }
65 { return Object.freeze({ r: 1, g: 1, b: 1 }); }
55 if (v <= SKULL_PURE_RED_VALUE)
66 if (v <= SKULL_PURE_RED_VALUE)
56 {
67 {
57 const t = (v - 1) / (SKULL_PURE_RED_VALUE - 1);
68 const t = (v - SKULL_RED_LERP_START) / (SKULL_PURE_RED_VALUE - SKULL_RED_LERP_START);
58 return Object.freeze({
69 return Object.freeze({
59 r: 1,
70 r: 1,
60 g: lerp(1, 0, t),
71 g: lerp(1, 0, t),