Add skill level-up toasts and overhead floats for nearby players.
Server detects level-ups when awarding XP and broadcasts a public event; the local player also gets a HUD toast.
@@ -304,6 +304,7 @@
304
304
305
305
<div id="nametag" hidden></div>
306
306
<div id="damage-numbers"></div>
307
<div id="skill-level-floats"></div>
307
308
<div id="chat-bubbles"></div>
308
309
<div id="chat-bar" hidden>
309
310
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">
@@ -304,6 +304,7 @@304
304
305
<div id="nametag" hidden></div>305
<div id="nametag" hidden></div>306
<div id="damage-numbers"></div>306
<div id="damage-numbers"></div>307
<div id="skill-level-floats"></div>307
<div id="chat-bubbles"></div>308
<div id="chat-bubbles"></div>308
<div id="chat-bar" hidden>309
<div id="chat-bar" hidden>309
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">310
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">@@ -968,6 +968,14 @@ async function main ()
968
968
view?.flashDamage(message.targetId);
969
969
view?.spawnDamageNumber(message.targetId, message.damage);
970
970
break;
971
case MessageType.skillLevelUp:
972
view?.spawnSkillLevelUp(message.entityId, message);
973
if (message.entityId === view?.localEntityId)
974
{
975
const name = message.displayName ?? message.skillId ?? "Skill";
976
toasts?.show(`${name} level ${message.level}!`);
977
}
978
break;
971
979
case MessageType.playerDied:
972
980
clearAllPendingActions();
973
981
contextMenu?.hide();
@@ -968,6 +968,14 @@ async function main ()968
view?.flashDamage(message.targetId);968
view?.flashDamage(message.targetId);969
view?.spawnDamageNumber(message.targetId, message.damage);969
view?.spawnDamageNumber(message.targetId, message.damage);970
break;970
break;971
case MessageType.skillLevelUp:972
view?.spawnSkillLevelUp(message.entityId, message);973
if (message.entityId === view?.localEntityId)974
{975
const name = message.displayName ?? message.skillId ?? "Skill";976
toasts?.show(`${name} level ${message.level}!`);977
}978
break;971
case MessageType.playerDied:979
case MessageType.playerDied:972
clearAllPendingActions();980
clearAllPendingActions();973
contextMenu?.hide();981
contextMenu?.hide();@@ -32,6 +32,7 @@ const SHOVE_MS = 280;
32
32
const GATHER_TOOL_HOLD_MS = 1100;
33
33
const DAMAGE_FLASH_MS = 180;
34
34
const DAMAGE_FLOAT_MS = 900;
35
const SKILL_LEVEL_FLOAT_MS = 2800;
35
36
36
37
const SPRITE_LIGHTING_FRAG = [
37
38
"precision mediump float;",
@@ -212,6 +213,8 @@ export class WorldView
212
213
this.swipes = [];
213
214
this.damageFloats = [];
214
215
this.damageNumbersEl = document.getElementById("damage-numbers");
216
this.skillLevelFloats = [];
217
this.skillLevelFloatsEl = document.getElementById("skill-level-floats");
215
218
/** @type {Map<string, { object: object, tileX: number, tileY: number, spriteName: string }>} */
216
219
this.editorSpawners = new Map();
217
220
this.spawnRangeHighlight = null;
@@ -408,6 +411,20 @@ export class WorldView
408
411
});
409
412
}
410
413
414
spawnSkillLevelUp (entityId, payload)
415
{
416
const level = payload?.level | 0;
417
if (level <= 0 || !payload?.icon)
418
{ return; }
419
this.skillLevelFloats.push({
420
entityId,
421
level,
422
icon: payload.icon,
423
displayName: payload.displayName ?? payload.skillId ?? "",
424
started: performance.now()
425
});
426
}
427
411
428
setAppearance (payload)
412
429
{
413
430
const existing = this.entities.get(payload.entityId);
@@ -612,6 +629,7 @@ export class WorldView
612
629
613
630
this.#updateSwipes(now);
614
631
this.#updateDamageNumbers(now);
632
this.#updateSkillLevelFloats(now);
615
633
this.#centerCamera();
616
634
this.#updateShade(deltaTime);
617
635
}
@@ -2050,6 +2068,54 @@ export class WorldView
2050
2068
});
2051
2069
}
2052
2070
2071
#updateSkillLevelFloats (now)
2072
{
2073
const layer = this.skillLevelFloatsEl;
2074
if (!layer)
2075
{ return; }
2076
this.skillLevelFloats = this.skillLevelFloats.filter((entry) =>
2077
{
2078
const elapsed = now - entry.started;
2079
if (elapsed >= SKILL_LEVEL_FLOAT_MS)
2080
{
2081
entry.element?.remove();
2082
return false;
2083
}
2084
const entity = this.entities.get(entry.entityId);
2085
if (!entity)
2086
{
2087
entry.element?.remove();
2088
return false;
2089
}
2090
if (!entry.element)
2091
{
2092
const root = document.createElement("div");
2093
root.className = "skill-level-float";
2094
2095
const levelEl = document.createElement("div");
2096
levelEl.className = "skill-level-float-level";
2097
levelEl.textContent = `↑${entry.level}↑`;
2098
2099
const icon = document.createElement("img");
2100
icon.className = "skill-level-float-icon";
2101
icon.src = entry.icon;
2102
icon.alt = entry.displayName || "";
2103
2104
root.append(levelEl, icon);
2105
entry.element = root;
2106
layer.append(entry.element);
2107
}
2108
const anchor = this.nametagAnchor(entity);
2109
if (!anchor)
2110
{ return true; }
2111
const t = elapsed / SKILL_LEVEL_FLOAT_MS;
2112
entry.element.style.left = `${anchor.x}px`;
2113
entry.element.style.top = `${anchor.y - 10 - t * 18}px`;
2114
entry.element.style.opacity = String(Math.max(0, 1 - t * 0.85));
2115
return true;
2116
});
2117
}
2118
2053
2119
#syncBloomLayer ()
2054
2120
{
2055
2121
const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;
@@ -32,6 +32,7 @@ const SHOVE_MS = 280;32
const GATHER_TOOL_HOLD_MS = 1100;32
const GATHER_TOOL_HOLD_MS = 1100;33
const DAMAGE_FLASH_MS = 180;33
const DAMAGE_FLASH_MS = 180;34
const DAMAGE_FLOAT_MS = 900;34
const DAMAGE_FLOAT_MS = 900;35
const SKILL_LEVEL_FLOAT_MS = 2800;35
36
36
const SPRITE_LIGHTING_FRAG = [37
const SPRITE_LIGHTING_FRAG = [37
"precision mediump float;",38
"precision mediump float;",@@ -212,6 +213,8 @@ export class WorldView212
this.swipes = [];213
this.swipes = [];213
this.damageFloats = [];214
this.damageFloats = [];214
this.damageNumbersEl = document.getElementById("damage-numbers");215
this.damageNumbersEl = document.getElementById("damage-numbers");216
this.skillLevelFloats = [];217
this.skillLevelFloatsEl = document.getElementById("skill-level-floats");215
/** @type {Map<string, { object: object, tileX: number, tileY: number, spriteName: string }>} */218
/** @type {Map<string, { object: object, tileX: number, tileY: number, spriteName: string }>} */216
this.editorSpawners = new Map();219
this.editorSpawners = new Map();217
this.spawnRangeHighlight = null;220
this.spawnRangeHighlight = null;@@ -408,6 +411,20 @@ export class WorldView408
});411
});409
}412
}410
413
414
spawnSkillLevelUp (entityId, payload)415
{416
const level = payload?.level | 0;417
if (level <= 0 || !payload?.icon)418
{ return; }419
this.skillLevelFloats.push({420
entityId,421
level,422
icon: payload.icon,423
displayName: payload.displayName ?? payload.skillId ?? "",424
started: performance.now()425
});426
}427
411
setAppearance (payload)428
setAppearance (payload)412
{429
{413
const existing = this.entities.get(payload.entityId);430
const existing = this.entities.get(payload.entityId);@@ -612,6 +629,7 @@ export class WorldView612
629
613
this.#updateSwipes(now);630
this.#updateSwipes(now);614
this.#updateDamageNumbers(now);631
this.#updateDamageNumbers(now);632
this.#updateSkillLevelFloats(now);615
this.#centerCamera();633
this.#centerCamera();616
this.#updateShade(deltaTime);634
this.#updateShade(deltaTime);617
}635
}@@ -2050,6 +2068,54 @@ export class WorldView2050
});2068
});2051
}2069
}2052
2070
2071
#updateSkillLevelFloats (now)2072
{2073
const layer = this.skillLevelFloatsEl;2074
if (!layer)2075
{ return; }2076
this.skillLevelFloats = this.skillLevelFloats.filter((entry) =>2077
{2078
const elapsed = now - entry.started;2079
if (elapsed >= SKILL_LEVEL_FLOAT_MS)2080
{2081
entry.element?.remove();2082
return false;2083
}2084
const entity = this.entities.get(entry.entityId);2085
if (!entity)2086
{2087
entry.element?.remove();2088
return false;2089
}2090
if (!entry.element)2091
{2092
const root = document.createElement("div");2093
root.className = "skill-level-float";2094
2095
const levelEl = document.createElement("div");2096
levelEl.className = "skill-level-float-level";2097
levelEl.textContent = `↑${entry.level}↑`;2098
2099
const icon = document.createElement("img");2100
icon.className = "skill-level-float-icon";2101
icon.src = entry.icon;2102
icon.alt = entry.displayName || "";2103
2104
root.append(levelEl, icon);2105
entry.element = root;2106
layer.append(entry.element);2107
}2108
const anchor = this.nametagAnchor(entity);2109
if (!anchor)2110
{ return true; }2111
const t = elapsed / SKILL_LEVEL_FLOAT_MS;2112
entry.element.style.left = `${anchor.x}px`;2113
entry.element.style.top = `${anchor.y - 10 - t * 18}px`;2114
entry.element.style.opacity = String(Math.max(0, 1 - t * 0.85));2115
return true;2116
});2117
}2118
2053
#syncBloomLayer ()2119
#syncBloomLayer ()2054
{2120
{2055
const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;2121
const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;@@ -932,6 +932,41 @@ a { color: #d4c48a; }
932
932
user-select: none;
933
933
}
934
934
935
#skill-level-floats {
936
position: fixed;
937
inset: 0;
938
z-index: 4;
939
pointer-events: none;
940
overflow: hidden;
941
}
942
943
.skill-level-float {
944
position: absolute;
945
transform: translate(-50%, -100%);
946
display: flex;
947
flex-direction: column;
948
align-items: center;
949
gap: 0.15rem;
950
pointer-events: none;
951
user-select: none;
952
}
953
954
.skill-level-float-level {
955
font-size: 0.8rem;
956
font-weight: 700;
957
color: #ffe8a8;
958
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
959
line-height: 1;
960
letter-spacing: 0.02em;
961
}
962
963
.skill-level-float-icon {
964
width: 28px;
965
height: 28px;
966
image-rendering: pixelated;
967
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.85));
968
}
969
935
970
#shop-panel {
936
971
position: fixed;
937
972
z-index: 6;
@@ -932,6 +932,41 @@ a { color: #d4c48a; }932
user-select: none;932
user-select: none;933
}933
}934
934
935
#skill-level-floats {936
position: fixed;937
inset: 0;938
z-index: 4;939
pointer-events: none;940
overflow: hidden;941
}942
943
.skill-level-float {944
position: absolute;945
transform: translate(-50%, -100%);946
display: flex;947
flex-direction: column;948
align-items: center;949
gap: 0.15rem;950
pointer-events: none;951
user-select: none;952
}953
954
.skill-level-float-level {955
font-size: 0.8rem;956
font-weight: 700;957
color: #ffe8a8;958
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);959
line-height: 1;960
letter-spacing: 0.02em;961
}962
963
.skill-level-float-icon {964
width: 28px;965
height: 28px;966
image-rendering: pixelated;967
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.85));968
}969
935
#shop-panel {970
#shop-panel {936
position: fixed;971
position: fixed;937
z-index: 6;972
z-index: 6;@@ -579,7 +579,8 @@ function applyLocalMeleeHit (
579
579
entityId: targetId,
580
580
characterId: healthXp.characterId,
581
581
skills: healthXp.view,
582
stored: healthXp.stored
582
stored: healthXp.stored,
583
levelUps: healthXp.levelUps ?? []
583
584
});
584
585
if (health)
585
586
{
@@ -605,7 +606,8 @@ function applyLocalMeleeHit (
605
606
entityId: attackerId,
606
607
characterId: attackerCharacter.characterId,
607
608
skills: xpAward.view,
608
stored: xpAward.stored
609
stored: xpAward.stored,
610
levelUps: xpAward.levelUps ?? []
609
611
});
610
612
}
611
613
}
@@ -579,7 +579,8 @@ function applyLocalMeleeHit (579
entityId: targetId,579
entityId: targetId,580
characterId: healthXp.characterId,580
characterId: healthXp.characterId,581
skills: healthXp.view,581
skills: healthXp.view,582
stored: healthXp.stored582
stored: healthXp.stored,583
levelUps: healthXp.levelUps ?? []583
});584
});584
if (health)585
if (health)585
{586
{@@ -605,7 +606,8 @@ function applyLocalMeleeHit (605
entityId: attackerId,606
entityId: attackerId,606
characterId: attackerCharacter.characterId,607
characterId: attackerCharacter.characterId,607
skills: xpAward.view,608
skills: xpAward.view,608
stored: xpAward.stored609
stored: xpAward.stored,610
levelUps: xpAward.levelUps ?? []609
});611
});610
}612
}611
}613
}@@ -17,7 +17,7 @@ import {
17
17
craftOrigin,
18
18
craftOriginVerbForStation
19
19
} from "../../../shared/items/origin.js";
20
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
20
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
21
21
import { bagView } from "../items/bags.js";
22
22
import { tileToChunk, tileToLocal } from "../world/coordinates.js";
23
23
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
@@ -305,10 +305,18 @@ export function stepCrafting (world, now)
305
305
inventory.slots = added.slots;
306
306
307
307
let skillsChanged = false;
308
const levelUps = [];
308
309
if (skills?.xp && recipe.xpMaterial && stationDef?.skillId)
309
310
{
310
if (addSkillXp(skills, stationDef.skillId, smeltingXpForMaterial(recipe.xpMaterial)))
311
const result = applySkillXp(
312
skills,
313
stationDef.skillId,
314
smeltingXpForMaterial(recipe.xpMaterial)
315
);
316
if (result.changed)
311
317
{ skillsChanged = true; }
318
if (result.levelUp)
319
{ levelUps.push(result.levelUp); }
312
320
}
313
321
314
322
privates.push({ characterId, bag: bagView(world.ecs, handle) });
@@ -316,9 +324,11 @@ export function stepCrafting (world, now)
316
324
{
317
325
events.push({
318
326
type: "skills-updated",
327
entityId,
319
328
characterId,
320
329
skills: publicSkillsView(skills),
321
stored: storedSkillXp(skills)
330
stored: storedSkillXp(skills),
331
levelUps
322
332
});
323
333
}
324
334
events.push({
@@ -17,7 +17,7 @@ import {17
craftOrigin,17
craftOrigin,18
craftOriginVerbForStation18
craftOriginVerbForStation19
} from "../../../shared/items/origin.js";19
} from "../../../shared/items/origin.js";20
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";20
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";21
import { bagView } from "../items/bags.js";21
import { bagView } from "../items/bags.js";22
import { tileToChunk, tileToLocal } from "../world/coordinates.js";22
import { tileToChunk, tileToLocal } from "../world/coordinates.js";23
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";23
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";@@ -305,10 +305,18 @@ export function stepCrafting (world, now)305
inventory.slots = added.slots;305
inventory.slots = added.slots;306
306
307
let skillsChanged = false;307
let skillsChanged = false;308
const levelUps = [];308
if (skills?.xp && recipe.xpMaterial && stationDef?.skillId)309
if (skills?.xp && recipe.xpMaterial && stationDef?.skillId)309
{310
{310
if (addSkillXp(skills, stationDef.skillId, smeltingXpForMaterial(recipe.xpMaterial)))311
const result = applySkillXp(312
skills,313
stationDef.skillId,314
smeltingXpForMaterial(recipe.xpMaterial)315
);316
if (result.changed)311
{ skillsChanged = true; }317
{ skillsChanged = true; }318
if (result.levelUp)319
{ levelUps.push(result.levelUp); }312
}320
}313
321
314
privates.push({ characterId, bag: bagView(world.ecs, handle) });322
privates.push({ characterId, bag: bagView(world.ecs, handle) });@@ -316,9 +324,11 @@ export function stepCrafting (world, now)316
{324
{317
events.push({325
events.push({318
type: "skills-updated",326
type: "skills-updated",327
entityId,319
characterId,328
characterId,320
skills: publicSkillsView(skills),329
skills: publicSkillsView(skills),321
stored: storedSkillXp(skills)330
stored: storedSkillXp(skills),331
levelUps322
});332
});323
}333
}324
events.push({334
events.push({@@ -1019,7 +1019,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1019
1019
}
1020
1020
continue;
1021
1021
}
1022
if (event.type === "entity-move" || event.type === "ground-item-appear" || event.type === "ground-item-despawn" || event.type === "entity-appearance" || event.type === "entity-despawn" || event.type === "entity-spawn" || event.type === "combat-swing" || event.type === "combat-hit" || event.type === "combat-miss" || event.type === "combat-block" || event.type === "gather-swing" || event.type === "tile-shove" || event.type === "chunk-delta")
1022
if (event.type === "entity-move" || event.type === "ground-item-appear" || event.type === "ground-item-despawn" || event.type === "entity-appearance" || event.type === "entity-despawn" || event.type === "entity-spawn" || event.type === "combat-swing" || event.type === "combat-hit" || event.type === "combat-miss" || event.type === "combat-block" || event.type === "gather-swing" || event.type === "tile-shove" || event.type === "chunk-delta" || event.type === "skill-level-up")
1023
1023
{ publishEntity(event); }
1024
1024
}
1025
1025
if (simulation.tickIndex % simulation.settings.simulationTickHz === 0)
@@ -1139,6 +1139,21 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1139
1139
}
1140
1140
continue;
1141
1141
}
1142
if (event.type === "skill-level-up")
1143
{
1144
if (session.entityId !== event.entityId && !seesTo)
1145
{ continue; }
1146
send(session, {
1147
type: MessageType.skillLevelUp,
1148
entityId: event.entityId,
1149
characterId: event.characterId,
1150
skillId: event.skillId,
1151
level: event.level,
1152
displayName: event.displayName,
1153
icon: event.icon
1154
});
1155
continue;
1156
}
1142
1157
if (event.type === "chunk-delta")
1143
1158
{
1144
1159
if (!seesTo)
@@ -1019,7 +1019,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1019
}1019
}1020
continue;1020
continue;1021
}1021
}1022
if (event.type === "entity-move" || event.type === "ground-item-appear" || event.type === "ground-item-despawn" || event.type === "entity-appearance" || event.type === "entity-despawn" || event.type === "entity-spawn" || event.type === "combat-swing" || event.type === "combat-hit" || event.type === "combat-miss" || event.type === "combat-block" || event.type === "gather-swing" || event.type === "tile-shove" || event.type === "chunk-delta")1022
if (event.type === "entity-move" || event.type === "ground-item-appear" || event.type === "ground-item-despawn" || event.type === "entity-appearance" || event.type === "entity-despawn" || event.type === "entity-spawn" || event.type === "combat-swing" || event.type === "combat-hit" || event.type === "combat-miss" || event.type === "combat-block" || event.type === "gather-swing" || event.type === "tile-shove" || event.type === "chunk-delta" || event.type === "skill-level-up")1023
{ publishEntity(event); }1023
{ publishEntity(event); }1024
}1024
}1025
if (simulation.tickIndex % simulation.settings.simulationTickHz === 0)1025
if (simulation.tickIndex % simulation.settings.simulationTickHz === 0)@@ -1139,6 +1139,21 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1139
}1139
}1140
continue;1140
continue;1141
}1141
}1142
if (event.type === "skill-level-up")1143
{1144
if (session.entityId !== event.entityId && !seesTo)1145
{ continue; }1146
send(session, {1147
type: MessageType.skillLevelUp,1148
entityId: event.entityId,1149
characterId: event.characterId,1150
skillId: event.skillId,1151
level: event.level,1152
displayName: event.displayName,1153
icon: event.icon1154
});1155
continue;1156
}1142
if (event.type === "chunk-delta")1157
if (event.type === "chunk-delta")1143
{1158
{1144
if (!seesTo)1159
if (!seesTo)@@ -19,7 +19,7 @@ import {
19
19
} from "../../../shared/definitions/gathering.js";
20
20
import { insertStack } from "../../../shared/items/inventory.js";
21
21
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";
22
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
22
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
23
23
import { seasonIdAt, treeStumpStateForSeason, SeasonId } from "../../../shared/world/season.js";
24
24
import { bagView } from "../items/bags.js";
25
25
import { chebyshev, clearEngage } from "../combat/service.js";
@@ -328,7 +328,7 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)
328
328
}, now);
329
329
}
330
330
331
function pushBagUpdate (events, privates, world, handle, character, skillsChanged, skills)
331
function pushBagUpdate (events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps = [])
332
332
{
333
333
privates.push({
334
334
characterId: character.characterId,
@@ -338,9 +338,11 @@ function pushBagUpdate (events, privates, world, handle, character, skillsChange
338
338
{
339
339
events.push({
340
340
type: "skills-updated",
341
entityId,
341
342
characterId: character.characterId,
342
343
skills: publicSkillsView(skills),
343
stored: storedSkillXp(skills)
344
stored: storedSkillXp(skills),
345
levelUps
344
346
});
345
347
}
346
348
}
@@ -376,8 +378,15 @@ function completeMining (world, handle, entityId, character, gather, events, pri
376
378
377
379
const skills = world.ecs.get(handle, Component.skills);
378
380
let skillsChanged = false;
379
if (skills?.xp && addSkillXp(skills, SkillId.mining, miningXpForMaterial(gather.materialId)))
380
{ skillsChanged = true; }
381
const levelUps = [];
382
if (skills?.xp)
383
{
384
const result = applySkillXp(skills, SkillId.mining, miningXpForMaterial(gather.materialId));
385
if (result.changed)
386
{ skillsChanged = true; }
387
if (result.levelUp)
388
{ levelUps.push(result.levelUp); }
389
}
381
390
382
391
const exhausted = setBoulderState(
383
392
world,
@@ -397,7 +406,7 @@ function completeMining (world, handle, entityId, character, gather, events, pri
397
406
}
398
407
399
408
clearGather(world.ecs, handle);
400
pushBagUpdate(events, privates, world, handle, character, skillsChanged, skills);
409
pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);
401
410
events.push({
402
411
type: "gather-complete",
403
412
characterId: character.characterId,
@@ -438,8 +447,15 @@ function completeWoodcutting (world, handle, entityId, character, gather, events
438
447
439
448
const skills = world.ecs.get(handle, Component.skills);
440
449
let skillsChanged = false;
441
if (skills?.xp && addSkillXp(skills, SkillId.woodcutting, woodcuttingXpForWood(gather.woodTier)))
442
{ skillsChanged = true; }
450
const levelUps = [];
451
if (skills?.xp)
452
{
453
const result = applySkillXp(skills, SkillId.woodcutting, woodcuttingXpForWood(gather.woodTier));
454
if (result.changed)
455
{ skillsChanged = true; }
456
if (result.levelUp)
457
{ levelUps.push(result.levelUp); }
458
}
443
459
444
460
const stumpState = treeStumpStateForSeason(seasonIdAt(now));
445
461
const exhausted = setTreeState(
@@ -462,7 +478,7 @@ function completeWoodcutting (world, handle, entityId, character, gather, events
462
478
}
463
479
464
480
clearGather(world.ecs, handle);
465
pushBagUpdate(events, privates, world, handle, character, skillsChanged, skills);
481
pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);
466
482
events.push({
467
483
type: "gather-complete",
468
484
characterId: character.characterId,
@@ -19,7 +19,7 @@ import {19
} from "../../../shared/definitions/gathering.js";19
} from "../../../shared/definitions/gathering.js";20
import { insertStack } from "../../../shared/items/inventory.js";20
import { insertStack } from "../../../shared/items/inventory.js";21
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";21
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";22
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";22
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";23
import { seasonIdAt, treeStumpStateForSeason, SeasonId } from "../../../shared/world/season.js";23
import { seasonIdAt, treeStumpStateForSeason, SeasonId } from "../../../shared/world/season.js";24
import { bagView } from "../items/bags.js";24
import { bagView } from "../items/bags.js";25
import { chebyshev, clearEngage } from "../combat/service.js";25
import { chebyshev, clearEngage } from "../combat/service.js";@@ -328,7 +328,7 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)328
}, now);328
}, now);329
}329
}330
330
331
function pushBagUpdate (events, privates, world, handle, character, skillsChanged, skills)331
function pushBagUpdate (events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps = [])332
{332
{333
privates.push({333
privates.push({334
characterId: character.characterId,334
characterId: character.characterId,@@ -338,9 +338,11 @@ function pushBagUpdate (events, privates, world, handle, character, skillsChange338
{338
{339
events.push({339
events.push({340
type: "skills-updated",340
type: "skills-updated",341
entityId,341
characterId: character.characterId,342
characterId: character.characterId,342
skills: publicSkillsView(skills),343
skills: publicSkillsView(skills),343
stored: storedSkillXp(skills)344
stored: storedSkillXp(skills),345
levelUps344
});346
});345
}347
}346
}348
}@@ -376,8 +378,15 @@ function completeMining (world, handle, entityId, character, gather, events, pri376
378
377
const skills = world.ecs.get(handle, Component.skills);379
const skills = world.ecs.get(handle, Component.skills);378
let skillsChanged = false;380
let skillsChanged = false;379
if (skills?.xp && addSkillXp(skills, SkillId.mining, miningXpForMaterial(gather.materialId)))381
const levelUps = [];380
{ skillsChanged = true; }382
if (skills?.xp)383
{384
const result = applySkillXp(skills, SkillId.mining, miningXpForMaterial(gather.materialId));385
if (result.changed)386
{ skillsChanged = true; }387
if (result.levelUp)388
{ levelUps.push(result.levelUp); }389
}381
390
382
const exhausted = setBoulderState(391
const exhausted = setBoulderState(383
world,392
world,@@ -397,7 +406,7 @@ function completeMining (world, handle, entityId, character, gather, events, pri397
}406
}398
407
399
clearGather(world.ecs, handle);408
clearGather(world.ecs, handle);400
pushBagUpdate(events, privates, world, handle, character, skillsChanged, skills);409
pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);401
events.push({410
events.push({402
type: "gather-complete",411
type: "gather-complete",403
characterId: character.characterId,412
characterId: character.characterId,@@ -438,8 +447,15 @@ function completeWoodcutting (world, handle, entityId, character, gather, events438
447
439
const skills = world.ecs.get(handle, Component.skills);448
const skills = world.ecs.get(handle, Component.skills);440
let skillsChanged = false;449
let skillsChanged = false;441
if (skills?.xp && addSkillXp(skills, SkillId.woodcutting, woodcuttingXpForWood(gather.woodTier)))450
const levelUps = [];442
{ skillsChanged = true; }451
if (skills?.xp)452
{453
const result = applySkillXp(skills, SkillId.woodcutting, woodcuttingXpForWood(gather.woodTier));454
if (result.changed)455
{ skillsChanged = true; }456
if (result.levelUp)457
{ levelUps.push(result.levelUp); }458
}443
459
444
const stumpState = treeStumpStateForSeason(seasonIdAt(now));460
const stumpState = treeStumpStateForSeason(seasonIdAt(now));445
const exhausted = setTreeState(461
const exhausted = setTreeState(@@ -462,7 +478,7 @@ function completeWoodcutting (world, handle, entityId, character, gather, events462
}478
}463
479
464
clearGather(world.ecs, handle);480
clearGather(world.ecs, handle);465
pushBagUpdate(events, privates, world, handle, character, skillsChanged, skills);481
pushBagUpdate(events, privates, world, handle, entityId, character, skillsChanged, skills, levelUps);466
events.push({482
events.push({467
type: "gather-complete",483
type: "gather-complete",468
characterId: character.characterId,484
characterId: character.characterId,@@ -205,7 +205,11 @@ export class Simulation
205
205
if (event.type === "entity-despawn")
206
206
{ this.#forget(event.entityId); }
207
207
if (event.type === "skills-updated")
208
{ this.#applySkillsUpdated(event); }
208
{
209
this.#applySkillsUpdated(event);
210
events.push(...this.#skillLevelUpEvents(event));
211
continue;
212
}
209
213
if (event.type === "inventory" && event.characterId)
210
214
{
211
215
this.#saveBagFromView(event.characterId, {
@@ -251,7 +255,11 @@ export class Simulation
251
255
if (event.type === "entity-move")
252
256
{ this.#applyMoveToDirectory(event); }
253
257
if (event.type === "skills-updated")
254
{ this.#applySkillsUpdated(event); }
258
{
259
this.#applySkillsUpdated(event);
260
events.push(...this.#skillLevelUpEvents(event));
261
continue;
262
}
255
263
this.#persistGroundEvent(event);
256
264
if (event.type !== "skills-updated")
257
265
{ events.push(event); }
@@ -907,7 +915,11 @@ export class Simulation
907
915
if (event.type === "entity-despawn")
908
916
{ this.#forget(event.entityId); }
909
917
if (event.type === "skills-updated")
910
{ this.#applySkillsUpdated(event); }
918
{
919
this.#applySkillsUpdated(event);
920
events.push(...this.#skillLevelUpEvents(event));
921
continue;
922
}
911
923
if (event.type === "player-died")
912
924
{
913
925
events.push(...this.#applyPlayerDeath(event));
@@ -932,9 +944,12 @@ export class Simulation
932
944
for (const xpEvent of xpResult?.events ?? [])
933
945
{
934
946
if (xpEvent.type === "skills-updated")
935
{ this.#applySkillsUpdated(xpEvent); }
936
if (xpEvent.type !== "skills-updated")
937
{ events.push(xpEvent); }
947
{
948
this.#applySkillsUpdated(xpEvent);
949
events.push(...this.#skillLevelUpEvents(xpEvent));
950
continue;
951
}
952
events.push(xpEvent);
938
953
}
939
954
}
940
955
return events;
@@ -1629,6 +1644,30 @@ export class Simulation
1629
1644
this.pushSkills(event.characterId, event.skills ?? []);
1630
1645
}
1631
1646
1647
#skillLevelUpEvents (event)
1648
{
1649
const levelUps = event?.levelUps ?? [];
1650
if (!levelUps.length)
1651
{ return []; }
1652
const entityId = event.entityId ?? this.characterEntities.get(event.characterId);
1653
if (entityId == null)
1654
{ return []; }
1655
const record = this.directory.get(entityId);
1656
const tileX = record?.tileX ?? 0;
1657
const tileY = record?.tileY ?? 0;
1658
return levelUps.map((levelUp) => ({
1659
type: "skill-level-up",
1660
entityId,
1661
characterId: event.characterId,
1662
tileX,
1663
tileY,
1664
skillId: levelUp.skillId,
1665
level: levelUp.level,
1666
displayName: levelUp.displayName,
1667
icon: levelUp.icon
1668
}));
1669
}
1670
1632
1671
#saveBagFromView (characterId, bag)
1633
1672
{
1634
1673
this.stateDb.saveBag(characterId, {
@@ -205,7 +205,11 @@ export class Simulation205
if (event.type === "entity-despawn")205
if (event.type === "entity-despawn")206
{ this.#forget(event.entityId); }206
{ this.#forget(event.entityId); }207
if (event.type === "skills-updated")207
if (event.type === "skills-updated")208
{ this.#applySkillsUpdated(event); }208
{209
this.#applySkillsUpdated(event);210
events.push(...this.#skillLevelUpEvents(event));211
continue;212
}209
if (event.type === "inventory" && event.characterId)213
if (event.type === "inventory" && event.characterId)210
{214
{211
this.#saveBagFromView(event.characterId, {215
this.#saveBagFromView(event.characterId, {@@ -251,7 +255,11 @@ export class Simulation251
if (event.type === "entity-move")255
if (event.type === "entity-move")252
{ this.#applyMoveToDirectory(event); }256
{ this.#applyMoveToDirectory(event); }253
if (event.type === "skills-updated")257
if (event.type === "skills-updated")254
{ this.#applySkillsUpdated(event); }258
{259
this.#applySkillsUpdated(event);260
events.push(...this.#skillLevelUpEvents(event));261
continue;262
}255
this.#persistGroundEvent(event);263
this.#persistGroundEvent(event);256
if (event.type !== "skills-updated")264
if (event.type !== "skills-updated")257
{ events.push(event); }265
{ events.push(event); }@@ -907,7 +915,11 @@ export class Simulation907
if (event.type === "entity-despawn")915
if (event.type === "entity-despawn")908
{ this.#forget(event.entityId); }916
{ this.#forget(event.entityId); }909
if (event.type === "skills-updated")917
if (event.type === "skills-updated")910
{ this.#applySkillsUpdated(event); }918
{919
this.#applySkillsUpdated(event);920
events.push(...this.#skillLevelUpEvents(event));921
continue;922
}911
if (event.type === "player-died")923
if (event.type === "player-died")912
{924
{913
events.push(...this.#applyPlayerDeath(event));925
events.push(...this.#applyPlayerDeath(event));@@ -932,9 +944,12 @@ export class Simulation932
for (const xpEvent of xpResult?.events ?? [])944
for (const xpEvent of xpResult?.events ?? [])933
{945
{934
if (xpEvent.type === "skills-updated")946
if (xpEvent.type === "skills-updated")935
{ this.#applySkillsUpdated(xpEvent); }947
{936
if (xpEvent.type !== "skills-updated")948
this.#applySkillsUpdated(xpEvent);937
{ events.push(xpEvent); }949
events.push(...this.#skillLevelUpEvents(xpEvent));950
continue;951
}952
events.push(xpEvent);938
}953
}939
}954
}940
return events;955
return events;@@ -1629,6 +1644,30 @@ export class Simulation1629
this.pushSkills(event.characterId, event.skills ?? []);1644
this.pushSkills(event.characterId, event.skills ?? []);1630
}1645
}1631
1646
1647
#skillLevelUpEvents (event)1648
{1649
const levelUps = event?.levelUps ?? [];1650
if (!levelUps.length)1651
{ return []; }1652
const entityId = event.entityId ?? this.characterEntities.get(event.characterId);1653
if (entityId == null)1654
{ return []; }1655
const record = this.directory.get(entityId);1656
const tileX = record?.tileX ?? 0;1657
const tileY = record?.tileY ?? 0;1658
return levelUps.map((levelUp) => ({1659
type: "skill-level-up",1660
entityId,1661
characterId: event.characterId,1662
tileX,1663
tileY,1664
skillId: levelUp.skillId,1665
level: levelUp.level,1666
displayName: levelUp.displayName,1667
icon: levelUp.icon1668
}));1669
}1670
1632
#saveBagFromView (characterId, bag)1671
#saveBagFromView (characterId, bag)1633
{1672
{1634
this.stateDb.saveBag(characterId, {1673
this.stateDb.saveBag(characterId, {@@ -52,7 +52,7 @@ import {
52
52
} from "../combat/service.js";
53
53
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";
54
54
import { SkillId } from "../../../shared/definitions/skills.js";
55
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
55
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
56
56
import {
57
57
STAMINA_REGEN_PER_SECOND,
58
58
STAMINA_XP_PER_POINT_SPENT,
@@ -717,7 +717,8 @@ export class WorkerWorld
717
717
entityId,
718
718
characterId: character.characterId,
719
719
skills: xpAward.view,
720
stored: xpAward.stored
720
stored: xpAward.stored,
721
levelUps: xpAward.levelUps ?? []
721
722
}]
722
723
};
723
724
}
@@ -851,14 +852,18 @@ export class WorkerWorld
851
852
stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);
852
853
stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;
853
854
let skillsChanged = false;
855
const levelUps = [];
854
856
while (stamina.xpDebt >= 1 && skills?.xp)
855
857
{
856
858
stamina.xpDebt -= 1;
857
if (addSkillXp(skills, SkillId.stamina, STAMINA_XP_PER_POINT_SPENT))
859
const result = applySkillXp(skills, SkillId.stamina, STAMINA_XP_PER_POINT_SPENT);
860
if (result.changed)
858
861
{
859
862
skillsChanged = true;
860
863
syncPlayerStamina(this.ecs, handle);
861
864
}
865
if (result.levelUp)
866
{ levelUps.push(result.levelUp); }
862
867
}
863
868
const movement = this.ecs.get(handle, Component.movement);
864
869
if (stamina.current <= 0 && movement)
@@ -871,9 +876,11 @@ export class WorkerWorld
871
876
{
872
877
events.push({
873
878
type: "skills-updated",
879
entityId: this.ecs.entityIdOf(handle),
874
880
characterId: character.characterId,
875
881
skills: publicSkillsView(skills),
876
stored: storedSkillXp(skills)
882
stored: storedSkillXp(skills),
883
levelUps
877
884
});
878
885
}
879
886
}
@@ -52,7 +52,7 @@ import {52
} from "../combat/service.js";52
} from "../combat/service.js";53
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";53
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";54
import { SkillId } from "../../../shared/definitions/skills.js";54
import { SkillId } from "../../../shared/definitions/skills.js";55
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";55
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";56
import {56
import {57
STAMINA_REGEN_PER_SECOND,57
STAMINA_REGEN_PER_SECOND,58
STAMINA_XP_PER_POINT_SPENT,58
STAMINA_XP_PER_POINT_SPENT,@@ -717,7 +717,8 @@ export class WorkerWorld717
entityId,717
entityId,718
characterId: character.characterId,718
characterId: character.characterId,719
skills: xpAward.view,719
skills: xpAward.view,720
stored: xpAward.stored720
stored: xpAward.stored,721
levelUps: xpAward.levelUps ?? []721
}]722
}]722
};723
};723
}724
}@@ -851,14 +852,18 @@ export class WorkerWorld851
stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);852
stamina.current = Math.max(0, (Number(stamina.current) || 0) - cost);852
stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;853
stamina.xpDebt = (Number(stamina.xpDebt) || 0) + cost;853
let skillsChanged = false;854
let skillsChanged = false;855
const levelUps = [];854
while (stamina.xpDebt >= 1 && skills?.xp)856
while (stamina.xpDebt >= 1 && skills?.xp)855
{857
{856
stamina.xpDebt -= 1;858
stamina.xpDebt -= 1;857
if (addSkillXp(skills, SkillId.stamina, STAMINA_XP_PER_POINT_SPENT))859
const result = applySkillXp(skills, SkillId.stamina, STAMINA_XP_PER_POINT_SPENT);860
if (result.changed)858
{861
{859
skillsChanged = true;862
skillsChanged = true;860
syncPlayerStamina(this.ecs, handle);863
syncPlayerStamina(this.ecs, handle);861
}864
}865
if (result.levelUp)866
{ levelUps.push(result.levelUp); }862
}867
}863
const movement = this.ecs.get(handle, Component.movement);868
const movement = this.ecs.get(handle, Component.movement);864
if (stamina.current <= 0 && movement)869
if (stamina.current <= 0 && movement)@@ -871,9 +876,11 @@ export class WorkerWorld871
{876
{872
events.push({877
events.push({873
type: "skills-updated",878
type: "skills-updated",879
entityId: this.ecs.entityIdOf(handle),874
characterId: character.characterId,880
characterId: character.characterId,875
skills: publicSkillsView(skills),881
skills: publicSkillsView(skills),876
stored: storedSkillXp(skills)882
stored: storedSkillXp(skills),883
levelUps877
});884
});878
}885
}879
}886
}@@ -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 { combatHitXpPerSkill } from "../../../shared/skills/progression.js";
4
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
4
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
5
5
6
6
export function syncPlayerHealth (ecs, handle)
7
7
{
@@ -37,13 +37,19 @@ export function awardCombatHitXp (ecs, attackerHandle, profile)
37
37
if (!skills?.xp)
38
38
{ return null; }
39
39
const perSkill = combatHitXpPerSkill();
40
const hit = addSkillXp(skills, profile.hitSkillId, perSkill);
41
const damage = addSkillXp(skills, profile.damageSkillId, perSkill);
42
if (!hit && !damage)
40
const levelUps = [];
41
const hit = applySkillXp(skills, profile.hitSkillId, perSkill);
42
if (hit.levelUp)
43
{ levelUps.push(hit.levelUp); }
44
const damage = applySkillXp(skills, profile.damageSkillId, perSkill);
45
if (damage.levelUp)
46
{ levelUps.push(damage.levelUp); }
47
if (!hit.changed && !damage.changed)
43
48
{ return null; }
44
49
return {
45
50
view: publicSkillsView(skills),
46
stored: storedSkillXp(skills)
51
stored: storedSkillXp(skills),
52
levelUps
47
53
};
48
54
}
49
55
@@ -58,12 +64,14 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)
58
64
const skills = ecs.get(targetHandle, Component.skills);
59
65
if (!skills?.xp)
60
66
{ return null; }
61
if (!addSkillXp(skills, SkillId.health, amount))
67
const result = applySkillXp(skills, SkillId.health, amount);
68
if (!result.changed)
62
69
{ return null; }
63
70
syncPlayerHealth(ecs, targetHandle);
64
71
return {
65
72
characterId: character.characterId,
66
73
view: publicSkillsView(skills),
67
stored: storedSkillXp(skills)
74
stored: storedSkillXp(skills),
75
levelUps: result.levelUp ? [result.levelUp] : []
68
76
};
69
77
}
@@ -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 { combatHitXpPerSkill } from "../../../shared/skills/progression.js";3
import { combatHitXpPerSkill } from "../../../shared/skills/progression.js";4
import { addSkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";4
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";5
5
6
export function syncPlayerHealth (ecs, handle)6
export function syncPlayerHealth (ecs, handle)7
{7
{@@ -37,13 +37,19 @@ export function awardCombatHitXp (ecs, attackerHandle, profile)37
if (!skills?.xp)37
if (!skills?.xp)38
{ return null; }38
{ return null; }39
const perSkill = combatHitXpPerSkill();39
const perSkill = combatHitXpPerSkill();40
const hit = addSkillXp(skills, profile.hitSkillId, perSkill);40
const levelUps = [];41
const damage = addSkillXp(skills, profile.damageSkillId, perSkill);41
const hit = applySkillXp(skills, profile.hitSkillId, perSkill);42
if (!hit && !damage)42
if (hit.levelUp)43
{ levelUps.push(hit.levelUp); }44
const damage = applySkillXp(skills, profile.damageSkillId, perSkill);45
if (damage.levelUp)46
{ levelUps.push(damage.levelUp); }47
if (!hit.changed && !damage.changed)43
{ return null; }48
{ return null; }44
return {49
return {45
view: publicSkillsView(skills),50
view: publicSkillsView(skills),46
stored: storedSkillXp(skills)51
stored: storedSkillXp(skills),52
levelUps47
};53
};48
}54
}49
55
@@ -58,12 +64,14 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)58
const skills = ecs.get(targetHandle, Component.skills);64
const skills = ecs.get(targetHandle, Component.skills);59
if (!skills?.xp)65
if (!skills?.xp)60
{ return null; }66
{ return null; }61
if (!addSkillXp(skills, SkillId.health, amount))67
const result = applySkillXp(skills, SkillId.health, amount);68
if (!result.changed)62
{ return null; }69
{ return null; }63
syncPlayerHealth(ecs, targetHandle);70
syncPlayerHealth(ecs, targetHandle);64
return {71
return {65
characterId: character.characterId,72
characterId: character.characterId,66
view: publicSkillsView(skills),73
view: publicSkillsView(skills),67
stored: storedSkillXp(skills)74
stored: storedSkillXp(skills),75
levelUps: result.levelUp ? [result.levelUp] : []68
};76
};69
}77
}@@ -3,7 +3,8 @@ import assert from "node:assert/strict";
3
3
import { createEmptyChunkData } from "../src/world/chunkData.js";
4
4
import { bakeLightMaps } from "../src/lighting/baker.js";
5
5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";
6
import { BlockType, LightOcclusion, blockLightOcclusionForBlock } from "../../shared/definitions/tiles.js";
6
import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";
7
import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
7
8
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
8
9
9
10
test("Bresenham visits start and end tiles", () =>
@@ -3,7 +3,8 @@ import assert from "node:assert/strict";3
import { createEmptyChunkData } from "../src/world/chunkData.js";3
import { createEmptyChunkData } from "../src/world/chunkData.js";4
import { bakeLightMaps } from "../src/lighting/baker.js";4
import { bakeLightMaps } from "../src/lighting/baker.js";5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";6
import { BlockType, LightOcclusion, blockLightOcclusionForBlock } from "../../shared/definitions/tiles.js";6
import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";7
import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";7
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";8
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";8
9
9
test("Bresenham visits start and end tiles", () =>10
test("Bresenham visits start and end tiles", () =>@@ -13,6 +13,7 @@ import {
13
13
normalizePlayerSkills,
14
14
defaultPlayerSkills,
15
15
addSkillXp,
16
applySkillXp,
16
17
publicSkillsView,
17
18
enforceMinimumSkillLevels
18
19
} from "../../shared/skills/state.js";
@@ -157,6 +158,16 @@ test("addSkillXp mutates the player skills component", () =>
157
158
assert.equal(skills.xp[SkillId.strength], 10);
158
159
});
159
160
161
test("applySkillXp reports a level-up when XP crosses a threshold", () =>
162
{
163
const skills = normalizePlayerSkills(null);
164
const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);
165
assert.equal(result.changed, true);
166
assert.equal(result.levelUp?.skillId, SkillId.strength);
167
assert.equal(result.levelUp?.level, 2);
168
assert.match(result.levelUp?.icon, /strength\.svg$/);
169
});
170
160
171
test("combat hit xp is split equally", () =>
161
172
{
162
173
assert.equal(combatHitXpPerSkill(), 5);
@@ -13,6 +13,7 @@ import {13
normalizePlayerSkills,13
normalizePlayerSkills,14
defaultPlayerSkills,14
defaultPlayerSkills,15
addSkillXp,15
addSkillXp,16
applySkillXp,16
publicSkillsView,17
publicSkillsView,17
enforceMinimumSkillLevels18
enforceMinimumSkillLevels18
} from "../../shared/skills/state.js";19
} from "../../shared/skills/state.js";@@ -157,6 +158,16 @@ test("addSkillXp mutates the player skills component", () =>157
assert.equal(skills.xp[SkillId.strength], 10);158
assert.equal(skills.xp[SkillId.strength], 10);158
});159
});159
160
161
test("applySkillXp reports a level-up when XP crosses a threshold", () =>162
{163
const skills = normalizePlayerSkills(null);164
const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);165
assert.equal(result.changed, true);166
assert.equal(result.levelUp?.skillId, SkillId.strength);167
assert.equal(result.levelUp?.level, 2);168
assert.match(result.levelUp?.icon, /strength\.svg$/);169
});170
160
test("combat hit xp is split equally", () =>171
test("combat hit xp is split equally", () =>161
{172
{162
assert.equal(combatHitXpPerSkill(), 5);173
assert.equal(combatHitXpPerSkill(), 5);