Add combat level display and aggro immunity for outlevelled players.
Show combat level above the skills panel, skip aggressive mob auto-aggro when the player outlevels them or has been in the same chunk for fifteen minutes (bosses exempt), and default shade spawners to level 28.
@@ -148,6 +148,7 @@
148
148
</aside>
149
149
<aside id="skills-panel" hidden>
150
150
<h2>Skills</h2>
151
<div id="skills-combat-level" class="skills-combat-level" hidden></div>
151
152
<div id="skills-list" class="skills-grid"></div>
152
153
</aside>
153
154
<aside id="spells-panel" hidden>
@@ -148,6 +148,7 @@148
</aside>148
</aside>149
<aside id="skills-panel" hidden>149
<aside id="skills-panel" hidden>150
<h2>Skills</h2>150
<h2>Skills</h2>151
<div id="skills-combat-level" class="skills-combat-level" hidden></div>151
<div id="skills-list" class="skills-grid"></div>152
<div id="skills-list" class="skills-grid"></div>152
</aside>153
</aside>153
<aside id="spells-panel" hidden>154
<aside id="spells-panel" hidden>@@ -1905,7 +1905,7 @@ async function main ()
1905
1905
market?.refresh();
1906
1906
break;
1907
1907
case MessageType.skills:
1908
skills?.render(message.skills);
1908
skills?.render(message.skills, message.combatLevel);
1909
1909
crafting?.refresh();
1910
1910
spells?.refreshCastGates?.();
1911
1911
break;
@@ -1905,7 +1905,7 @@ async function main ()1905
market?.refresh();1905
market?.refresh();1906
break;1906
break;1907
case MessageType.skills:1907
case MessageType.skills:1908
skills?.render(message.skills);1908
skills?.render(message.skills, message.combatLevel);1909
crafting?.refresh();1909
crafting?.refresh();1910
spells?.refreshCastGates?.();1910
spells?.refreshCastGates?.();1911
break;1911
break;@@ -5,9 +5,11 @@ const XP_GAIN_VISIBLE_MS = 5000;
5
5
export function initSkills ({ getEquipmentSlots, getSettings } = {})
6
6
{
7
7
const panel = document.getElementById("skills-panel");
8
const combatLevelEl = document.getElementById("skills-combat-level");
8
9
const list = document.getElementById("skills-list");
9
10
const gainHud = document.getElementById("xp-gain-hud");
10
11
let current = [];
12
let combatLevel = 0;
11
13
/** @type {Map<string, { skill: object, gainedAt: number, timer: number|null }>} */
12
14
const recentGains = new Map();
13
15
@@ -121,6 +123,19 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
121
123
function renderPanel (skills)
122
124
{
123
125
const bonuses = equipmentBonuses();
126
if (combatLevelEl)
127
{
128
if (combatLevel > 0)
129
{
130
combatLevelEl.hidden = false;
131
combatLevelEl.textContent = `Combat Level ${combatLevel}`;
132
}
133
else
134
{
135
combatLevelEl.hidden = true;
136
combatLevelEl.textContent = "";
137
}
138
}
124
139
list.replaceChildren();
125
140
for (const skill of skills)
126
141
{
@@ -128,12 +143,13 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})
128
143
}
129
144
}
130
145
131
function render (skills)
146
function render (skills, nextCombatLevel = combatLevel)
132
147
{
133
148
const next = skills ?? [];
134
149
const previous = current;
135
150
noteXpGains(previous, next);
136
151
current = next;
152
combatLevel = nextCombatLevel | 0;
137
153
if (!panel.hidden)
138
154
{ renderPanel(current); }
139
155
}
@@ -5,9 +5,11 @@ const XP_GAIN_VISIBLE_MS = 5000;5
export function initSkills ({ getEquipmentSlots, getSettings } = {})5
export function initSkills ({ getEquipmentSlots, getSettings } = {})6
{6
{7
const panel = document.getElementById("skills-panel");7
const panel = document.getElementById("skills-panel");8
const combatLevelEl = document.getElementById("skills-combat-level");8
const list = document.getElementById("skills-list");9
const list = document.getElementById("skills-list");9
const gainHud = document.getElementById("xp-gain-hud");10
const gainHud = document.getElementById("xp-gain-hud");10
let current = [];11
let current = [];12
let combatLevel = 0;11
/** @type {Map<string, { skill: object, gainedAt: number, timer: number|null }>} */13
/** @type {Map<string, { skill: object, gainedAt: number, timer: number|null }>} */12
const recentGains = new Map();14
const recentGains = new Map();13
15
@@ -121,6 +123,19 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})121
function renderPanel (skills)123
function renderPanel (skills)122
{124
{123
const bonuses = equipmentBonuses();125
const bonuses = equipmentBonuses();126
if (combatLevelEl)127
{128
if (combatLevel > 0)129
{130
combatLevelEl.hidden = false;131
combatLevelEl.textContent = `Combat Level ${combatLevel}`;132
}133
else134
{135
combatLevelEl.hidden = true;136
combatLevelEl.textContent = "";137
}138
}124
list.replaceChildren();139
list.replaceChildren();125
for (const skill of skills)140
for (const skill of skills)126
{141
{@@ -128,12 +143,13 @@ export function initSkills ({ getEquipmentSlots, getSettings } = {})128
}143
}129
}144
}130
145
131
function render (skills)146
function render (skills, nextCombatLevel = combatLevel)132
{147
{133
const next = skills ?? [];148
const next = skills ?? [];134
const previous = current;149
const previous = current;135
noteXpGains(previous, next);150
noteXpGains(previous, next);136
current = next;151
current = next;152
combatLevel = nextCombatLevel | 0;137
if (!panel.hidden)153
if (!panel.hidden)138
{ renderPanel(current); }154
{ renderPanel(current); }139
}155
}@@ -715,6 +715,15 @@ button.friend-account-name:hover {
715
715
margin: 0.5rem 0;
716
716
}
717
717
718
.skills-combat-level {
719
margin: 0.35rem 0 0.15rem;
720
padding: 0.45rem 0.55rem;
721
background: #12151b;
722
border: 1px solid #2c3340;
723
font-weight: 600;
724
text-align: center;
725
}
726
718
727
.skill-row {
719
728
display: flex;
720
729
gap: 0.55rem;
@@ -715,6 +715,15 @@ button.friend-account-name:hover {715
margin: 0.5rem 0;715
margin: 0.5rem 0;716
}716
}717
717
718
.skills-combat-level {719
margin: 0.35rem 0 0.15rem;720
padding: 0.45rem 0.55rem;721
background: #12151b;722
border: 1px solid #2c3340;723
font-weight: 600;724
text-align: center;725
}726
718
.skill-row {727
.skill-row {719
display: flex;728
display: flex;720
gap: 0.55rem;729
gap: 0.55rem;@@ -29,7 +29,7 @@ import {
29
29
stackQuantity
30
30
} from "../../../shared/items/inventory.js";
31
31
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";
32
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
32
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
33
33
import { craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
34
34
import { tileToChunk, tileToLocal } from "../world/coordinates.js";
35
35
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
@@ -446,7 +446,7 @@ function bottle (world, sessionId, command)
446
446
type: "skills-updated",
447
447
entityId,
448
448
characterId: command.characterId,
449
skills: publicSkillsView(skills),
449
...publicSkillsPayload(skills),
450
450
stored: storedSkillXp(skills),
451
451
levelUps: result.levelUp ? [result.levelUp] : []
452
452
});
@@ -565,7 +565,7 @@ function createDye (world, sessionId, command)
565
565
type: "skills-updated",
566
566
entityId,
567
567
characterId: command.characterId,
568
skills: publicSkillsView(skills),
568
...publicSkillsPayload(skills),
569
569
stored: storedSkillXp(skills),
570
570
levelUps: result.levelUp ? [result.levelUp] : []
571
571
});
@@ -29,7 +29,7 @@ import {29
stackQuantity29
stackQuantity30
} from "../../../shared/items/inventory.js";30
} from "../../../shared/items/inventory.js";31
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";31
import { attachOrigins, craftOrigin, CraftOriginVerb, writtenOrigin, normalizeOrigins } from "../../../shared/items/origin.js";32
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";32
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";33
import { craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";33
import { craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";34
import { tileToChunk, tileToLocal } from "../world/coordinates.js";34
import { tileToChunk, tileToLocal } from "../world/coordinates.js";35
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";35
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";@@ -446,7 +446,7 @@ function bottle (world, sessionId, command)446
type: "skills-updated",446
type: "skills-updated",447
entityId,447
entityId,448
characterId: command.characterId,448
characterId: command.characterId,449
skills: publicSkillsView(skills),449
...publicSkillsPayload(skills),450
stored: storedSkillXp(skills),450
stored: storedSkillXp(skills),451
levelUps: result.levelUp ? [result.levelUp] : []451
levelUps: result.levelUp ? [result.levelUp] : []452
});452
});@@ -565,7 +565,7 @@ function createDye (world, sessionId, command)565
type: "skills-updated",565
type: "skills-updated",566
entityId,566
entityId,567
characterId: command.characterId,567
characterId: command.characterId,568
skills: publicSkillsView(skills),568
...publicSkillsPayload(skills),569
stored: storedSkillXp(skills),569
stored: storedSkillXp(skills),570
levelUps: result.levelUp ? [result.levelUp] : []570
levelUps: result.levelUp ? [result.levelUp] : []571
});571
});@@ -9,8 +9,16 @@ import
9
9
mobMeleeAttackProfile,
10
10
mobSkillLevels,
11
11
mobIsAggressive,
12
mobAggroRangeTiles
12
mobAggroRangeTiles,
13
mobIsBoss
13
14
} from "../../../shared/definitions/mobCombat.js";
15
import {
16
combatLevelFromSkills,
17
mobAggressionLevel,
18
playerOutlevelsMobAggression
19
} from "../../../shared/combat/combatLevel.js";
20
import { chunkPeaceAggressionImmunity } from "../../../shared/navigation/chunkPresence.js";
21
import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
14
22
import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
15
23
import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16
24
import { mobDamageAffinities } from "../../../shared/combat/magic.js";
@@ -41,9 +49,9 @@ import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
41
49
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";
42
50
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
43
51
import { chunkBoundsAround, findPath } from "../navigation/astar.js";
52
import { tileToChunk } from "../world/coordinates.js";
44
53
import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";
45
54
import { CHUNK_SIZE, VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
46
import { tileToChunk } from "../world/coordinates.js";
47
55
import { stackQuantity } from "../../../shared/items/inventory.js";
48
56
import { addGroundItem, publicGroundItem } from "../items/bags.js";
49
57
import { resolveItemDualTint } from "../../../shared/render/tint.js";
@@ -555,7 +563,7 @@ export function stepAggression (world, now = Date.now())
555
563
const range = mobAggroRangeTiles(def);
556
564
const bestId = townGuard
557
565
? pickAggressionTargetAggressiveMob(world, entity, range)
558
: pickAggressionTargetPlayerOrGuard(world, entity, range);
566
: pickAggressionTargetPlayerOrGuard(world, entity, range, now);
559
567
if (bestId == null)
560
568
{ continue; }
561
569
if (!ensureMobCombat(world.ecs, entity.entityId))
@@ -587,12 +595,14 @@ function entityIsTownGuard (world, handle, creature)
587
595
}
588
596
589
597
/** Nearest living player or town guard in range with LOS. */
590
function pickAggressionTargetPlayerOrGuard (world, entity, range)
598
function pickAggressionTargetPlayerOrGuard (world, entity, range, now = Date.now())
591
599
{
592
600
let bestId = null;
593
601
let bestDist = Infinity;
594
602
for (const player of world.ecs.query(Component.character, Component.position))
595
603
{
604
if (playerIgnoresAggressiveMob(world, entity, player.handle, now))
605
{ continue; }
596
606
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);
597
607
if (dist != null && dist < bestDist)
598
608
{
@@ -616,6 +626,34 @@ function pickAggressionTargetPlayerOrGuard (world, entity, range)
616
626
return bestId;
617
627
}
618
628
629
/** Non-boss aggressive mobs skip players who outlevel them or have chunk peace. */
630
function playerIgnoresAggressiveMob (world, mobEntity, playerHandle, now)
631
{
632
const def = mobDefinition(mobEntity.creature.mobTypeId);
633
if (mobIsBoss(def))
634
{ return false; }
635
const skills = world.ecs.get(playerHandle, Component.skills);
636
if (!skills)
637
{ return false; }
638
const playerLevel = combatLevelFromSkills(skills);
639
const origin = world.ecs.get(mobEntity.handle, Component.spawnOrigin);
640
const mobLevel = mobAggressionLevel(mobEntity.creature, origin, def);
641
if (playerOutlevelsMobAggression(playerLevel, mobLevel))
642
{ return true; }
643
const presence = world.ecs.get(playerHandle, Component.chunkPresence);
644
const pos = world.ecs.get(playerHandle, Component.position);
645
if (!presence || !pos)
646
{ return false; }
647
return chunkPeaceAggressionImmunity(
648
presence,
649
pos.tileX,
650
pos.tileY,
651
pos.dimensionId ?? OVERWORLD_ID,
652
now,
653
tileToChunk
654
);
655
}
656
619
657
/** Nearest aggressive hostile creature in range with LOS (for town guards). */
620
658
function pickAggressionTargetAggressiveMob (world, entity, range)
621
659
{
@@ -1840,7 +1878,8 @@ function applyLocalMeleeHit (
1840
1878
type: "skills-updated",
1841
1879
entityId: targetId,
1842
1880
characterId: dodgeXp.characterId,
1843
skills: dodgeXp.view,
1881
skills: dodgeXp.skills,
1882
combatLevel: dodgeXp.combatLevel,
1844
1883
stored: dodgeXp.stored,
1845
1884
levelUps: dodgeXp.levelUps ?? []
1846
1885
});
@@ -1869,7 +1908,8 @@ function applyLocalMeleeHit (
1869
1908
type: "skills-updated",
1870
1909
entityId: targetId,
1871
1910
characterId: blockXp.characterId,
1872
skills: blockXp.view,
1911
skills: blockXp.skills,
1912
combatLevel: blockXp.combatLevel,
1873
1913
stored: blockXp.stored,
1874
1914
levelUps: blockXp.levelUps ?? []
1875
1915
});
@@ -1904,7 +1944,8 @@ function applyLocalMeleeHit (
1904
1944
type: "skills-updated",
1905
1945
entityId: targetId,
1906
1946
characterId: healthXp.characterId,
1907
skills: healthXp.view,
1947
skills: healthXp.skills,
1948
combatLevel: healthXp.combatLevel,
1908
1949
stored: healthXp.stored,
1909
1950
levelUps: healthXp.levelUps ?? []
1910
1951
});
@@ -1934,7 +1975,8 @@ function applyLocalMeleeHit (
1934
1975
type: "skills-updated",
1935
1976
entityId: attackerId,
1936
1977
characterId: attackerCharacter.characterId,
1937
skills: xpAward.view,
1978
skills: xpAward.skills,
1979
combatLevel: xpAward.combatLevel,
1938
1980
stored: xpAward.stored,
1939
1981
levelUps: xpAward.levelUps ?? []
1940
1982
});
@@ -2090,7 +2132,8 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D
2090
2132
type: "skills-updated",
2091
2133
entityId: targetId,
2092
2134
characterId: healthXp.characterId,
2093
skills: healthXp.view,
2135
skills: healthXp.skills,
2136
combatLevel: healthXp.combatLevel,
2094
2137
stored: healthXp.stored,
2095
2138
levelUps: healthXp.levelUps ?? []
2096
2139
});
@@ -9,8 +9,16 @@ import9
mobMeleeAttackProfile,9
mobMeleeAttackProfile,10
mobSkillLevels,10
mobSkillLevels,11
mobIsAggressive,11
mobIsAggressive,12
mobAggroRangeTiles12
mobAggroRangeTiles,13
mobIsBoss13
} from "../../../shared/definitions/mobCombat.js";14
} from "../../../shared/definitions/mobCombat.js";15
import {16
combatLevelFromSkills,17
mobAggressionLevel,18
playerOutlevelsMobAggression19
} from "../../../shared/combat/combatLevel.js";20
import { chunkPeaceAggressionImmunity } from "../../../shared/navigation/chunkPresence.js";21
import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";14
import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";22
import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";15
import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";23
import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";16
import { mobDamageAffinities } from "../../../shared/combat/magic.js";24
import { mobDamageAffinities } from "../../../shared/combat/magic.js";@@ -41,9 +49,9 @@ import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";41
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";49
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";42
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";50
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";43
import { chunkBoundsAround, findPath } from "../navigation/astar.js";51
import { chunkBoundsAround, findPath } from "../navigation/astar.js";52
import { tileToChunk } from "../world/coordinates.js";44
import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";53
import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";45
import { CHUNK_SIZE, VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";54
import { CHUNK_SIZE, VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";46
import { tileToChunk } from "../world/coordinates.js";47
import { stackQuantity } from "../../../shared/items/inventory.js";55
import { stackQuantity } from "../../../shared/items/inventory.js";48
import { addGroundItem, publicGroundItem } from "../items/bags.js";56
import { addGroundItem, publicGroundItem } from "../items/bags.js";49
import { resolveItemDualTint } from "../../../shared/render/tint.js";57
import { resolveItemDualTint } from "../../../shared/render/tint.js";@@ -555,7 +563,7 @@ export function stepAggression (world, now = Date.now())555
const range = mobAggroRangeTiles(def);563
const range = mobAggroRangeTiles(def);556
const bestId = townGuard564
const bestId = townGuard557
? pickAggressionTargetAggressiveMob(world, entity, range)565
? pickAggressionTargetAggressiveMob(world, entity, range)558
: pickAggressionTargetPlayerOrGuard(world, entity, range);566
: pickAggressionTargetPlayerOrGuard(world, entity, range, now);559
if (bestId == null)567
if (bestId == null)560
{ continue; }568
{ continue; }561
if (!ensureMobCombat(world.ecs, entity.entityId))569
if (!ensureMobCombat(world.ecs, entity.entityId))@@ -587,12 +595,14 @@ function entityIsTownGuard (world, handle, creature)587
}595
}588
596
589
/** Nearest living player or town guard in range with LOS. */597
/** Nearest living player or town guard in range with LOS. */590
function pickAggressionTargetPlayerOrGuard (world, entity, range)598
function pickAggressionTargetPlayerOrGuard (world, entity, range, now = Date.now())591
{599
{592
let bestId = null;600
let bestId = null;593
let bestDist = Infinity;601
let bestDist = Infinity;594
for (const player of world.ecs.query(Component.character, Component.position))602
for (const player of world.ecs.query(Component.character, Component.position))595
{603
{604
if (playerIgnoresAggressiveMob(world, entity, player.handle, now))605
{ continue; }596
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);606
const dist = considerAggressionCandidate(world, entity, player.handle, player.entityId, player.position, range);597
if (dist != null && dist < bestDist)607
if (dist != null && dist < bestDist)598
{608
{@@ -616,6 +626,34 @@ function pickAggressionTargetPlayerOrGuard (world, entity, range)616
return bestId;626
return bestId;617
}627
}618
628
629
/** Non-boss aggressive mobs skip players who outlevel them or have chunk peace. */630
function playerIgnoresAggressiveMob (world, mobEntity, playerHandle, now)631
{632
const def = mobDefinition(mobEntity.creature.mobTypeId);633
if (mobIsBoss(def))634
{ return false; }635
const skills = world.ecs.get(playerHandle, Component.skills);636
if (!skills)637
{ return false; }638
const playerLevel = combatLevelFromSkills(skills);639
const origin = world.ecs.get(mobEntity.handle, Component.spawnOrigin);640
const mobLevel = mobAggressionLevel(mobEntity.creature, origin, def);641
if (playerOutlevelsMobAggression(playerLevel, mobLevel))642
{ return true; }643
const presence = world.ecs.get(playerHandle, Component.chunkPresence);644
const pos = world.ecs.get(playerHandle, Component.position);645
if (!presence || !pos)646
{ return false; }647
return chunkPeaceAggressionImmunity(648
presence,649
pos.tileX,650
pos.tileY,651
pos.dimensionId ?? OVERWORLD_ID,652
now,653
tileToChunk654
);655
}656
619
/** Nearest aggressive hostile creature in range with LOS (for town guards). */657
/** Nearest aggressive hostile creature in range with LOS (for town guards). */620
function pickAggressionTargetAggressiveMob (world, entity, range)658
function pickAggressionTargetAggressiveMob (world, entity, range)621
{659
{@@ -1840,7 +1878,8 @@ function applyLocalMeleeHit (1840
type: "skills-updated",1878
type: "skills-updated",1841
entityId: targetId,1879
entityId: targetId,1842
characterId: dodgeXp.characterId,1880
characterId: dodgeXp.characterId,1843
skills: dodgeXp.view,1881
skills: dodgeXp.skills,1882
combatLevel: dodgeXp.combatLevel,1844
stored: dodgeXp.stored,1883
stored: dodgeXp.stored,1845
levelUps: dodgeXp.levelUps ?? []1884
levelUps: dodgeXp.levelUps ?? []1846
});1885
});@@ -1869,7 +1908,8 @@ function applyLocalMeleeHit (1869
type: "skills-updated",1908
type: "skills-updated",1870
entityId: targetId,1909
entityId: targetId,1871
characterId: blockXp.characterId,1910
characterId: blockXp.characterId,1872
skills: blockXp.view,1911
skills: blockXp.skills,1912
combatLevel: blockXp.combatLevel,1873
stored: blockXp.stored,1913
stored: blockXp.stored,1874
levelUps: blockXp.levelUps ?? []1914
levelUps: blockXp.levelUps ?? []1875
});1915
});@@ -1904,7 +1944,8 @@ function applyLocalMeleeHit (1904
type: "skills-updated",1944
type: "skills-updated",1905
entityId: targetId,1945
entityId: targetId,1906
characterId: healthXp.characterId,1946
characterId: healthXp.characterId,1907
skills: healthXp.view,1947
skills: healthXp.skills,1948
combatLevel: healthXp.combatLevel,1908
stored: healthXp.stored,1949
stored: healthXp.stored,1909
levelUps: healthXp.levelUps ?? []1950
levelUps: healthXp.levelUps ?? []1910
});1951
});@@ -1934,7 +1975,8 @@ function applyLocalMeleeHit (1934
type: "skills-updated",1975
type: "skills-updated",1935
entityId: attackerId,1976
entityId: attackerId,1936
characterId: attackerCharacter.characterId,1977
characterId: attackerCharacter.characterId,1937
skills: xpAward.view,1978
skills: xpAward.skills,1979
combatLevel: xpAward.combatLevel,1938
stored: xpAward.stored,1980
stored: xpAward.stored,1939
levelUps: xpAward.levelUps ?? []1981
levelUps: xpAward.levelUps ?? []1940
});1982
});@@ -2090,7 +2132,8 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D2090
type: "skills-updated",2132
type: "skills-updated",2091
entityId: targetId,2133
entityId: targetId,2092
characterId: healthXp.characterId,2134
characterId: healthXp.characterId,2093
skills: healthXp.view,2135
skills: healthXp.skills,2136
combatLevel: healthXp.combatLevel,2094
stored: healthXp.stored,2137
stored: healthXp.stored,2095
levelUps: healthXp.levelUps ?? []2138
levelUps: healthXp.levelUps ?? []2096
});2139
});@@ -21,7 +21,7 @@ import
21
21
craftOriginVerbForStation,
22
22
CraftOriginVerb
23
23
} from "../../../shared/items/origin.js";
24
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
24
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
25
25
import { bagView } from "../items/bags.js";
26
26
import { tileToChunk, tileToLocal } from "../world/coordinates.js";
27
27
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
@@ -443,7 +443,7 @@ export function stepCrafting (world, now)
443
443
type: "skills-updated",
444
444
entityId,
445
445
characterId,
446
skills: publicSkillsView(skills),
446
...publicSkillsPayload(skills),
447
447
stored: storedSkillXp(skills),
448
448
levelUps
449
449
});
@@ -21,7 +21,7 @@ import21
craftOriginVerbForStation,21
craftOriginVerbForStation,22
CraftOriginVerb22
CraftOriginVerb23
} from "../../../shared/items/origin.js";23
} from "../../../shared/items/origin.js";24
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";24
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";25
import { bagView } from "../items/bags.js";25
import { bagView } from "../items/bags.js";26
import { tileToChunk, tileToLocal } from "../world/coordinates.js";26
import { tileToChunk, tileToLocal } from "../world/coordinates.js";27
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";27
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";@@ -443,7 +443,7 @@ export function stepCrafting (world, now)443
type: "skills-updated",443
type: "skills-updated",444
entityId,444
entityId,445
characterId,445
characterId,446
skills: publicSkillsView(skills),446
...publicSkillsPayload(skills),447
stored: storedSkillXp(skills),447
stored: storedSkillXp(skills),448
levelUps448
levelUps449
});449
});@@ -27,7 +27,9 @@ export const Component = Object.freeze({
27
27
spells: "spells",
28
28
spellcasting: "spellcasting",
29
29
/** Temporary summoned companion (Shade). */
30
summon: "summon"
30
summon: "summon",
31
/** Player chunk residency for aggro peace (sinceMs when current chunk was entered). */
32
chunkPresence: "chunkPresence"
31
33
});
32
34
33
35
/** Default position component fields (tile coords + dimension). */
@@ -27,7 +27,9 @@ export const Component = Object.freeze({27
spells: "spells",27
spells: "spells",28
spellcasting: "spellcasting",28
spellcasting: "spellcasting",29
/** Temporary summoned companion (Shade). */29
/** Temporary summoned companion (Shade). */30
summon: "summon"30
summon: "summon",31
/** Player chunk residency for aggro peace (sinceMs when current chunk was entered). */32
chunkPresence: "chunkPresence"31
});33
});32
34
33
/** Default position component fields (tile coords + dimension). */35
/** Default position component fields (tile coords + dimension). */@@ -14,7 +14,7 @@ import { MATERIAL_DISPLAY_NAME, WOOD_TIER_ORDER } from "../../../shared/definiti
14
14
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
15
15
import { itemDefinition } from "../../../shared/definitions/items.js";
16
16
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";
17
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
17
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
18
18
import { rollSkill } from "../../../shared/combat/rolls.js";
19
19
import { stackQuantity } from "../../../shared/items/inventory.js";
20
20
import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";
@@ -372,7 +372,7 @@ function succeedLight (world, handle, entityId, characterId, session, events, pr
372
372
type: "skills-updated",
373
373
entityId,
374
374
characterId,
375
skills: publicSkillsView(skills),
375
...publicSkillsPayload(skills),
376
376
stored: storedSkillXp(skills),
377
377
levelUps
378
378
});
@@ -14,7 +14,7 @@ import { MATERIAL_DISPLAY_NAME, WOOD_TIER_ORDER } from "../../../shared/definiti14
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";14
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";15
import { itemDefinition } from "../../../shared/definitions/items.js";15
import { itemDefinition } from "../../../shared/definitions/items.js";16
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";16
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";17
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";17
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";18
import { rollSkill } from "../../../shared/combat/rolls.js";18
import { rollSkill } from "../../../shared/combat/rolls.js";19
import { stackQuantity } from "../../../shared/items/inventory.js";19
import { stackQuantity } from "../../../shared/items/inventory.js";20
import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";20
import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";@@ -372,7 +372,7 @@ function succeedLight (world, handle, entityId, characterId, session, events, pr372
type: "skills-updated",372
type: "skills-updated",373
entityId,373
entityId,374
characterId,374
characterId,375
skills: publicSkillsView(skills),375
...publicSkillsPayload(skills),376
stored: storedSkillXp(skills),376
stored: storedSkillXp(skills),377
levelUps377
levelUps378
});378
});@@ -26,7 +26,7 @@ import {
26
26
import { yarnItemId } from "../../../shared/definitions/clothItems.js";
27
27
import { itemDefinition } from "../../../shared/definitions/items.js";
28
28
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";
29
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
29
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
30
30
import { rollSkill } from "../../../shared/combat/rolls.js";
31
31
import {
32
32
insertStack,
@@ -362,7 +362,7 @@ function completeCatch (world, handle, entityId, characterId, session, events, p
362
362
type: "skills-updated",
363
363
entityId,
364
364
characterId,
365
skills: publicSkillsView(skills),
365
...publicSkillsPayload(skills),
366
366
stored: storedSkillXp(skills),
367
367
levelUps
368
368
});
@@ -26,7 +26,7 @@ import {26
import { yarnItemId } from "../../../shared/definitions/clothItems.js";26
import { yarnItemId } from "../../../shared/definitions/clothItems.js";27
import { itemDefinition } from "../../../shared/definitions/items.js";27
import { itemDefinition } from "../../../shared/definitions/items.js";28
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";28
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";29
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";29
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";30
import { rollSkill } from "../../../shared/combat/rolls.js";30
import { rollSkill } from "../../../shared/combat/rolls.js";31
import {31
import {32
insertStack,32
insertStack,@@ -362,7 +362,7 @@ function completeCatch (world, handle, entityId, characterId, session, events, p362
type: "skills-updated",362
type: "skills-updated",363
entityId,363
entityId,364
characterId,364
characterId,365
skills: publicSkillsView(skills),365
...publicSkillsPayload(skills),366
stored: storedSkillXp(skills),366
stored: storedSkillXp(skills),367
levelUps367
levelUps368
});368
});@@ -5,7 +5,7 @@ import { VISIBLE_CHUNK_RADIUS, STATIC_CHUNK_RADIUS } from "../../../shared/proto
5
5
import { staticChunkRadiusForViewDistance, ViewDistance, normalizeGraphicsSettings } from "../../../shared/graphics/settings.js";
6
6
import { broadcastSpeech, broadcastItemBubble } from "../chat/speech.js";
7
7
import { CraftingStationId, craftingStationDefinition } from "../../../shared/definitions/craftingStations.js";
8
import { publicSkillsView } from "../../../shared/skills/state.js";
8
import { publicSkillsPayload } from "../../../shared/skills/state.js";
9
9
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
10
10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";
11
11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";
@@ -1163,7 +1163,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1163
1163
{ send(session, { type: MessageType.inventory, ...bag }); }
1164
1164
const skills = simulation.skillsOf(session.entityId);
1165
1165
if (skills)
1166
{ send(session, { type: MessageType.skills, skills: publicSkillsView(skills) }); }
1166
{ send(session, { type: MessageType.skills, ...publicSkillsPayload(skills) }); }
1167
1167
const spellView = simulation.spellsOf(session.entityId);
1168
1168
if (spellView)
1169
1169
{
@@ -1505,7 +1505,11 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1505
1505
const session = [...sessions.values()].find((entry) => entry.characterId === event.characterId);
1506
1506
if (!session)
1507
1507
{ continue; }
1508
send(session, { type: MessageType.skills, skills: event.skills ?? [] });
1508
send(session, {
1509
type: MessageType.skills,
1510
skills: event.skills ?? [],
1511
combatLevel: event.combatLevel ?? 0
1512
});
1509
1513
continue;
1510
1514
}
1511
1515
if (event.type === "spells")
@@ -5,7 +5,7 @@ import { VISIBLE_CHUNK_RADIUS, STATIC_CHUNK_RADIUS } from "../../../shared/proto5
import { staticChunkRadiusForViewDistance, ViewDistance, normalizeGraphicsSettings } from "../../../shared/graphics/settings.js";5
import { staticChunkRadiusForViewDistance, ViewDistance, normalizeGraphicsSettings } from "../../../shared/graphics/settings.js";6
import { broadcastSpeech, broadcastItemBubble } from "../chat/speech.js";6
import { broadcastSpeech, broadcastItemBubble } from "../chat/speech.js";7
import { CraftingStationId, craftingStationDefinition } from "../../../shared/definitions/craftingStations.js";7
import { CraftingStationId, craftingStationDefinition } from "../../../shared/definitions/craftingStations.js";8
import { publicSkillsView } from "../../../shared/skills/state.js";8
import { publicSkillsPayload } from "../../../shared/skills/state.js";9
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";9
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";@@ -1163,7 +1163,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1163
{ send(session, { type: MessageType.inventory, ...bag }); }1163
{ send(session, { type: MessageType.inventory, ...bag }); }1164
const skills = simulation.skillsOf(session.entityId);1164
const skills = simulation.skillsOf(session.entityId);1165
if (skills)1165
if (skills)1166
{ send(session, { type: MessageType.skills, skills: publicSkillsView(skills) }); }1166
{ send(session, { type: MessageType.skills, ...publicSkillsPayload(skills) }); }1167
const spellView = simulation.spellsOf(session.entityId);1167
const spellView = simulation.spellsOf(session.entityId);1168
if (spellView)1168
if (spellView)1169
{1169
{@@ -1505,7 +1505,11 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1505
const session = [...sessions.values()].find((entry) => entry.characterId === event.characterId);1505
const session = [...sessions.values()].find((entry) => entry.characterId === event.characterId);1506
if (!session)1506
if (!session)1507
{ continue; }1507
{ continue; }1508
send(session, { type: MessageType.skills, skills: event.skills ?? [] });1508
send(session, {1509
type: MessageType.skills,1510
skills: event.skills ?? [],1511
combatLevel: event.combatLevel ?? 01512
});1509
continue;1513
continue;1510
}1514
}1511
if (event.type === "spells")1515
if (event.type === "spells")@@ -34,7 +34,7 @@ import {
34
34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";
35
35
import { insertStack } from "../../../shared/items/inventory.js";
36
36
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";
37
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
37
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
38
38
import {
39
39
seasonIdAt,
40
40
treeStumpStateForSeason,
@@ -540,7 +540,7 @@ function pushBagUpdate (events, privates, world, handle, entityId, character, sk
540
540
type: "skills-updated",
541
541
entityId,
542
542
characterId: character.characterId,
543
skills: publicSkillsView(skills),
543
...publicSkillsPayload(skills),
544
544
stored: storedSkillXp(skills),
545
545
levelUps
546
546
});
@@ -34,7 +34,7 @@ import {34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";35
import { insertStack } from "../../../shared/items/inventory.js";35
import { insertStack } from "../../../shared/items/inventory.js";36
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";36
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";37
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";37
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";38
import {38
import {39
seasonIdAt,39
seasonIdAt,40
treeStumpStateForSeason,40
treeStumpStateForSeason,@@ -540,7 +540,7 @@ function pushBagUpdate (events, privates, world, handle, entityId, character, sk540
type: "skills-updated",540
type: "skills-updated",541
entityId,541
entityId,542
characterId: character.characterId,542
characterId: character.characterId,543
skills: publicSkillsView(skills),543
...publicSkillsPayload(skills),544
stored: storedSkillXp(skills),544
stored: storedSkillXp(skills),545
levelUps545
levelUps546
});546
});@@ -7,7 +7,7 @@ import {
7
7
} from "../../../shared/definitions/materialTiers.js";
8
8
import { itemDefinition } from "../../../shared/definitions/items.js";
9
9
import { SkillId } from "../../../shared/definitions/skills.js";
10
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
10
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
11
11
import { insertStack } from "../../../shared/items/inventory.js";
12
12
import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
13
13
import { bagView } from "../items/bags.js";
@@ -263,7 +263,7 @@ function completeShear (world, handle, entityId, characterId, session, events, p
263
263
type: "skills-updated",
264
264
entityId,
265
265
characterId,
266
skills: publicSkillsView(skills),
266
...publicSkillsPayload(skills),
267
267
stored: storedSkillXp(skills),
268
268
levelUps
269
269
});
@@ -7,7 +7,7 @@ import {7
} from "../../../shared/definitions/materialTiers.js";7
} from "../../../shared/definitions/materialTiers.js";8
import { itemDefinition } from "../../../shared/definitions/items.js";8
import { itemDefinition } from "../../../shared/definitions/items.js";9
import { SkillId } from "../../../shared/definitions/skills.js";9
import { SkillId } from "../../../shared/definitions/skills.js";10
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";10
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";11
import { insertStack } from "../../../shared/items/inventory.js";11
import { insertStack } from "../../../shared/items/inventory.js";12
import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";12
import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";13
import { bagView } from "../items/bags.js";13
import { bagView } from "../items/bags.js";@@ -263,7 +263,7 @@ function completeShear (world, handle, entityId, characterId, session, events, p263
type: "skills-updated",263
type: "skills-updated",264
entityId,264
entityId,265
characterId,265
characterId,266
skills: publicSkillsView(skills),266
...publicSkillsPayload(skills),267
stored: storedSkillXp(skills),267
stored: storedSkillXp(skills),268
levelUps268
levelUps269
});269
});@@ -478,6 +478,12 @@ export class Simulation
478
478
nextCastAt: 0,
479
479
pendingCast: null
480
480
},
481
chunkPresence: {
482
chunkX: tileToChunk(tileX),
483
chunkY: tileToChunk(tileY),
484
dimensionId,
485
sinceMs: this.now
486
},
481
487
};
482
488
if (isDead)
483
489
{ components.dead = {}; }
@@ -734,12 +740,13 @@ export class Simulation
734
740
return { row, view };
735
741
}
736
742
737
pushSkills (characterId, skills)
743
pushSkills (characterId, skills, combatLevel)
738
744
{
739
745
this.pendingPrivate.push({
740
746
type: "skills",
741
747
characterId,
742
skills
748
skills,
749
combatLevel
743
750
});
744
751
}
745
752
@@ -2687,7 +2694,7 @@ export class Simulation
2687
2694
if (!event?.characterId || !event.stored)
2688
2695
{ return; }
2689
2696
this.stateDb.saveSkills(event.characterId, { xp: event.stored });
2690
this.pushSkills(event.characterId, event.skills ?? []);
2697
this.pushSkills(event.characterId, event.skills ?? [], event.combatLevel ?? 0);
2691
2698
}
2692
2699
2693
2700
#applySpellsUpdated (event)
@@ -478,6 +478,12 @@ export class Simulation478
nextCastAt: 0,478
nextCastAt: 0,479
pendingCast: null479
pendingCast: null480
},480
},481
chunkPresence: {482
chunkX: tileToChunk(tileX),483
chunkY: tileToChunk(tileY),484
dimensionId,485
sinceMs: this.now486
},481
};487
};482
if (isDead)488
if (isDead)483
{ components.dead = {}; }489
{ components.dead = {}; }@@ -734,12 +740,13 @@ export class Simulation734
return { row, view };740
return { row, view };735
}741
}736
742
737
pushSkills (characterId, skills)743
pushSkills (characterId, skills, combatLevel)738
{744
{739
this.pendingPrivate.push({745
this.pendingPrivate.push({740
type: "skills",746
type: "skills",741
characterId,747
characterId,742
skills748
skills,749
combatLevel743
});750
});744
}751
}745
752
@@ -2687,7 +2694,7 @@ export class Simulation2687
if (!event?.characterId || !event.stored)2694
if (!event?.characterId || !event.stored)2688
{ return; }2695
{ return; }2689
this.stateDb.saveSkills(event.characterId, { xp: event.stored });2696
this.stateDb.saveSkills(event.characterId, { xp: event.stored });2690
this.pushSkills(event.characterId, event.skills ?? []);2697
this.pushSkills(event.characterId, event.skills ?? [], event.combatLevel ?? 0);2691
}2698
}2692
2699
2693
#applySpellsUpdated (event)2700
#applySpellsUpdated (event)@@ -68,7 +68,8 @@ import {
68
68
} from "../combat/service.js";
69
69
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";
70
70
import { SkillId } from "../../../shared/definitions/skills.js";
71
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
71
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
72
import { syncCharacterChunkPresence } from "../navigation/chunkPresence.js";
72
73
import {
73
74
STAMINA_REGEN_PER_SECOND,
74
75
STAMINA_XP_PER_POINT_SPENT,
@@ -420,7 +421,10 @@ export class WorkerWorld
420
421
{ ensureFlightComponent(this.ecs, handle, position, def); }
421
422
const character = this.ecs.get(handle, Component.character);
422
423
if (character?.characterId)
423
{ this.characterEntities.set(character.characterId, entityId); }
424
{
425
this.characterEntities.set(character.characterId, entityId);
426
syncCharacterChunkPresence(this.ecs, handle, Date.now());
427
}
424
428
return publicEntityView(this.ecs, entityId);
425
429
}
426
430
@@ -623,6 +627,7 @@ export class WorkerWorld
623
627
this.#vacate(message.entityId, fromTileX, fromTileY);
624
628
position.tileX = message.tileX;
625
629
position.tileY = message.tileY;
630
syncCharacterChunkPresence(this.ecs, handle, Date.now());
626
631
this.#occupy(message.entityId, position.tileX, position.tileY);
627
632
return {
628
633
accepted: true,
@@ -696,6 +701,7 @@ export class WorkerWorld
696
701
position.tileX = destTileX;
697
702
position.tileY = destTileY;
698
703
position.dimensionId = dimensionId;
704
syncCharacterChunkPresence(this.ecs, handle, Date.now());
699
705
if (!this.#isFlying(handle))
700
706
{ this.#occupy(message.entityId, destTileX, destTileY); }
701
707
return {
@@ -803,6 +809,7 @@ export class WorkerWorld
803
809
const tileY = Math.floor(flight.y);
804
810
position.tileX = tileX;
805
811
position.tileY = tileY;
812
syncCharacterChunkPresence(this.ecs, handle, now);
806
813
const destRegionX = tileToRegion(tileX);
807
814
const destRegionY = tileToRegion(tileY);
808
815
const dimensionId = normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID);
@@ -1005,7 +1012,8 @@ export class WorkerWorld
1005
1012
type: "skills-updated",
1006
1013
entityId,
1007
1014
characterId: character.characterId,
1008
skills: xpAward.view,
1015
skills: xpAward.skills,
1016
combatLevel: xpAward.combatLevel,
1009
1017
stored: xpAward.stored,
1010
1018
levelUps: xpAward.levelUps ?? []
1011
1019
}]
@@ -1209,7 +1217,7 @@ export class WorkerWorld
1209
1217
type: "skills-updated",
1210
1218
entityId: this.ecs.entityIdOf(handle),
1211
1219
characterId: character.characterId,
1212
skills: publicSkillsView(skills),
1220
...publicSkillsPayload(skills),
1213
1221
stored: storedSkillXp(skills),
1214
1222
levelUps
1215
1223
});
@@ -1465,6 +1473,7 @@ export class WorkerWorld
1465
1473
path.stuckTileY = position.tileY;
1466
1474
recordFollowTrail(this.ecs, entityId, fromTileX, fromTileY);
1467
1475
consumeFollowTrail(this.ecs, entityId, position.tileX, position.tileY);
1476
syncCharacterChunkPresence(this.ecs, handle, now);
1468
1477
if (!isWalk)
1469
1478
{ this.#consumeRunStamina(handle, events); }
1470
1479
events.push(this.#moveEvent(entityId, fromTileX, fromTileY));
@@ -68,7 +68,8 @@ import {68
} from "../combat/service.js";68
} from "../combat/service.js";69
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";69
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";70
import { SkillId } from "../../../shared/definitions/skills.js";70
import { SkillId } from "../../../shared/definitions/skills.js";71
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";71
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";72
import { syncCharacterChunkPresence } from "../navigation/chunkPresence.js";72
import {73
import {73
STAMINA_REGEN_PER_SECOND,74
STAMINA_REGEN_PER_SECOND,74
STAMINA_XP_PER_POINT_SPENT,75
STAMINA_XP_PER_POINT_SPENT,@@ -420,7 +421,10 @@ export class WorkerWorld420
{ ensureFlightComponent(this.ecs, handle, position, def); }421
{ ensureFlightComponent(this.ecs, handle, position, def); }421
const character = this.ecs.get(handle, Component.character);422
const character = this.ecs.get(handle, Component.character);422
if (character?.characterId)423
if (character?.characterId)423
{ this.characterEntities.set(character.characterId, entityId); }424
{425
this.characterEntities.set(character.characterId, entityId);426
syncCharacterChunkPresence(this.ecs, handle, Date.now());427
}424
return publicEntityView(this.ecs, entityId);428
return publicEntityView(this.ecs, entityId);425
}429
}426
430
@@ -623,6 +627,7 @@ export class WorkerWorld623
this.#vacate(message.entityId, fromTileX, fromTileY);627
this.#vacate(message.entityId, fromTileX, fromTileY);624
position.tileX = message.tileX;628
position.tileX = message.tileX;625
position.tileY = message.tileY;629
position.tileY = message.tileY;630
syncCharacterChunkPresence(this.ecs, handle, Date.now());626
this.#occupy(message.entityId, position.tileX, position.tileY);631
this.#occupy(message.entityId, position.tileX, position.tileY);627
return {632
return {628
accepted: true,633
accepted: true,@@ -696,6 +701,7 @@ export class WorkerWorld696
position.tileX = destTileX;701
position.tileX = destTileX;697
position.tileY = destTileY;702
position.tileY = destTileY;698
position.dimensionId = dimensionId;703
position.dimensionId = dimensionId;704
syncCharacterChunkPresence(this.ecs, handle, Date.now());699
if (!this.#isFlying(handle))705
if (!this.#isFlying(handle))700
{ this.#occupy(message.entityId, destTileX, destTileY); }706
{ this.#occupy(message.entityId, destTileX, destTileY); }701
return {707
return {@@ -803,6 +809,7 @@ export class WorkerWorld803
const tileY = Math.floor(flight.y);809
const tileY = Math.floor(flight.y);804
position.tileX = tileX;810
position.tileX = tileX;805
position.tileY = tileY;811
position.tileY = tileY;812
syncCharacterChunkPresence(this.ecs, handle, now);806
const destRegionX = tileToRegion(tileX);813
const destRegionX = tileToRegion(tileX);807
const destRegionY = tileToRegion(tileY);814
const destRegionY = tileToRegion(tileY);808
const dimensionId = normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID);815
const dimensionId = normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID);@@ -1005,7 +1012,8 @@ export class WorkerWorld1005
type: "skills-updated",1012
type: "skills-updated",1006
entityId,1013
entityId,1007
characterId: character.characterId,1014
characterId: character.characterId,1008
skills: xpAward.view,1015
skills: xpAward.skills,1016
combatLevel: xpAward.combatLevel,1009
stored: xpAward.stored,1017
stored: xpAward.stored,1010
levelUps: xpAward.levelUps ?? []1018
levelUps: xpAward.levelUps ?? []1011
}]1019
}]@@ -1209,7 +1217,7 @@ export class WorkerWorld1209
type: "skills-updated",1217
type: "skills-updated",1210
entityId: this.ecs.entityIdOf(handle),1218
entityId: this.ecs.entityIdOf(handle),1211
characterId: character.characterId,1219
characterId: character.characterId,1212
skills: publicSkillsView(skills),1220
...publicSkillsPayload(skills),1213
stored: storedSkillXp(skills),1221
stored: storedSkillXp(skills),1214
levelUps1222
levelUps1215
});1223
});@@ -1465,6 +1473,7 @@ export class WorkerWorld1465
path.stuckTileY = position.tileY;1473
path.stuckTileY = position.tileY;1466
recordFollowTrail(this.ecs, entityId, fromTileX, fromTileY);1474
recordFollowTrail(this.ecs, entityId, fromTileX, fromTileY);1467
consumeFollowTrail(this.ecs, entityId, position.tileX, position.tileY);1475
consumeFollowTrail(this.ecs, entityId, position.tileX, position.tileY);1476
syncCharacterChunkPresence(this.ecs, handle, now);1468
if (!isWalk)1477
if (!isWalk)1469
{ this.#consumeRunStamina(handle, events); }1478
{ this.#consumeRunStamina(handle, events); }1470
events.push(this.#moveEvent(entityId, fromTileX, fromTileY));1479
events.push(this.#moveEvent(entityId, fromTileX, fromTileY));@@ -1,7 +1,7 @@
1
1
import { Component } from "../ecs/components.js";
2
2
import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";
3
3
import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";
4
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
4
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
5
5
6
6
export function syncPlayerHealth (ecs, handle)
7
7
{
@@ -49,7 +49,7 @@ export function awardCombatHitXp (ecs, attackerHandle, profile, damage)
49
49
if (!hit.changed && !damageSkill.changed)
50
50
{ return null; }
51
51
return {
52
view: publicSkillsView(skills),
52
...publicSkillsPayload(skills),
53
53
stored: storedSkillXp(skills),
54
54
levelUps
55
55
};
@@ -68,7 +68,7 @@ export function awardSpellCastXp (ecs, casterHandle, spellDifficulty)
68
68
const character = ecs.get(casterHandle, Component.character);
69
69
return {
70
70
characterId: character?.characterId ?? null,
71
view: publicSkillsView(skills),
71
...publicSkillsPayload(skills),
72
72
stored: storedSkillXp(skills),
73
73
levelUps: result.levelUp ? [result.levelUp] : []
74
74
};
@@ -95,7 +95,7 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)
95
95
syncPlayerHealth(ecs, targetHandle);
96
96
return {
97
97
characterId: character.characterId,
98
view: publicSkillsView(skills),
98
...publicSkillsPayload(skills),
99
99
stored: storedSkillXp(skills),
100
100
levelUps: result.levelUp ? [result.levelUp] : []
101
101
};
@@ -118,7 +118,7 @@ export function awardCombatAvoidanceXp (ecs, targetHandle, skillId, avoidedDamag
118
118
{ return null; }
119
119
return {
120
120
characterId: character.characterId,
121
view: publicSkillsView(skills),
121
...publicSkillsPayload(skills),
122
122
stored: storedSkillXp(skills),
123
123
levelUps: result.levelUp ? [result.levelUp] : []
124
124
};
@@ -1,7 +1,7 @@1
import { Component } from "../ecs/components.js";1
import { Component } from "../ecs/components.js";2
import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";2
import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";3
import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";3
import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";4
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";4
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";5
5
6
export function syncPlayerHealth (ecs, handle)6
export function syncPlayerHealth (ecs, handle)7
{7
{@@ -49,7 +49,7 @@ export function awardCombatHitXp (ecs, attackerHandle, profile, damage)49
if (!hit.changed && !damageSkill.changed)49
if (!hit.changed && !damageSkill.changed)50
{ return null; }50
{ return null; }51
return {51
return {52
view: publicSkillsView(skills),52
...publicSkillsPayload(skills),53
stored: storedSkillXp(skills),53
stored: storedSkillXp(skills),54
levelUps54
levelUps55
};55
};@@ -68,7 +68,7 @@ export function awardSpellCastXp (ecs, casterHandle, spellDifficulty)68
const character = ecs.get(casterHandle, Component.character);68
const character = ecs.get(casterHandle, Component.character);69
return {69
return {70
characterId: character?.characterId ?? null,70
characterId: character?.characterId ?? null,71
view: publicSkillsView(skills),71
...publicSkillsPayload(skills),72
stored: storedSkillXp(skills),72
stored: storedSkillXp(skills),73
levelUps: result.levelUp ? [result.levelUp] : []73
levelUps: result.levelUp ? [result.levelUp] : []74
};74
};@@ -95,7 +95,7 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)95
syncPlayerHealth(ecs, targetHandle);95
syncPlayerHealth(ecs, targetHandle);96
return {96
return {97
characterId: character.characterId,97
characterId: character.characterId,98
view: publicSkillsView(skills),98
...publicSkillsPayload(skills),99
stored: storedSkillXp(skills),99
stored: storedSkillXp(skills),100
levelUps: result.levelUp ? [result.levelUp] : []100
levelUps: result.levelUp ? [result.levelUp] : []101
};101
};@@ -118,7 +118,7 @@ export function awardCombatAvoidanceXp (ecs, targetHandle, skillId, avoidedDamag118
{ return null; }118
{ return null; }119
return {119
return {120
characterId: character.characterId,120
characterId: character.characterId,121
view: publicSkillsView(skills),121
...publicSkillsPayload(skills),122
stored: storedSkillXp(skills),122
stored: storedSkillXp(skills),123
levelUps: result.levelUp ? [result.levelUp] : []123
levelUps: result.levelUp ? [result.levelUp] : []124
};124
};@@ -43,7 +43,7 @@ import
43
43
resolveCombatTarget,
44
44
applyDamageAndKill
45
45
} from "../combat/service.js";
46
import { publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
46
import { storedSkillXp } from "../../../shared/skills/state.js";
47
47
import { spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";
48
48
import { publicSpellLight, SpellLightRegistry } from "./lights.js";
49
49
import { spellbookInstance, spellbookItemIdForSpell, spellIdFromSpellbookStack } from "../../../shared/definitions/spellItems.js";
@@ -466,7 +466,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
466
466
type: "skills-updated",
467
467
entityId,
468
468
characterId: character.characterId,
469
skills: xpAward.view,
469
skills: xpAward.skills,
470
combatLevel: xpAward.combatLevel,
470
471
stored: xpAward.stored,
471
472
levelUps: xpAward.levelUps ?? []
472
473
});
@@ -681,7 +682,8 @@ function awardMagicHitXp (world, impact, damage)
681
682
type: "skills-updated",
682
683
entityId: impact.casterEntityId,
683
684
characterId: impact.casterCharacterId,
684
skills: xp.view,
685
skills: xp.skills,
686
combatLevel: xp.combatLevel,
685
687
stored: xp.stored,
686
688
levelUps: xp.levelUps ?? []
687
689
});
@@ -43,7 +43,7 @@ import43
resolveCombatTarget,43
resolveCombatTarget,44
applyDamageAndKill44
applyDamageAndKill45
} from "../combat/service.js";45
} from "../combat/service.js";46
import { publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";46
import { storedSkillXp } from "../../../shared/skills/state.js";47
import { spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";47
import { spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";48
import { publicSpellLight, SpellLightRegistry } from "./lights.js";48
import { publicSpellLight, SpellLightRegistry } from "./lights.js";49
import { spellbookInstance, spellbookItemIdForSpell, spellIdFromSpellbookStack } from "../../../shared/definitions/spellItems.js";49
import { spellbookInstance, spellbookItemIdForSpell, spellIdFromSpellbookStack } from "../../../shared/definitions/spellItems.js";@@ -466,7 +466,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)466
type: "skills-updated",466
type: "skills-updated",467
entityId,467
entityId,468
characterId: character.characterId,468
characterId: character.characterId,469
skills: xpAward.view,469
skills: xpAward.skills,470
combatLevel: xpAward.combatLevel,470
stored: xpAward.stored,471
stored: xpAward.stored,471
levelUps: xpAward.levelUps ?? []472
levelUps: xpAward.levelUps ?? []472
});473
});@@ -681,7 +682,8 @@ function awardMagicHitXp (world, impact, damage)681
type: "skills-updated",682
type: "skills-updated",682
entityId: impact.casterEntityId,683
entityId: impact.casterEntityId,683
characterId: impact.casterCharacterId,684
characterId: impact.casterCharacterId,684
skills: xp.view,685
skills: xp.skills,686
combatLevel: xp.combatLevel,685
stored: xp.stored,687
stored: xp.stored,686
levelUps: xp.levelUps ?? []688
levelUps: xp.levelUps ?? []687
});689
});@@ -5,7 +5,7 @@ import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
5
5
import { itemDefinition } from "../../../shared/definitions/items.js";
6
6
import { cookedFishItemId } from "../../../shared/definitions/fishItems.js";
7
7
import { SkillId } from "../../../shared/definitions/skills.js";
8
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
8
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
9
9
import { rollSkill } from "../../../shared/combat/rolls.js";
10
10
import { firestartingDifficulty, campfireDurationMs } from "../../../shared/definitions/craftingStations.js";
11
11
import { MATERIAL_DISPLAY_NAME } from "../../../shared/definitions/materialTiers.js";
@@ -274,7 +274,7 @@ export function applyTindersAtTile (world, impact, now)
274
274
type: "skills-updated",
275
275
entityId: impact.casterEntityId,
276
276
characterId: impact.casterCharacterId,
277
skills: publicSkillsView(skills),
277
...publicSkillsPayload(skills),
278
278
stored: storedSkillXp(skills),
279
279
levelUps: result.levelUp ? [result.levelUp] : []
280
280
});
@@ -5,7 +5,7 @@ import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";5
import { itemDefinition } from "../../../shared/definitions/items.js";5
import { itemDefinition } from "../../../shared/definitions/items.js";6
import { cookedFishItemId } from "../../../shared/definitions/fishItems.js";6
import { cookedFishItemId } from "../../../shared/definitions/fishItems.js";7
import { SkillId } from "../../../shared/definitions/skills.js";7
import { SkillId } from "../../../shared/definitions/skills.js";8
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";8
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";9
import { rollSkill } from "../../../shared/combat/rolls.js";9
import { rollSkill } from "../../../shared/combat/rolls.js";10
import { firestartingDifficulty, campfireDurationMs } from "../../../shared/definitions/craftingStations.js";10
import { firestartingDifficulty, campfireDurationMs } from "../../../shared/definitions/craftingStations.js";11
import { MATERIAL_DISPLAY_NAME } from "../../../shared/definitions/materialTiers.js";11
import { MATERIAL_DISPLAY_NAME } from "../../../shared/definitions/materialTiers.js";@@ -274,7 +274,7 @@ export function applyTindersAtTile (world, impact, now)274
type: "skills-updated",274
type: "skills-updated",275
entityId: impact.casterEntityId,275
entityId: impact.casterEntityId,276
characterId: impact.casterCharacterId,276
characterId: impact.casterCharacterId,277
skills: publicSkillsView(skills),277
...publicSkillsPayload(skills),278
stored: storedSkillXp(skills),278
stored: storedSkillXp(skills),279
levelUps: result.levelUp ? [result.levelUp] : []279
levelUps: result.levelUp ? [result.levelUp] : []280
});280
});@@ -0,0 +1,148 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import {
4
combatLevelFromSkills,
5
mobAggressionLevel,
6
playerOutlevelsMobAggression
7
} from "../../shared/combat/combatLevel.js";
8
import { CHUNK_AGGRO_PEACE_MS, chunkPeaceAggressionImmunity } from "../../shared/navigation/chunkPresence.js";
9
import { normalizePlayerSkills } from "../../shared/skills/state.js";
10
import { SkillId } from "../../shared/definitions/skills.js";
11
import { totalXpForLevel } from "../../shared/skills/progression.js";
12
import { mobComponents } from "../src/simulation/spawners.js";
13
import { MobId } from "../../shared/definitions/mobs.js";
14
import { Component } from "../src/ecs/components.js";
15
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
17
18
function componentsOf (simulation, entityId)
19
{
20
const record = simulation.entityRecord(entityId);
21
const worker = simulation.workers[record.workerId];
22
const handle = worker.world.ecs.handleOf(entityId);
23
const out = {};
24
for (const key of Object.values(Component))
25
{
26
const value = worker.world.ecs.get(handle, key);
27
if (value != null)
28
{ out[key] = value; }
29
}
30
return out;
31
}
32
33
const COMBAT_SKILL_IDS = [
34
SkillId.health,
35
SkillId.defence,
36
SkillId.agility,
37
SkillId.strength,
38
SkillId.swordfighting,
39
SkillId.axefighting,
40
SkillId.unarmed,
41
SkillId.clubfighting,
42
SkillId.archery,
43
SkillId.dexterity,
44
SkillId.magic,
45
SkillId.mind
46
];
47
48
function skillsAtLevel (level)
49
{
50
const xp = {};
51
for (const skillId of COMBAT_SKILL_IDS)
52
{ xp[skillId] = totalXpForLevel(level); }
53
return normalizePlayerSkills(xp);
54
}
55
56
test("combatLevelFromSkills applies D + max(M, R, S)", () =>
57
{
58
const starter = defaultPlayerSkills();
59
assert.equal(combatLevelFromSkills(starter), 3);
60
61
const focused = skillsAtLevel(30);
62
assert.equal(combatLevelFromSkills(focused), 40);
63
});
64
65
test("playerOutlevelsMobAggression requires combat level above 2× mob + 1", () =>
66
{
67
assert.equal(playerOutlevelsMobAggression(3, 1), false);
68
assert.equal(playerOutlevelsMobAggression(4, 1), true);
69
assert.equal(playerOutlevelsMobAggression(10, 4), true);
70
assert.equal(playerOutlevelsMobAggression(9, 4), false);
71
});
72
73
test("mobAggressionLevel prefers creature and spawn origin levels", () =>
74
{
75
assert.equal(mobAggressionLevel({ level: 7 }, null, { attackSkill: 1 }), 7);
76
assert.equal(mobAggressionLevel({}, { level: 5 }, { attackSkill: 1 }), 5);
77
assert.equal(mobAggressionLevel({}, null, { attackSkill: 2 }), 2);
78
});
79
80
test("chunkPeaceAggressionImmunity after fifteen minutes in the same chunk", () =>
81
{
82
const tileToChunk = (tile) => Math.floor(tile / CHUNK_SIZE);
83
const presence = { chunkX: 0, chunkY: 0, dimensionId: "overworld", sinceMs: 1_000 };
84
assert.equal(
85
chunkPeaceAggressionImmunity(presence, 8, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS - 1, tileToChunk),
86
false
87
);
88
assert.equal(
89
chunkPeaceAggressionImmunity(presence, 8, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS, tileToChunk),
90
true
91
);
92
assert.equal(
93
chunkPeaceAggressionImmunity(presence, 256, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS, tileToChunk),
94
false
95
);
96
});
97
98
test("high combat level players are ignored by aggressive rats", () =>
99
{
100
const harness = makeSimulation({ workerCount: 1 });
101
try
102
{
103
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
104
harness.stateDb.saveSkills(character.character_id, skillsAtLevel(30));
105
const playerId = harness.simulation.spawnCharacter(1, character);
106
const ratId = harness.simulation.spawnEntity(mobComponents({
107
tileX: 12,
108
tileY: 8,
109
mobTypeId: MobId.rat,
110
spawnerId: null
111
}));
112
113
harness.simulation.step();
114
assert.notEqual(componentsOf(harness.simulation, ratId).combat?.targetEntityId, playerId);
115
}
116
finally
117
{ harness.close(); }
118
});
119
120
test("chunk peace prevents aggressive rats from auto-aggroing", () =>
121
{
122
const harness = makeSimulation({ workerCount: 1 });
123
try
124
{
125
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
126
const playerId = harness.simulation.spawnCharacter(1, character);
127
harness.advance(CHUNK_AGGRO_PEACE_MS + 1);
128
const ratId = harness.simulation.spawnEntity(mobComponents({
129
tileX: 12,
130
tileY: 8,
131
mobTypeId: MobId.rat,
132
spawnerId: null
133
}));
134
135
harness.simulation.step();
136
assert.notEqual(componentsOf(harness.simulation, ratId).combat?.targetEntityId, playerId);
137
}
138
finally
139
{ harness.close(); }
140
});
141
142
function defaultPlayerSkills ()
143
{
144
return normalizePlayerSkills({
145
[SkillId.health]: totalXpForLevel(10),
146
[SkillId.stamina]: totalXpForLevel(5)
147
});
148
}
@@ -0,0 +1,148 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import {4
combatLevelFromSkills,5
mobAggressionLevel,6
playerOutlevelsMobAggression7
} from "../../shared/combat/combatLevel.js";8
import { CHUNK_AGGRO_PEACE_MS, chunkPeaceAggressionImmunity } from "../../shared/navigation/chunkPresence.js";9
import { normalizePlayerSkills } from "../../shared/skills/state.js";10
import { SkillId } from "../../shared/definitions/skills.js";11
import { totalXpForLevel } from "../../shared/skills/progression.js";12
import { mobComponents } from "../src/simulation/spawners.js";13
import { MobId } from "../../shared/definitions/mobs.js";14
import { Component } from "../src/ecs/components.js";15
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";17
18
function componentsOf (simulation, entityId)19
{20
const record = simulation.entityRecord(entityId);21
const worker = simulation.workers[record.workerId];22
const handle = worker.world.ecs.handleOf(entityId);23
const out = {};24
for (const key of Object.values(Component))25
{26
const value = worker.world.ecs.get(handle, key);27
if (value != null)28
{ out[key] = value; }29
}30
return out;31
}32
33
const COMBAT_SKILL_IDS = [34
SkillId.health,35
SkillId.defence,36
SkillId.agility,37
SkillId.strength,38
SkillId.swordfighting,39
SkillId.axefighting,40
SkillId.unarmed,41
SkillId.clubfighting,42
SkillId.archery,43
SkillId.dexterity,44
SkillId.magic,45
SkillId.mind46
];47
48
function skillsAtLevel (level)49
{50
const xp = {};51
for (const skillId of COMBAT_SKILL_IDS)52
{ xp[skillId] = totalXpForLevel(level); }53
return normalizePlayerSkills(xp);54
}55
56
test("combatLevelFromSkills applies D + max(M, R, S)", () =>57
{58
const starter = defaultPlayerSkills();59
assert.equal(combatLevelFromSkills(starter), 3);60
61
const focused = skillsAtLevel(30);62
assert.equal(combatLevelFromSkills(focused), 40);63
});64
65
test("playerOutlevelsMobAggression requires combat level above 2× mob + 1", () =>66
{67
assert.equal(playerOutlevelsMobAggression(3, 1), false);68
assert.equal(playerOutlevelsMobAggression(4, 1), true);69
assert.equal(playerOutlevelsMobAggression(10, 4), true);70
assert.equal(playerOutlevelsMobAggression(9, 4), false);71
});72
73
test("mobAggressionLevel prefers creature and spawn origin levels", () =>74
{75
assert.equal(mobAggressionLevel({ level: 7 }, null, { attackSkill: 1 }), 7);76
assert.equal(mobAggressionLevel({}, { level: 5 }, { attackSkill: 1 }), 5);77
assert.equal(mobAggressionLevel({}, null, { attackSkill: 2 }), 2);78
});79
80
test("chunkPeaceAggressionImmunity after fifteen minutes in the same chunk", () =>81
{82
const tileToChunk = (tile) => Math.floor(tile / CHUNK_SIZE);83
const presence = { chunkX: 0, chunkY: 0, dimensionId: "overworld", sinceMs: 1_000 };84
assert.equal(85
chunkPeaceAggressionImmunity(presence, 8, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS - 1, tileToChunk),86
false87
);88
assert.equal(89
chunkPeaceAggressionImmunity(presence, 8, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS, tileToChunk),90
true91
);92
assert.equal(93
chunkPeaceAggressionImmunity(presence, 256, 8, "overworld", 1_000 + CHUNK_AGGRO_PEACE_MS, tileToChunk),94
false95
);96
});97
98
test("high combat level players are ignored by aggressive rats", () =>99
{100
const harness = makeSimulation({ workerCount: 1 });101
try102
{103
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });104
harness.stateDb.saveSkills(character.character_id, skillsAtLevel(30));105
const playerId = harness.simulation.spawnCharacter(1, character);106
const ratId = harness.simulation.spawnEntity(mobComponents({107
tileX: 12,108
tileY: 8,109
mobTypeId: MobId.rat,110
spawnerId: null111
}));112
113
harness.simulation.step();114
assert.notEqual(componentsOf(harness.simulation, ratId).combat?.targetEntityId, playerId);115
}116
finally117
{ harness.close(); }118
});119
120
test("chunk peace prevents aggressive rats from auto-aggroing", () =>121
{122
const harness = makeSimulation({ workerCount: 1 });123
try124
{125
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });126
const playerId = harness.simulation.spawnCharacter(1, character);127
harness.advance(CHUNK_AGGRO_PEACE_MS + 1);128
const ratId = harness.simulation.spawnEntity(mobComponents({129
tileX: 12,130
tileY: 8,131
mobTypeId: MobId.rat,132
spawnerId: null133
}));134
135
harness.simulation.step();136
assert.notEqual(componentsOf(harness.simulation, ratId).combat?.targetEntityId, playerId);137
}138
finally139
{ harness.close(); }140
});141
142
function defaultPlayerSkills ()143
{144
return normalizePlayerSkills({145
[SkillId.health]: totalXpForLevel(10),146
[SkillId.stamina]: totalXpForLevel(5)147
});148
}@@ -1,6 +1,6 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { mobCanFight, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";
3
import { mobCanFight, mobIsBoss, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";
4
4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";
5
5
import { SkillId } from "../../shared/definitions/skills.js";
6
6
@@ -11,6 +11,12 @@ test("living targetable mobs can fight except pigeons", () =>
11
11
assert.equal(mobCanFight(mobDefinition(MobId.pigeon)), false);
12
12
});
13
13
14
test("mobIsBoss is false for normal mobs", () =>
15
{
16
assert.equal(mobIsBoss(mobDefinition(MobId.rat)), false);
17
assert.equal(mobIsBoss({ boss: true }), true);
18
});
19
14
20
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>
15
21
{
16
22
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
@@ -1,6 +1,6 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { mobCanFight, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";3
import { mobCanFight, mobIsBoss, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";5
import { SkillId } from "../../shared/definitions/skills.js";5
import { SkillId } from "../../shared/definitions/skills.js";6
6
@@ -11,6 +11,12 @@ test("living targetable mobs can fight except pigeons", () =>11
assert.equal(mobCanFight(mobDefinition(MobId.pigeon)), false);11
assert.equal(mobCanFight(mobDefinition(MobId.pigeon)), false);12
});12
});13
13
14
test("mobIsBoss is false for normal mobs", () =>15
{16
assert.equal(mobIsBoss(mobDefinition(MobId.rat)), false);17
assert.equal(mobIsBoss({ boss: true }), true);18
});19
14
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>20
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>15
{21
{16
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));22
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));@@ -46,6 +46,12 @@ test("goblin spawner defaults level 5 without equipment", () =>
46
46
assert.equal(config.equipment.weapon, null);
47
47
});
48
48
49
test("shade spawner defaults level 28", () =>
50
{
51
const config = normalizeSpawnerConfig({ mobTypeId: MobId.shade }, "shade-1");
52
assert.equal(config.level, 28);
53
});
54
49
55
test("goblin spawns with slashing melee profile from mob definition", () =>
50
56
{
51
57
const harness = makeSimulation({ workerCount: 1 });
@@ -46,6 +46,12 @@ test("goblin spawner defaults level 5 without equipment", () =>46
assert.equal(config.equipment.weapon, null);46
assert.equal(config.equipment.weapon, null);47
});47
});48
48
49
test("shade spawner defaults level 28", () =>50
{51
const config = normalizeSpawnerConfig({ mobTypeId: MobId.shade }, "shade-1");52
assert.equal(config.level, 28);53
});54
49
test("goblin spawns with slashing melee profile from mob definition", () =>55
test("goblin spawns with slashing melee profile from mob definition", () =>50
{56
{51
const harness = makeSimulation({ workerCount: 1 });57
const harness = makeSimulation({ workerCount: 1 });@@ -18,6 +18,7 @@ import { normalizePlayerSpells } from "../../shared/spells/state.js";
18
18
import { createSpellbookStack } from "../src/spells/service.js";
19
19
import { SkillId } from "../../shared/definitions/skills.js";
20
20
import { totalXpForLevel } from "../../shared/skills/progression.js";
21
import { engageTarget, ensureMobCombat } from "../src/combat/service.js";
21
22
22
23
function workerOf (simulation, entityId)
23
24
{
@@ -526,8 +527,8 @@ test("auto-retaliate does not engage while auto-casting an attack spell", () =>
526
527
const handle = worker.world.ecs.handleOf(playerId);
527
528
const deerHandle = worker.world.ecs.handleOf(deerId);
528
529
const deerHealth = worker.world.ecs.get(deerHandle, Component.health);
529
deerHealth.max = 500;
530
deerHealth.current = 500;
530
deerHealth.max = 500_000;
531
deerHealth.current = 500_000;
531
532
const spells = worker.world.ecs.get(handle, Component.spells);
532
533
spells.known.push(SpellId.manaBullet);
533
534
spells.autoCast = true;
@@ -544,6 +545,8 @@ test("auto-retaliate does not engage while auto-casting an attack spell", () =>
544
545
harness.simulation.step();
545
546
assert.equal(worker.world.ecs.get(handle, Component.spellcasting).repeatSpellId, SpellId.manaBullet);
546
547
assert.equal(worker.world.ecs.get(handle, Component.combat)?.targetEntityId ?? null, null);
548
assert.ok(ensureMobCombat(worker.world.ecs, ratId));
549
engageTarget(worker.world.ecs, ratId, playerId, harness.now());
547
550
548
551
let ratSwung = false;
549
552
for (let i = 0; i < 80; i++)
@@ -18,6 +18,7 @@ import { normalizePlayerSpells } from "../../shared/spells/state.js";18
import { createSpellbookStack } from "../src/spells/service.js";18
import { createSpellbookStack } from "../src/spells/service.js";19
import { SkillId } from "../../shared/definitions/skills.js";19
import { SkillId } from "../../shared/definitions/skills.js";20
import { totalXpForLevel } from "../../shared/skills/progression.js";20
import { totalXpForLevel } from "../../shared/skills/progression.js";21
import { engageTarget, ensureMobCombat } from "../src/combat/service.js";21
22
22
function workerOf (simulation, entityId)23
function workerOf (simulation, entityId)23
{24
{@@ -526,8 +527,8 @@ test("auto-retaliate does not engage while auto-casting an attack spell", () =>526
const handle = worker.world.ecs.handleOf(playerId);527
const handle = worker.world.ecs.handleOf(playerId);527
const deerHandle = worker.world.ecs.handleOf(deerId);528
const deerHandle = worker.world.ecs.handleOf(deerId);528
const deerHealth = worker.world.ecs.get(deerHandle, Component.health);529
const deerHealth = worker.world.ecs.get(deerHandle, Component.health);529
deerHealth.max = 500;530
deerHealth.max = 500_000;530
deerHealth.current = 500;531
deerHealth.current = 500_000;531
const spells = worker.world.ecs.get(handle, Component.spells);532
const spells = worker.world.ecs.get(handle, Component.spells);532
spells.known.push(SpellId.manaBullet);533
spells.known.push(SpellId.manaBullet);533
spells.autoCast = true;534
spells.autoCast = true;@@ -544,6 +545,8 @@ test("auto-retaliate does not engage while auto-casting an attack spell", () =>544
harness.simulation.step();545
harness.simulation.step();545
assert.equal(worker.world.ecs.get(handle, Component.spellcasting).repeatSpellId, SpellId.manaBullet);546
assert.equal(worker.world.ecs.get(handle, Component.spellcasting).repeatSpellId, SpellId.manaBullet);546
assert.equal(worker.world.ecs.get(handle, Component.combat)?.targetEntityId ?? null, null);547
assert.equal(worker.world.ecs.get(handle, Component.combat)?.targetEntityId ?? null, null);548
assert.ok(ensureMobCombat(worker.world.ecs, ratId));549
engageTarget(worker.world.ecs, ratId, playerId, harness.now());547
550
548
let ratSwung = false;551
let ratSwung = false;549
for (let i = 0; i < 80; i++)552
for (let i = 0; i < 80; i++)