BlueGit

timfa questward

Toast skill unlocks on level-up and add metal skirts/shields.

Show equip/gather/craft unlock lines when a skill crosses a tier gate, zero clothing defence bonuses, and add skirt/shield armour (shield: bars + leather, dual-tint equip).

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
9b426a49e1d4db3ed6cef9abbc864ac624859bdc
Parent
64b8eeb5
19 files changed +492 −66
client/assets/items/armour/shield-equip.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/armour/shield.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/armour/skirt-equip.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/armour/skirt.png added Binary file +0 −0

The contents of this binary file are not shown.

client/src/play/main.js +9 −2
@@ -21,6 +21,7 @@ import { initStatusEffects } from "./statusEffects.js";
21 21 import { initContextMenu } from "./contextMenu.js";
22 22 import { initDeath } from "./death.js";
23 23 import { initToasts } from "./toasts.js";
24 import { skillLevelUpToastText, skillUnlockMessages } from "/shared/skills/levelUpUnlocks.js";
24 25 import { initQuests } from "./quests.js";
25 26 import { initDialogue } from "./dialogue.js";
26 27 import { initShop } from "./shop.js";
@@ -1805,8 +1806,14 @@ async function main ()
1805 1806 view?.spawnSkillLevelUp(message.entityId, message);
1806 1807 if (message.entityId === view?.localEntityId)
1807 1808 {
1808 const name = message.displayName ?? message.skillId ?? "Skill";
1809 toasts?.show(`${name} level ${message.level}!`);
1809 const level = message.level | 0;
1810 const previousLevel = message.previousLevel == null
1811 ? Math.max(0, level - 1)
1812 : message.previousLevel | 0;
1813 const unlockCount = skillUnlockMessages(message.skillId, previousLevel, level).length;
1814 toasts?.show(skillLevelUpToastText(message.skillId, level, previousLevel), {
1815 durationMs: 3500 + unlockCount * 1600
1816 });
1810 1817 }
1811 1818 break;
1812 1819 case MessageType.playerDied:
@@ -21,6 +21,7 @@ import { initStatusEffects } from "./statusEffects.js";
21import { initContextMenu } from "./contextMenu.js";
21import { initContextMenu } from "./contextMenu.js";
22import { initDeath } from "./death.js";
22import { initDeath } from "./death.js";
23import { initToasts } from "./toasts.js";
23import { initToasts } from "./toasts.js";
24import { skillLevelUpToastText, skillUnlockMessages } from "/shared/skills/levelUpUnlocks.js";
24import { initQuests } from "./quests.js";
25import { initQuests } from "./quests.js";
25import { initDialogue } from "./dialogue.js";
26import { initDialogue } from "./dialogue.js";
26import { initShop } from "./shop.js";
27import { initShop } from "./shop.js";
@@ -1805,8 +1806,14 @@ async function main ()
1805 view?.spawnSkillLevelUp(message.entityId, message);
1806 view?.spawnSkillLevelUp(message.entityId, message);
1806 if (message.entityId === view?.localEntityId)
1807 if (message.entityId === view?.localEntityId)
1807 {
1808 {
1808 const name = message.displayName ?? message.skillId ?? "Skill";
1809 const level = message.level | 0;
1809 toasts?.show(`${name} level ${message.level}!`);
1810 const previousLevel = message.previousLevel == null
1811 ? Math.max(0, level - 1)
1812 : message.previousLevel | 0;
1813 const unlockCount = skillUnlockMessages(message.skillId, previousLevel, level).length;
1814 toasts?.show(skillLevelUpToastText(message.skillId, level, previousLevel), {
1815 durationMs: 3500 + unlockCount * 1600
1816 });
1810 }
1817 }
1811 break;
1818 break;
1812 case MessageType.playerDied:
1819 case MessageType.playerDied:
client/src/render/potionIcon.js +9 −8
@@ -1,12 +1,13 @@
1 1 import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";
2 2 import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
3 import {
4 applyMagentaTintToImageData,
5 applyDualChannelTintToImageData,
6 normalizeRgb,
7 resolveItemTint,
8 resolveItemDualTint
9 } from "/shared/render/tint.js";
3 import
4 {
5 applyMagentaTintToImageData,
6 applyDualChannelTintToImageData,
7 normalizeRgb,
8 resolveItemTint,
9 resolveItemDualTint
10 } from "/shared/render/tint.js";
10 11
11 12 const bottleCache = new Map();
12 13 const fillCache = new Map();
@@ -134,7 +135,7 @@ export function applyItemIcon (img, stack, fallbackPath)
134 135 { return; }
135 136 img.src = fallbackPath;
136 137 const def = itemDefinition(stack?.itemId);
137 const dualTint = resolveItemDualTint(stack, def);
138 const dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
138 139 if (dualTint)
139 140 {
140 141 dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
@@ -1,12 +1,13 @@
1import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";
1import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitions/items.js";
2import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
2import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
3import {
3import
4 applyMagentaTintToImageData,
4 {
5 applyDualChannelTintToImageData,
5 applyMagentaTintToImageData,
6 normalizeRgb,
6 applyDualChannelTintToImageData,
7 resolveItemTint,
7 normalizeRgb,
8 resolveItemDualTint
8 resolveItemTint,
9} from "/shared/render/tint.js";
9 resolveItemDualTint
10 } from "/shared/render/tint.js";
10
11
11const bottleCache = new Map();
12const bottleCache = new Map();
12const fillCache = new Map();
13const fillCache = new Map();
@@ -134,7 +135,7 @@ export function applyItemIcon (img, stack, fallbackPath)
134 { return; }
135 { return; }
135 img.src = fallbackPath;
136 img.src = fallbackPath;
136 const def = itemDefinition(stack?.itemId);
137 const def = itemDefinition(stack?.itemId);
137 const dualTint = resolveItemDualTint(stack, def);
138 const dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
138 if (dualTint)
139 if (dualTint)
139 {
140 {
140 dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
141 dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
client/src/render/worldView.js +3 −2
@@ -1133,8 +1133,9 @@ export class WorldView
1133 1133 item.sprite = spriteName;
1134 1134 item.instance = payload.instance ?? null;
1135 1135 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
1136 item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId));
1137 item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId));
1136 const def = itemDefinition(payload.itemId);
1137 item.dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
1138 item.tintColor = item.dualTint ? null : resolveItemTint(stack, def);
1138 1139 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
1139 1140 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
1140 1141 }
@@ -1133,8 +1133,9 @@ export class WorldView
1133 item.sprite = spriteName;
1133 item.sprite = spriteName;
1134 item.instance = payload.instance ?? null;
1134 item.instance = payload.instance ?? null;
1135 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
1135 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
1136 item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId));
1136 const def = itemDefinition(payload.itemId);
1137 item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId));
1137 item.dualTint = def?.iconTintFromTier ? null : resolveItemDualTint(stack, def);
1138 item.tintColor = item.dualTint ? null : resolveItemTint(stack, def);
1138 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
1139 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
1139 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
1140 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
1140 }
1141 }
client/ui/play.css +2 −0
@@ -167,8 +167,10 @@ body {
167 167 border: 1px solid #4a5568;
168 168 padding: 0.5rem 0.9rem;
169 169 font-size: 0.95rem;
170 line-height: 1.35;
170 171 text-align: center;
171 172 color: #f0ebe0;
173 white-space: pre-line;
172 174 opacity: 0;
173 175 transform: translateY(-8px);
174 176 transition: opacity 0.22s ease, transform 0.22s ease;
@@ -167,8 +167,10 @@ body {
167 border: 1px solid #4a5568;
167 border: 1px solid #4a5568;
168 padding: 0.5rem 0.9rem;
168 padding: 0.5rem 0.9rem;
169 font-size: 0.95rem;
169 font-size: 0.95rem;
170 line-height: 1.35;
170 text-align: center;
171 text-align: center;
171 color: #f0ebe0;
172 color: #f0ebe0;
173 white-space: pre-line;
172 opacity: 0;
174 opacity: 0;
173 transform: translateY(-8px);
175 transform: translateY(-8px);
174 transition: opacity 0.22s ease, transform 0.22s ease;
176 transition: opacity 0.22s ease, transform 0.22s ease;
server/src/gateway/websocket.js +1 −0
@@ -2124,6 +2124,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2124 2124 characterId: event.characterId,
2125 2125 skillId: event.skillId,
2126 2126 level: event.level,
2127 previousLevel: event.previousLevel,
2127 2128 displayName: event.displayName,
2128 2129 icon: event.icon
2129 2130 });
@@ -2124,6 +2124,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2124 characterId: event.characterId,
2124 characterId: event.characterId,
2125 skillId: event.skillId,
2125 skillId: event.skillId,
2126 level: event.level,
2126 level: event.level,
2127 previousLevel: event.previousLevel,
2127 displayName: event.displayName,
2128 displayName: event.displayName,
2128 icon: event.icon
2129 icon: event.icon
2129 });
2130 });
server/src/simulation/simulation.js +1 −0
@@ -2665,6 +2665,7 @@ export class Simulation
2665 2665 tileY,
2666 2666 skillId: levelUp.skillId,
2667 2667 level: levelUp.level,
2668 previousLevel: levelUp.previousLevel,
2668 2669 displayName: levelUp.displayName,
2669 2670 icon: levelUp.icon
2670 2671 }));
@@ -2665,6 +2665,7 @@ export class Simulation
2665 tileY,
2665 tileY,
2666 skillId: levelUp.skillId,
2666 skillId: levelUp.skillId,
2667 level: levelUp.level,
2667 level: levelUp.level,
2668 previousLevel: levelUp.previousLevel,
2668 displayName: levelUp.displayName,
2669 displayName: levelUp.displayName,
2669 icon: levelUp.icon
2670 icon: levelUp.icon
2670 }));
2671 }));
server/tests/crafting.test.js +21 −8
@@ -6,13 +6,13 @@ import { ItemId } from "../../shared/definitions/items.js";
6 6 import { ArmourItemId } from "../../shared/definitions/armourItems.js";
7 7 import { SkillId } from "../../shared/definitions/skills.js";
8 8 import
9 {
10 MaterialTier,
11 GatherMaterialId,
12 tierSmeltSkillLevel,
13 smeltingDurationMs,
14 associatedBarTier
15 } from "../../shared/definitions/materialTiers.js";
9 {
10 MaterialTier,
11 GatherMaterialId,
12 tierSmeltSkillLevel,
13 smeltingDurationMs,
14 associatedBarTier
15 } from "../../shared/definitions/materialTiers.js";
16 16 import { craftDurationMs } from "../../shared/definitions/gathering.js";
17 17 import { recipesForStation, recipeDefinition } from "../../shared/crafting/stationRecipes.js";
18 18 import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
@@ -449,6 +449,11 @@ test("anvil armour recipes use bar counts per piece", () =>
449 449 const greaves = recipeDefinition("armour-greaves-iron");
450 450 assert.deepEqual(greaves.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]);
451 451
452 const skirt = recipeDefinition("armour-skirt-iron");
453 assert.ok(skirt);
454 assert.equal(skirt.output.itemId, ArmourItemId.ironSkirt);
455 assert.deepEqual(skirt.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]);
456
452 457 const boots = recipeDefinition("armour-boots-steel");
453 458 assert.deepEqual(boots.inputs, [{ itemId: ItemId.steelBar, quantity: 2 }]);
454 459
@@ -464,7 +469,15 @@ test("anvil armour recipes use bar counts per piece", () =>
464 469 { itemId: ItemId.bones, quantity: 1 }
465 470 ]);
466 471
472 const shield = recipeDefinition("armour-shield-iron");
473 assert.ok(shield);
474 assert.equal(shield.output.itemId, ArmourItemId.ironShield);
475 assert.deepEqual(shield.inputs, [
476 { itemId: ItemId.ironBar, quantity: 4 },
477 { itemId: ItemId.hardLeather, quantity: 1 }
478 ]);
479
467 480 const anvilArmour = recipesForStation(CraftingStationId.anvil)
468 481 .filter((recipe) => recipe.recipeId.startsWith("armour-"));
469 assert.equal(anvilArmour.length, 7 * 6);
482 assert.equal(anvilArmour.length, 7 * 8);
470 483 });
@@ -6,13 +6,13 @@ import { ItemId } from "../../shared/definitions/items.js";
6import { ArmourItemId } from "../../shared/definitions/armourItems.js";
6import { ArmourItemId } from "../../shared/definitions/armourItems.js";
7import { SkillId } from "../../shared/definitions/skills.js";
7import { SkillId } from "../../shared/definitions/skills.js";
8import
8import
9 {
9{
10 MaterialTier,
10 MaterialTier,
11 GatherMaterialId,
11 GatherMaterialId,
12 tierSmeltSkillLevel,
12 tierSmeltSkillLevel,
13 smeltingDurationMs,
13 smeltingDurationMs,
14 associatedBarTier
14 associatedBarTier
15 } from "../../shared/definitions/materialTiers.js";
15} from "../../shared/definitions/materialTiers.js";
16import { craftDurationMs } from "../../shared/definitions/gathering.js";
16import { craftDurationMs } from "../../shared/definitions/gathering.js";
17import { recipesForStation, recipeDefinition } from "../../shared/crafting/stationRecipes.js";
17import { recipesForStation, recipeDefinition } from "../../shared/crafting/stationRecipes.js";
18import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
18import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js";
@@ -449,6 +449,11 @@ test("anvil armour recipes use bar counts per piece", () =>
449 const greaves = recipeDefinition("armour-greaves-iron");
449 const greaves = recipeDefinition("armour-greaves-iron");
450 assert.deepEqual(greaves.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]);
450 assert.deepEqual(greaves.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]);
451
451
452 const skirt = recipeDefinition("armour-skirt-iron");
453 assert.ok(skirt);
454 assert.equal(skirt.output.itemId, ArmourItemId.ironSkirt);
455 assert.deepEqual(skirt.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]);
456
452 const boots = recipeDefinition("armour-boots-steel");
457 const boots = recipeDefinition("armour-boots-steel");
453 assert.deepEqual(boots.inputs, [{ itemId: ItemId.steelBar, quantity: 2 }]);
458 assert.deepEqual(boots.inputs, [{ itemId: ItemId.steelBar, quantity: 2 }]);
454
459
@@ -464,7 +469,15 @@ test("anvil armour recipes use bar counts per piece", () =>
464 { itemId: ItemId.bones, quantity: 1 }
469 { itemId: ItemId.bones, quantity: 1 }
465 ]);
470 ]);
466
471
472 const shield = recipeDefinition("armour-shield-iron");
473 assert.ok(shield);
474 assert.equal(shield.output.itemId, ArmourItemId.ironShield);
475 assert.deepEqual(shield.inputs, [
476 { itemId: ItemId.ironBar, quantity: 4 },
477 { itemId: ItemId.hardLeather, quantity: 1 }
478 ]);
479
467 const anvilArmour = recipesForStation(CraftingStationId.anvil)
480 const anvilArmour = recipesForStation(CraftingStationId.anvil)
468 .filter((recipe) => recipe.recipeId.startsWith("armour-"));
481 .filter((recipe) => recipe.recipeId.startsWith("armour-"));
469 assert.equal(anvilArmour.length, 7 * 6);
482 assert.equal(anvilArmour.length, 7 * 8);
470});
483});
server/tests/equipment.test.js +46 −3
@@ -9,19 +9,22 @@ import { EquipmentKind } from "../../shared/definitions/equipmentKinds.js";
9 9 import { SkillId } from "../../shared/definitions/skills.js";
10 10 import { normalizePlayerSkills } from "../../shared/skills/state.js";
11 11 import { totalXpForLevel } from "../../shared/skills/progression.js";
12 import {
12 import
13 {
13 14 canEquipItem,
14 15 effectiveSkillLevel,
15 16 equipmentBonusesFromSlots
16 17 } from "../../shared/equipment/stats.js";
17 18 import { emptyEquipment } from "../../shared/items/inventory.js";
18 import {
19 import
20 {
19 21 assertAllBonusGearCategorized,
20 22 defaultEquipmentStatBonuses,
21 23 normalizeEquipmentStatBonuses,
22 24 bonusForEquippedItem,
23 25 diffEquipmentStatBonuses
24 26 } from "../../shared/definitions/equipmentStatCategories.js";
27 import { resolveItemDualTint } from "../../shared/render/tint.js";
25 28
26 29 test("tier stat bonuses scale by material", () =>
27 30 {
@@ -46,13 +49,53 @@ test("equipped weapons and armour add effective combat stats", () =>
46 49 };
47 50 const bonuses = equipmentBonusesFromSlots(slots);
48 51 assert.equal(bonuses[SkillId.strength], tierStatBonus(WoodTier.pine));
49 assert.equal(bonuses[SkillId.defence], 1);
52 assert.equal(bonuses[SkillId.defence], 0);
50 53 assert.equal(
51 54 effectiveSkillLevel(skills, SkillId.strength, bonuses),
52 55 1 + tierStatBonus(WoodTier.pine)
53 56 );
54 57 });
55 58
59 test("metal skirt matches greaves defence bonus", () =>
60 {
61 const defaults = defaultEquipmentStatBonuses();
62 assert.equal(
63 defaults.metalArmour.skirt.iron.defence,
64 defaults.metalArmour.greaves.iron.defence
65 );
66 const slots = {
67 ...emptyEquipment().slots,
68 legs: { itemId: ArmourItemId.ironSkirt, quantity: 1 }
69 };
70 const bonuses = equipmentBonusesFromSlots(slots);
71 assert.equal(bonuses[SkillId.defence], tierStatBonus(MaterialTier.iron));
72 assert.equal(itemDefinition(ArmourItemId.ironSkirt)?.equipment?.slot, "legs");
73 assert.equal(itemDefinition(ArmourItemId.ironSkirt)?.equipment?.equipSprite, "item:armour:skirt:equip");
74 });
75
76 test("metal shield uses leather dual-tint on equip and magenta icon", () =>
77 {
78 const def = itemDefinition(ArmourItemId.ironShield);
79 assert.equal(def?.equipment?.slot, "offhand");
80 assert.equal(def?.equipment?.kind, EquipmentKind.shield);
81 assert.equal(def?.equipment?.equipSprite, "item:armour:shield:equip");
82 assert.equal(def?.iconTintFromTier, true);
83 assert.equal(def?.dualTintFromTier, true);
84 assert.equal(def?.leatherTier, "hardLeather");
85 const dual = resolveItemDualTint({ itemId: ArmourItemId.ironShield }, def);
86 assert.ok(dual?.shaft);
87 assert.ok(dual?.tip);
88 assert.equal(
89 defaultEquipmentStatBonuses().metalArmour.shield.iron.defence,
90 tierStatBonus(MaterialTier.iron)
91 );
92 const slots = {
93 ...emptyEquipment().slots,
94 offhand: { itemId: ArmourItemId.ironShield, quantity: 1 }
95 };
96 assert.equal(equipmentBonusesFromSlots(slots)[SkillId.defence], tierStatBonus(MaterialTier.iron));
97 });
98
56 99 test("leather shoes grant independent agility and defence from settings", () =>
57 100 {
58 101 const settings = normalizeEquipmentStatBonuses({
@@ -9,19 +9,22 @@ import { EquipmentKind } from "../../shared/definitions/equipmentKinds.js";
9import { SkillId } from "../../shared/definitions/skills.js";
9import { SkillId } from "../../shared/definitions/skills.js";
10import { normalizePlayerSkills } from "../../shared/skills/state.js";
10import { normalizePlayerSkills } from "../../shared/skills/state.js";
11import { totalXpForLevel } from "../../shared/skills/progression.js";
11import { totalXpForLevel } from "../../shared/skills/progression.js";
12import {
12import
13{
13 canEquipItem,
14 canEquipItem,
14 effectiveSkillLevel,
15 effectiveSkillLevel,
15 equipmentBonusesFromSlots
16 equipmentBonusesFromSlots
16} from "../../shared/equipment/stats.js";
17} from "../../shared/equipment/stats.js";
17import { emptyEquipment } from "../../shared/items/inventory.js";
18import { emptyEquipment } from "../../shared/items/inventory.js";
18import {
19import
20{
19 assertAllBonusGearCategorized,
21 assertAllBonusGearCategorized,
20 defaultEquipmentStatBonuses,
22 defaultEquipmentStatBonuses,
21 normalizeEquipmentStatBonuses,
23 normalizeEquipmentStatBonuses,
22 bonusForEquippedItem,
24 bonusForEquippedItem,
23 diffEquipmentStatBonuses
25 diffEquipmentStatBonuses
24} from "../../shared/definitions/equipmentStatCategories.js";
26} from "../../shared/definitions/equipmentStatCategories.js";
27import { resolveItemDualTint } from "../../shared/render/tint.js";
25
28
26test("tier stat bonuses scale by material", () =>
29test("tier stat bonuses scale by material", () =>
27{
30{
@@ -46,13 +49,53 @@ test("equipped weapons and armour add effective combat stats", () =>
46 };
49 };
47 const bonuses = equipmentBonusesFromSlots(slots);
50 const bonuses = equipmentBonusesFromSlots(slots);
48 assert.equal(bonuses[SkillId.strength], tierStatBonus(WoodTier.pine));
51 assert.equal(bonuses[SkillId.strength], tierStatBonus(WoodTier.pine));
49 assert.equal(bonuses[SkillId.defence], 1);
52 assert.equal(bonuses[SkillId.defence], 0);
50 assert.equal(
53 assert.equal(
51 effectiveSkillLevel(skills, SkillId.strength, bonuses),
54 effectiveSkillLevel(skills, SkillId.strength, bonuses),
52 1 + tierStatBonus(WoodTier.pine)
55 1 + tierStatBonus(WoodTier.pine)
53 );
56 );
54});
57});
55
58
59test("metal skirt matches greaves defence bonus", () =>
60{
61 const defaults = defaultEquipmentStatBonuses();
62 assert.equal(
63 defaults.metalArmour.skirt.iron.defence,
64 defaults.metalArmour.greaves.iron.defence
65 );
66 const slots = {
67 ...emptyEquipment().slots,
68 legs: { itemId: ArmourItemId.ironSkirt, quantity: 1 }
69 };
70 const bonuses = equipmentBonusesFromSlots(slots);
71 assert.equal(bonuses[SkillId.defence], tierStatBonus(MaterialTier.iron));
72 assert.equal(itemDefinition(ArmourItemId.ironSkirt)?.equipment?.slot, "legs");
73 assert.equal(itemDefinition(ArmourItemId.ironSkirt)?.equipment?.equipSprite, "item:armour:skirt:equip");
74});
75
76test("metal shield uses leather dual-tint on equip and magenta icon", () =>
77{
78 const def = itemDefinition(ArmourItemId.ironShield);
79 assert.equal(def?.equipment?.slot, "offhand");
80 assert.equal(def?.equipment?.kind, EquipmentKind.shield);
81 assert.equal(def?.equipment?.equipSprite, "item:armour:shield:equip");
82 assert.equal(def?.iconTintFromTier, true);
83 assert.equal(def?.dualTintFromTier, true);
84 assert.equal(def?.leatherTier, "hardLeather");
85 const dual = resolveItemDualTint({ itemId: ArmourItemId.ironShield }, def);
86 assert.ok(dual?.shaft);
87 assert.ok(dual?.tip);
88 assert.equal(
89 defaultEquipmentStatBonuses().metalArmour.shield.iron.defence,
90 tierStatBonus(MaterialTier.iron)
91 );
92 const slots = {
93 ...emptyEquipment().slots,
94 offhand: { itemId: ArmourItemId.ironShield, quantity: 1 }
95 };
96 assert.equal(equipmentBonusesFromSlots(slots)[SkillId.defence], tierStatBonus(MaterialTier.iron));
97});
98
56test("leather shoes grant independent agility and defence from settings", () =>
99test("leather shoes grant independent agility and defence from settings", () =>
57{
100{
58 const settings = normalizeEquipmentStatBonuses({
101 const settings = normalizeEquipmentStatBonuses({
server/tests/level-up-unlocks.test.js added +56 −0
@@ -0,0 +1,56 @@
1 import test from "node:test";
2 import assert from "node:assert/strict";
3 import { SkillId } from "../../shared/definitions/skills.js";
4 import
5 {
6 skillUnlockMessages,
7 skillLevelUpToastText
8 } from "../../shared/skills/levelUpUnlocks.js";
9 import { applySkillXp, normalizePlayerSkills } from "../../shared/skills/state.js";
10 import { SKILL_XP_BASE } from "../../shared/skills/progression.js";
11
12 test("defence 9→10 unlocks iron armour wear", () =>
13 {
14 const lines = skillUnlockMessages(SkillId.defence, 9, 10);
15 assert.ok(lines.some((line) => /wear Iron armour/i.test(line)));
16 });
17
18 test("archery 9→10 unlocks birch bows", () =>
19 {
20 const lines = skillUnlockMessages(SkillId.archery, 9, 10);
21 assert.ok(lines.some((line) => /Birch bows and Iron arrows/i.test(line)));
22 });
23
24 test("mining gather unlock for mithril", () =>
25 {
26 const lines = skillUnlockMessages(SkillId.mining, 17, 18);
27 assert.ok(lines.some((line) => /mine Mithril ore/i.test(line)));
28 });
29
30 test("smithing craft unlock for adamantium", () =>
31 {
32 const lines = skillUnlockMessages(SkillId.smithing, 37, 38);
33 assert.ok(lines.some((line) => /smith Adamantium items/i.test(line)));
34 });
35
36 test("toast text includes title and unlock line", () =>
37 {
38 const text = skillLevelUpToastText(SkillId.defence, 10, 9);
39 assert.match(text, /Your Defence leveled up to 10!/);
40 assert.match(text, /You can now wear Iron armour\./);
41 });
42
43 test("multi-level jump reports unlocks for every crossed gate", () =>
44 {
45 const lines = skillUnlockMessages(SkillId.woodcutting, 4, 10);
46 assert.ok(lines.some((line) => /chop Birch trees/i.test(line)));
47 assert.ok(lines.some((line) => /equip Iron axes/i.test(line)));
48 });
49
50 test("applySkillXp includes previousLevel on level-up", () =>
51 {
52 const skills = normalizePlayerSkills(null);
53 const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);
54 assert.equal(result.levelUp?.level, 2);
55 assert.equal(result.levelUp?.previousLevel, 1);
56 });
@@ -0,0 +1,56 @@
1import test from "node:test";
2import assert from "node:assert/strict";
3import { SkillId } from "../../shared/definitions/skills.js";
4import
5 {
6 skillUnlockMessages,
7 skillLevelUpToastText
8 } from "../../shared/skills/levelUpUnlocks.js";
9import { applySkillXp, normalizePlayerSkills } from "../../shared/skills/state.js";
10import { SKILL_XP_BASE } from "../../shared/skills/progression.js";
11
12test("defence 9→10 unlocks iron armour wear", () =>
13{
14 const lines = skillUnlockMessages(SkillId.defence, 9, 10);
15 assert.ok(lines.some((line) => /wear Iron armour/i.test(line)));
16});
17
18test("archery 9→10 unlocks birch bows", () =>
19{
20 const lines = skillUnlockMessages(SkillId.archery, 9, 10);
21 assert.ok(lines.some((line) => /Birch bows and Iron arrows/i.test(line)));
22});
23
24test("mining gather unlock for mithril", () =>
25{
26 const lines = skillUnlockMessages(SkillId.mining, 17, 18);
27 assert.ok(lines.some((line) => /mine Mithril ore/i.test(line)));
28});
29
30test("smithing craft unlock for adamantium", () =>
31{
32 const lines = skillUnlockMessages(SkillId.smithing, 37, 38);
33 assert.ok(lines.some((line) => /smith Adamantium items/i.test(line)));
34});
35
36test("toast text includes title and unlock line", () =>
37{
38 const text = skillLevelUpToastText(SkillId.defence, 10, 9);
39 assert.match(text, /Your Defence leveled up to 10!/);
40 assert.match(text, /You can now wear Iron armour\./);
41});
42
43test("multi-level jump reports unlocks for every crossed gate", () =>
44{
45 const lines = skillUnlockMessages(SkillId.woodcutting, 4, 10);
46 assert.ok(lines.some((line) => /chop Birch trees/i.test(line)));
47 assert.ok(lines.some((line) => /equip Iron axes/i.test(line)));
48});
49
50test("applySkillXp includes previousLevel on level-up", () =>
51{
52 const skills = normalizePlayerSkills(null);
53 const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);
54 assert.equal(result.levelUp?.level, 2);
55 assert.equal(result.levelUp?.previousLevel, 1);
56});
shared/crafting/tierRecipes.js +25 −17
@@ -3,23 +3,25 @@ import { ItemId } from "../definitions/items.js";
3 3 import { ItemFamilyId } from "../definitions/tierFamilies.js";
4 4 import { familyItemId } from "../definitions/familyItemIds.js";
5 5 import { WoodItemId } from "../definitions/woodItems.js";
6 import {
7 WOOD_TIER_ORDER,
8 MATERIAL_TIER_ORDER,
9 CLOTH_TIER_ORDER,
10 MATERIAL_DISPLAY_NAME,
11 WoodTier,
12 woodTierForMetal,
13 leatherTierForMetal,
14 clothTierForWood,
15 tierSmeltSkillLevel,
16 tierCraftSkillLevel,
17 tierMinSkillLevel
18 } from "../definitions/materialTiers.js";
19 import {
20 ARMOUR_CRAFT_PIECES,
21 armourItemIdForTier
22 } from "../definitions/armourItems.js";
6 import
7 {
8 WOOD_TIER_ORDER,
9 MATERIAL_TIER_ORDER,
10 CLOTH_TIER_ORDER,
11 MATERIAL_DISPLAY_NAME,
12 WoodTier,
13 woodTierForMetal,
14 leatherTierForMetal,
15 clothTierForWood,
16 tierSmeltSkillLevel,
17 tierCraftSkillLevel,
18 tierMinSkillLevel
19 } from "../definitions/materialTiers.js";
20 import
21 {
22 ARMOUR_CRAFT_PIECES,
23 armourItemIdForTier
24 } from "../definitions/armourItems.js";
23 25 import { RangedItemId } from "../definitions/rangedItems.js";
24 26 import { yarnItemId } from "../definitions/clothItems.js";
25 27 import { leatherMaterialItemId } from "../definitions/leatherItems.js";
@@ -405,6 +407,12 @@ function armourRecipes ()
405 407 const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }];
406 408 if (piece.needsBone)
407 409 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
410 if (piece.needsLeather)
411 {
412 const leatherId = leatherMaterialItemId(leatherTierForMetal(metalTier));
413 if (leatherId != null)
414 { inputs.push({ itemId: leatherId, quantity: 1 }); }
415 }
408 416 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
409 417 return Object.freeze({
410 418 recipeId: `armour-${piece.suffix}-${metalTier}`,
@@ -3,23 +3,25 @@ import { ItemId } from "../definitions/items.js";
3import { ItemFamilyId } from "../definitions/tierFamilies.js";
3import { ItemFamilyId } from "../definitions/tierFamilies.js";
4import { familyItemId } from "../definitions/familyItemIds.js";
4import { familyItemId } from "../definitions/familyItemIds.js";
5import { WoodItemId } from "../definitions/woodItems.js";
5import { WoodItemId } from "../definitions/woodItems.js";
6import {
6import
7 WOOD_TIER_ORDER,
7 {
8 MATERIAL_TIER_ORDER,
8 WOOD_TIER_ORDER,
9 CLOTH_TIER_ORDER,
9 MATERIAL_TIER_ORDER,
10 MATERIAL_DISPLAY_NAME,
10 CLOTH_TIER_ORDER,
11 WoodTier,
11 MATERIAL_DISPLAY_NAME,
12 woodTierForMetal,
12 WoodTier,
13 leatherTierForMetal,
13 woodTierForMetal,
14 clothTierForWood,
14 leatherTierForMetal,
15 tierSmeltSkillLevel,
15 clothTierForWood,
16 tierCraftSkillLevel,
16 tierSmeltSkillLevel,
17 tierMinSkillLevel
17 tierCraftSkillLevel,
18} from "../definitions/materialTiers.js";
18 tierMinSkillLevel
19import {
19 } from "../definitions/materialTiers.js";
20 ARMOUR_CRAFT_PIECES,
20import
21 armourItemIdForTier
21 {
22} from "../definitions/armourItems.js";
22 ARMOUR_CRAFT_PIECES,
23 armourItemIdForTier
24 } from "../definitions/armourItems.js";
23import { RangedItemId } from "../definitions/rangedItems.js";
25import { RangedItemId } from "../definitions/rangedItems.js";
24import { yarnItemId } from "../definitions/clothItems.js";
26import { yarnItemId } from "../definitions/clothItems.js";
25import { leatherMaterialItemId } from "../definitions/leatherItems.js";
27import { leatherMaterialItemId } from "../definitions/leatherItems.js";
@@ -405,6 +407,12 @@ function armourRecipes ()
405 const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }];
407 const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }];
406 if (piece.needsBone)
408 if (piece.needsBone)
407 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
409 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
410 if (piece.needsLeather)
411 {
412 const leatherId = leatherMaterialItemId(leatherTierForMetal(metalTier));
413 if (leatherId != null)
414 { inputs.push({ itemId: leatherId, quantity: 1 }); }
415 }
408 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
416 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
409 return Object.freeze({
417 return Object.freeze({
410 recipeId: `armour-${piece.suffix}-${metalTier}`,
418 recipeId: `armour-${piece.suffix}-${metalTier}`,
shared/definitions/armourItems.js +58 −10
@@ -1,16 +1,18 @@
1 1 import { ItemCategory } from "./itemCategories.js";
2 import {
3 MaterialTier,
2 import
3 {
4 4 MATERIAL_TIER_ORDER,
5 5 MATERIAL_DISPLAY_NAME,
6 tierMinSkillLevel
6 tierMinSkillLevel,
7 leatherTierForMetal
7 8 } from "./materialTiers.js";
8 9 import { EquipmentKind } from "./equipmentKinds.js";
9 10 import { equipImageName } from "./tileSprites.js";
10 11
11 12 /**
12 * Metal armour — shared overlay sprites in items/armour/*-equip.png,
13 * per-tier tint via magenta mask. Shield (offhand) not included yet.
13 * Metal armour — shared overlay sprites in items/armour/*-equip.png.
14 * Most pieces: magenta → metal. Shield equip is dual-channel (red metal, blue leather);
15 * shield inventory icon stays magenta metal only.
14 16 */
15 17 export const ArmourItemId = Object.freeze({
16 18 bronzeChestplate: 91,
@@ -54,7 +56,21 @@ export const ArmourItemId = Object.freeze({
54 56 dragonBoots: 129,
55 57 dragonHelmet: 130,
56 58 dragonFullHelm: 131,
57 dragonHornedHelm: 132
59 dragonHornedHelm: 132,
60 bronzeSkirt: 475,
61 ironSkirt: 476,
62 steelSkirt: 477,
63 mithrilSkirt: 478,
64 adamantiumSkirt: 479,
65 orichalcumSkirt: 480,
66 dragonSkirt: 481,
67 bronzeShield: 482,
68 ironShield: 483,
69 steelShield: 484,
70 mithrilShield: 485,
71 adamantiumShield: 486,
72 orichalcumShield: 487,
73 dragonShield: 488
58 74 });
59 75
60 76 const ARMOUR_PIECES = Object.freeze([
@@ -74,6 +90,15 @@ const ARMOUR_PIECES = Object.freeze([
74 90 idKey: "Greaves",
75 91 ingots: 4
76 92 }),
93 /** Same slot/cost/defence as greaves; alternate legs look. */
94 Object.freeze({
95 suffix: "skirt",
96 slot: "legs",
97 label: "skirt",
98 overlay: "skirt",
99 idKey: "Skirt",
100 ingots: 4
101 }),
77 102 Object.freeze({
78 103 suffix: "boots",
79 104 slot: "boots",
@@ -107,6 +132,18 @@ const ARMOUR_PIECES = Object.freeze([
107 132 idKey: "HornedHelm",
108 133 ingots: 2,
109 134 needsBone: true
135 }),
136 Object.freeze({
137 suffix: "shield",
138 slot: "offhand",
139 label: "shield",
140 overlay: "shield",
141 idKey: "Shield",
142 ingots: 4,
143 kind: EquipmentKind.shield,
144 needsLeather: true,
145 /** Equip: red = metal, blue = leather. Icon: magenta metal only. */
146 dualTintLeather: true
110 147 })
111 148 ]);
112 149
@@ -119,18 +156,21 @@ function armourDef (itemId, tier, piece)
119 156 {
120 157 const tierName = MATERIAL_DISPLAY_NAME[tier] ?? tier;
121 158 const key = `${tier}-${piece.suffix}`;
159 const kind = piece.kind ?? EquipmentKind.metalArmour;
160 const dualTintLeather = !!piece.dualTintLeather;
122 161 const equipment = {
123 162 slot: piece.slot,
124 163 tier,
125 kind: EquipmentKind.metalArmour,
126 tintFromTier: true,
164 kind,
127 165 equipSprite: equipImageName("item", "armour", piece.overlay)
128 166 };
167 if (!dualTintLeather)
168 { equipment.tintFromTier = true; }
129 169 if (piece.fullHelm)
130 170 {
131 171 equipment.minSkillLevel = tierMinSkillLevel(tier) + 1;
132 172 }
133 return Object.freeze({
173 const def = {
134 174 itemId,
135 175 key,
136 176 displayName: `${tierName} ${piece.label}`,
@@ -145,7 +185,15 @@ function armourDef (itemId, tier, piece)
145 185 defaultState: piece.overlay,
146 186 tintFromTier: true,
147 187 equipment: Object.freeze(equipment)
148 });
188 };
189 if (dualTintLeather)
190 {
191 def.leatherTier = leatherTierForMetal(tier);
192 def.dualTintFromTier = true;
193 /** Inventory icon stays single-channel magenta; worn overlay uses dual tint. */
194 def.iconTintFromTier = true;
195 }
196 return Object.freeze(def);
149 197 }
150 198
151 199 function buildArmourDefinitions ()
@@ -1,16 +1,18 @@
1import { ItemCategory } from "./itemCategories.js";
1import { ItemCategory } from "./itemCategories.js";
2import {
2import
3 MaterialTier,
3{
4 MATERIAL_TIER_ORDER,
4 MATERIAL_TIER_ORDER,
5 MATERIAL_DISPLAY_NAME,
5 MATERIAL_DISPLAY_NAME,
6 tierMinSkillLevel
6 tierMinSkillLevel,
7 leatherTierForMetal
7} from "./materialTiers.js";
8} from "./materialTiers.js";
8import { EquipmentKind } from "./equipmentKinds.js";
9import { EquipmentKind } from "./equipmentKinds.js";
9import { equipImageName } from "./tileSprites.js";
10import { equipImageName } from "./tileSprites.js";
10
11
11/**
12/**
12 * Metal armour — shared overlay sprites in items/armour/*-equip.png,
13 * Metal armour — shared overlay sprites in items/armour/*-equip.png.
13 * per-tier tint via magenta mask. Shield (offhand) not included yet.
14 * Most pieces: magenta → metal. Shield equip is dual-channel (red metal, blue leather);
15 * shield inventory icon stays magenta metal only.
14 */
16 */
15export const ArmourItemId = Object.freeze({
17export const ArmourItemId = Object.freeze({
16 bronzeChestplate: 91,
18 bronzeChestplate: 91,
@@ -54,7 +56,21 @@ export const ArmourItemId = Object.freeze({
54 dragonBoots: 129,
56 dragonBoots: 129,
55 dragonHelmet: 130,
57 dragonHelmet: 130,
56 dragonFullHelm: 131,
58 dragonFullHelm: 131,
57 dragonHornedHelm: 132
59 dragonHornedHelm: 132,
60 bronzeSkirt: 475,
61 ironSkirt: 476,
62 steelSkirt: 477,
63 mithrilSkirt: 478,
64 adamantiumSkirt: 479,
65 orichalcumSkirt: 480,
66 dragonSkirt: 481,
67 bronzeShield: 482,
68 ironShield: 483,
69 steelShield: 484,
70 mithrilShield: 485,
71 adamantiumShield: 486,
72 orichalcumShield: 487,
73 dragonShield: 488
58});
74});
59
75
60const ARMOUR_PIECES = Object.freeze([
76const ARMOUR_PIECES = Object.freeze([
@@ -74,6 +90,15 @@ const ARMOUR_PIECES = Object.freeze([
74 idKey: "Greaves",
90 idKey: "Greaves",
75 ingots: 4
91 ingots: 4
76 }),
92 }),
93 /** Same slot/cost/defence as greaves; alternate legs look. */
94 Object.freeze({
95 suffix: "skirt",
96 slot: "legs",
97 label: "skirt",
98 overlay: "skirt",
99 idKey: "Skirt",
100 ingots: 4
101 }),
77 Object.freeze({
102 Object.freeze({
78 suffix: "boots",
103 suffix: "boots",
79 slot: "boots",
104 slot: "boots",
@@ -107,6 +132,18 @@ const ARMOUR_PIECES = Object.freeze([
107 idKey: "HornedHelm",
132 idKey: "HornedHelm",
108 ingots: 2,
133 ingots: 2,
109 needsBone: true
134 needsBone: true
135 }),
136 Object.freeze({
137 suffix: "shield",
138 slot: "offhand",
139 label: "shield",
140 overlay: "shield",
141 idKey: "Shield",
142 ingots: 4,
143 kind: EquipmentKind.shield,
144 needsLeather: true,
145 /** Equip: red = metal, blue = leather. Icon: magenta metal only. */
146 dualTintLeather: true
110 })
147 })
111]);
148]);
112
149
@@ -119,18 +156,21 @@ function armourDef (itemId, tier, piece)
119{
156{
120 const tierName = MATERIAL_DISPLAY_NAME[tier] ?? tier;
157 const tierName = MATERIAL_DISPLAY_NAME[tier] ?? tier;
121 const key = `${tier}-${piece.suffix}`;
158 const key = `${tier}-${piece.suffix}`;
159 const kind = piece.kind ?? EquipmentKind.metalArmour;
160 const dualTintLeather = !!piece.dualTintLeather;
122 const equipment = {
161 const equipment = {
123 slot: piece.slot,
162 slot: piece.slot,
124 tier,
163 tier,
125 kind: EquipmentKind.metalArmour,
164 kind,
126 tintFromTier: true,
127 equipSprite: equipImageName("item", "armour", piece.overlay)
165 equipSprite: equipImageName("item", "armour", piece.overlay)
128 };
166 };
167 if (!dualTintLeather)
168 { equipment.tintFromTier = true; }
129 if (piece.fullHelm)
169 if (piece.fullHelm)
130 {
170 {
131 equipment.minSkillLevel = tierMinSkillLevel(tier) + 1;
171 equipment.minSkillLevel = tierMinSkillLevel(tier) + 1;
132 }
172 }
133 return Object.freeze({
173 const def = {
134 itemId,
174 itemId,
135 key,
175 key,
136 displayName: `${tierName} ${piece.label}`,
176 displayName: `${tierName} ${piece.label}`,
@@ -145,7 +185,15 @@ function armourDef (itemId, tier, piece)
145 defaultState: piece.overlay,
185 defaultState: piece.overlay,
146 tintFromTier: true,
186 tintFromTier: true,
147 equipment: Object.freeze(equipment)
187 equipment: Object.freeze(equipment)
148 });
188 };
189 if (dualTintLeather)
190 {
191 def.leatherTier = leatherTierForMetal(tier);
192 def.dualTintFromTier = true;
193 /** Inventory icon stays single-channel magenta; worn overlay uses dual tint. */
194 def.iconTintFromTier = true;
195 }
196 return Object.freeze(def);
149}
197}
150
198
151function buildArmourDefinitions ()
199function buildArmourDefinitions ()
shared/definitions/equipmentStatCategories.js +13 −13
@@ -1,18 +1,18 @@
1 1 import { SkillId } from "./skills.js";
2 2 import { EquipmentKind } from "./equipmentKinds.js";
3 3 import
4 {
5 MATERIAL_TIER_ORDER,
6 WOOD_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 LEATHER_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
10 CLOTH_DISPLAY_NAME,
11 LEATHER_DISPLAY_NAME,
12 WoodTier,
13 tierStatBonus,
14 tierRank
15 } from "./materialTiers.js";
4 {
5 MATERIAL_TIER_ORDER,
6 WOOD_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 LEATHER_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
10 CLOTH_DISPLAY_NAME,
11 LEATHER_DISPLAY_NAME,
12 WoodTier,
13 tierStatBonus,
14 tierRank
15 } from "./materialTiers.js";
16 16 import { ARMOUR_CRAFT_PIECES, armourItemIdForTier } from "./armourItems.js";
17 17 import { sweaterItemId, shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "./clothItems.js";
18 18 import { LeatherItemId } from "./leatherItems.js";
@@ -273,7 +273,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
273 273 Object.freeze({
274 274 pieceKey: "shirt",
275 275 label: "Shirt",
276 defaultBonus: 1,
276 defaultBonus: 0,
277 277 resolveItemId: (tier) => shirtItemId(tier)
278 278 })
279 279 ])
@@ -1,18 +1,18 @@
1import { SkillId } from "./skills.js";
1import { SkillId } from "./skills.js";
2import { EquipmentKind } from "./equipmentKinds.js";
2import { EquipmentKind } from "./equipmentKinds.js";
3import
3import
4 {
4{
5 MATERIAL_TIER_ORDER,
5 MATERIAL_TIER_ORDER,
6 WOOD_TIER_ORDER,
6 WOOD_TIER_ORDER,
7 CLOTH_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 LEATHER_TIER_ORDER,
8 LEATHER_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
9 MATERIAL_DISPLAY_NAME,
10 CLOTH_DISPLAY_NAME,
10 CLOTH_DISPLAY_NAME,
11 LEATHER_DISPLAY_NAME,
11 LEATHER_DISPLAY_NAME,
12 WoodTier,
12 WoodTier,
13 tierStatBonus,
13 tierStatBonus,
14 tierRank
14 tierRank
15 } from "./materialTiers.js";
15} from "./materialTiers.js";
16import { ARMOUR_CRAFT_PIECES, armourItemIdForTier } from "./armourItems.js";
16import { ARMOUR_CRAFT_PIECES, armourItemIdForTier } from "./armourItems.js";
17import { sweaterItemId, shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "./clothItems.js";
17import { sweaterItemId, shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "./clothItems.js";
18import { LeatherItemId } from "./leatherItems.js";
18import { LeatherItemId } from "./leatherItems.js";
@@ -273,7 +273,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
273 Object.freeze({
273 Object.freeze({
274 pieceKey: "shirt",
274 pieceKey: "shirt",
275 label: "Shirt",
275 label: "Shirt",
276 defaultBonus: 1,
276 defaultBonus: 0,
277 resolveItemId: (tier) => shirtItemId(tier)
277 resolveItemId: (tier) => shirtItemId(tier)
278 })
278 })
279 ])
279 ])
shared/render/tint.js +1 −1
@@ -273,7 +273,7 @@ export function resolveItemTint (stackOrDef, def = null)
273 273 { return normalizeRgb(stack.instance.dyeColor); }
274 274 if (definition?.tint)
275 275 { return normalizeRgb(definition.tint); }
276 if (definition?.dualTintFromTier)
276 if (definition?.dualTintFromTier && !definition?.iconTintFromTier)
277 277 { return null; }
278 278 if (definition?.tintFromTier === "ash" && definition.tier)
279 279 { return ashTintColor(definition.tier); }
@@ -273,7 +273,7 @@ export function resolveItemTint (stackOrDef, def = null)
273 { return normalizeRgb(stack.instance.dyeColor); }
273 { return normalizeRgb(stack.instance.dyeColor); }
274 if (definition?.tint)
274 if (definition?.tint)
275 { return normalizeRgb(definition.tint); }
275 { return normalizeRgb(definition.tint); }
276 if (definition?.dualTintFromTier)
276 if (definition?.dualTintFromTier && !definition?.iconTintFromTier)
277 { return null; }
277 { return null; }
278 if (definition?.tintFromTier === "ash" && definition.tier)
278 if (definition?.tintFromTier === "ash" && definition.tier)
279 { return ashTintColor(definition.tier); }
279 { return ashTintColor(definition.tier); }
shared/skills/levelUpUnlocks.js added +243 −0
@@ -0,0 +1,243 @@
1 import { SkillId, SKILL_DEFINITIONS } from "../definitions/skills.js";
2 import
3 {
4 MATERIAL_TIER_ORDER,
5 WOOD_TIER_ORDER,
6 CLOTH_TIER_ORDER,
7 LEATHER_TIER_ORDER,
8 GEM_TIER_ORDER,
9 ORE_BEARING_MATERIALS,
10 MATERIAL_DISPLAY_NAME,
11 CLOTH_DISPLAY_NAME,
12 LEATHER_DISPLAY_NAME,
13 woodTierForMetal,
14 tierMinSkillLevel,
15 tierMineSkillLevel,
16 tierSmeltSkillLevel,
17 isGemstoneMaterial,
18 GatherMaterialId
19 } from "../definitions/materialTiers.js";
20 import { firestartingDifficulty } from "../definitions/craftingStations.js";
21 import { HERB_DEFINITIONS, HERB_GATHER_SKILL_LEVEL } from "../definitions/herbs.js";
22 import { SPELL_DEFINITIONS } from "../definitions/spells.js";
23 import { ALCHEMY_POTION_DEFINITIONS } from "../definitions/alchemy.js";
24
25 /**
26 * Unlock lines for skill thresholds crossed when leveling from `fromLevel` (exclusive)
27 * to `toLevel` (inclusive). Pure / shared — used by client toasts.
28 * @param {string} skillId
29 * @param {number} fromLevel
30 * @param {number} toLevel
31 * @returns {string[]}
32 */
33 export function skillUnlockMessages (skillId, fromLevel, toLevel)
34 {
35 const from = Math.max(0, Math.floor(Number(fromLevel) || 0));
36 const to = Math.max(0, Math.floor(Number(toLevel) || 0));
37 if (to <= from)
38 { return []; }
39 const entries = unlockCatalog().filter((entry) => entry.skillId === skillId
40 && entry.level > from
41 && entry.level <= to);
42 entries.sort((a, b) => a.level - b.level || a.message.localeCompare(b.message));
43 return entries.map((entry) => entry.message);
44 }
45
46 /** Level-up toast title line. */
47 export function skillLevelUpToastTitle (skillId, level)
48 {
49 const name = SKILL_DEFINITIONS[skillId]?.displayName ?? skillId;
50 return `Your ${name} leveled up to ${level | 0}!`;
51 }
52
53 /**
54 * Full toast body: title + unlock lines.
55 * @returns {string}
56 */
57 export function skillLevelUpToastText (skillId, level, previousLevel = null)
58 {
59 const prev = previousLevel == null ? Math.max(0, (level | 0) - 1) : previousLevel | 0;
60 const lines = [
61 skillLevelUpToastTitle(skillId, level),
62 ...skillUnlockMessages(skillId, prev, level)
63 ];
64 return lines.join("\n");
65 }
66
67 /** @type {null | Array<{ skillId: string, level: number, message: string }>} */
68 let _catalog = null;
69
70 function unlockCatalog ()
71 {
72 if (!_catalog)
73 { _catalog = buildUnlockCatalog(); }
74 return _catalog;
75 }
76
77 /** Reset cache (tests). */
78 export function clearSkillUnlockCatalogCache ()
79 {
80 _catalog = null;
81 }
82
83 function buildUnlockCatalog ()
84 {
85 /** @type {Array<{ skillId: string, level: number, message: string }>} */
86 const out = [];
87 const add = (skillId, level, message) =>
88 {
89 if ((level | 0) <= 1)
90 { return; }
91 out.push({ skillId, level: level | 0, message });
92 };
93
94 for (const metal of MATERIAL_TIER_ORDER)
95 {
96 const name = MATERIAL_DISPLAY_NAME[metal] ?? metal;
97 const wood = woodTierForMetal(metal);
98 const woodName = MATERIAL_DISPLAY_NAME[wood] ?? wood;
99 const equip = tierMinSkillLevel(metal);
100 const craft = tierSmeltSkillLevel(metal);
101
102 add(SkillId.defence, equip, `You can now wear ${name} armour.`);
103 add(SkillId.swordfighting, equip, `You can now equip ${name} swords.`);
104 add(SkillId.axefighting, equip, `You can now equip ${name} war axes.`);
105 add(SkillId.archery, equip, `You can now equip ${woodName} bows and ${name} arrows.`);
106 add(SkillId.woodcutting, equip, `You can now equip ${name} axes.`);
107 add(SkillId.mining, equip, `You can now equip ${name} pickaxes.`);
108 add(SkillId.herbalism, equip, `You can now equip ${name} plant clippers.`);
109 add(SkillId.smithing, craft, `You can now smith ${name} items.`);
110 add(SkillId.crafting, craft, `You can now craft ${name} tools.`);
111 add(SkillId.crafting, equip, `You can now craft ${name} arrows.`);
112 }
113
114 for (const wood of WOOD_TIER_ORDER)
115 {
116 const name = MATERIAL_DISPLAY_NAME[wood] ?? wood;
117 const equip = tierMinSkillLevel(wood);
118 const craft = tierSmeltSkillLevel(wood);
119 const fell = tierMineSkillLevel(wood);
120 const light = firestartingDifficulty(wood);
121
122 add(SkillId.clubfighting, equip, `You can now equip ${name} quarterstaves.`);
123 add(SkillId.magic, equip, `You can now equip ${name} staves.`);
124 add(SkillId.fishing, equip, `You can now equip ${name} fishing rods.`);
125 add(SkillId.crafting, craft, `You can now craft ${name} wood items.`);
126 add(SkillId.crafting, equip, `You can now craft ${name} bows.`);
127 add(SkillId.jewelering, equip, `You can now craft ${name} staves.`);
128 add(SkillId.woodcutting, fell, `You can now chop ${name} trees.`);
129 add(SkillId.firestarting, light, `You can now light ${name} logs.`);
130 }
131
132 for (const leather of LEATHER_TIER_ORDER)
133 {
134 const name = LEATHER_DISPLAY_NAME[leather] ?? leather;
135 const craft = tierSmeltSkillLevel(leather);
136 add(SkillId.leatherworking, craft, `You can now craft ${name}.`);
137 }
138
139 for (const cloth of CLOTH_TIER_ORDER)
140 {
141 const name = CLOTH_DISPLAY_NAME[cloth] ?? cloth;
142 const equip = tierMinSkillLevel(cloth);
143 const craft = tierSmeltSkillLevel(cloth);
144 add(SkillId.defence, equip, `You can now wear ${name} clothing.`);
145 add(SkillId.tailoring, craft, `You can now tailor ${name} goods.`);
146 }
147
148 for (const gem of GEM_TIER_ORDER)
149 {
150 const name = MATERIAL_DISPLAY_NAME[gem] ?? gem;
151 const cut = tierSmeltSkillLevel(gem);
152 add(SkillId.jewelering, cut, `You can now cut ${name}.`);
153 }
154
155 /** @type {Map<number, string[]>} */
156 const mineByLevel = new Map();
157 for (const material of ORE_BEARING_MATERIALS)
158 {
159 if (material === GatherMaterialId.bronze || material === GatherMaterialId.steel)
160 { continue; }
161 const level = tierMineSkillLevel(material);
162 const name = MATERIAL_DISPLAY_NAME[material] ?? material;
163 let label = name;
164 if (material === GatherMaterialId.coal)
165 { label = "Coal"; }
166 else if (!isGemstoneMaterial(material))
167 { label = `${name} ore`; }
168 const list = mineByLevel.get(level) ?? [];
169 list.push(label);
170 mineByLevel.set(level, list);
171 }
172 for (const [level, labels] of mineByLevel)
173 {
174 add(SkillId.mining, level, `You can now mine ${joinNames(labels)}.`);
175 }
176
177 /** @type {Map<number, string[]>} */
178 const herbsByLevel = new Map();
179 for (const herb of Object.values(HERB_DEFINITIONS))
180 {
181 const level = HERB_GATHER_SKILL_LEVEL[herb.tier] ?? 1;
182 const list = herbsByLevel.get(level) ?? [];
183 list.push(herb.displayName);
184 herbsByLevel.set(level, list);
185 }
186 for (const [level, names] of herbsByLevel)
187 {
188 add(SkillId.herbalism, level, `You can now gather ${joinNames(names)}.`);
189 }
190
191 /** @type {Map<number, string[]>} */
192 const spellsByLevel = new Map();
193 for (const spell of Object.values(SPELL_DEFINITIONS))
194 {
195 if (spell.mobOnly || spell.starter)
196 { continue; }
197 const level = Math.max(1, spell.minMagicLevel | 0 || spell.tier | 0 || 1);
198 const list = spellsByLevel.get(level) ?? [];
199 list.push(spell.displayName);
200 spellsByLevel.set(level, list);
201 }
202 for (const [level, names] of spellsByLevel)
203 {
204 if (names.length <= 4)
205 { add(SkillId.magic, level, `You can now cast ${joinNames(names)}.`); }
206 else
207 { add(SkillId.magic, level, `You can now cast Magic level ${level} spells.`); }
208 }
209
210 /** @type {Map<number, string[]>} */
211 const potionsByLevel = new Map();
212 for (const potion of Object.values(ALCHEMY_POTION_DEFINITIONS))
213 {
214 const level = Math.max(1, potion.minAlchemyLevel | 0 || 1);
215 const list = potionsByLevel.get(level) ?? [];
216 list.push(potion.displayName);
217 potionsByLevel.set(level, list);
218 }
219 for (const [level, names] of potionsByLevel)
220 {
221 add(SkillId.alchemy, level, `You can now brew ${joinNames(names)}.`);
222 }
223
224 for (const material of [GatherMaterialId.silver, GatherMaterialId.gold, GatherMaterialId.electrum])
225 {
226 const name = MATERIAL_DISPLAY_NAME[material] ?? material;
227 add(SkillId.smithing, tierSmeltSkillLevel(material), `You can now smith ${name} bars.`);
228 }
229
230 return Object.freeze(out.map((entry) => Object.freeze(entry)));
231 }
232
233 function joinNames (names)
234 {
235 const list = [...names];
236 if (list.length === 0)
237 { return "new materials"; }
238 if (list.length === 1)
239 { return list[0]; }
240 if (list.length === 2)
241 { return `${list[0]} and ${list[1]}`; }
242 return `${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]}`;
243 }
@@ -0,0 +1,243 @@
1import { SkillId, SKILL_DEFINITIONS } from "../definitions/skills.js";
2import
3 {
4 MATERIAL_TIER_ORDER,
5 WOOD_TIER_ORDER,
6 CLOTH_TIER_ORDER,
7 LEATHER_TIER_ORDER,
8 GEM_TIER_ORDER,
9 ORE_BEARING_MATERIALS,
10 MATERIAL_DISPLAY_NAME,
11 CLOTH_DISPLAY_NAME,
12 LEATHER_DISPLAY_NAME,
13 woodTierForMetal,
14 tierMinSkillLevel,
15 tierMineSkillLevel,
16 tierSmeltSkillLevel,
17 isGemstoneMaterial,
18 GatherMaterialId
19 } from "../definitions/materialTiers.js";
20import { firestartingDifficulty } from "../definitions/craftingStations.js";
21import { HERB_DEFINITIONS, HERB_GATHER_SKILL_LEVEL } from "../definitions/herbs.js";
22import { SPELL_DEFINITIONS } from "../definitions/spells.js";
23import { ALCHEMY_POTION_DEFINITIONS } from "../definitions/alchemy.js";
24
25/**
26 * Unlock lines for skill thresholds crossed when leveling from `fromLevel` (exclusive)
27 * to `toLevel` (inclusive). Pure / shared — used by client toasts.
28 * @param {string} skillId
29 * @param {number} fromLevel
30 * @param {number} toLevel
31 * @returns {string[]}
32 */
33export function skillUnlockMessages (skillId, fromLevel, toLevel)
34{
35 const from = Math.max(0, Math.floor(Number(fromLevel) || 0));
36 const to = Math.max(0, Math.floor(Number(toLevel) || 0));
37 if (to <= from)
38 { return []; }
39 const entries = unlockCatalog().filter((entry) => entry.skillId === skillId
40 && entry.level > from
41 && entry.level <= to);
42 entries.sort((a, b) => a.level - b.level || a.message.localeCompare(b.message));
43 return entries.map((entry) => entry.message);
44}
45
46/** Level-up toast title line. */
47export function skillLevelUpToastTitle (skillId, level)
48{
49 const name = SKILL_DEFINITIONS[skillId]?.displayName ?? skillId;
50 return `Your ${name} leveled up to ${level | 0}!`;
51}
52
53/**
54 * Full toast body: title + unlock lines.
55 * @returns {string}
56 */
57export function skillLevelUpToastText (skillId, level, previousLevel = null)
58{
59 const prev = previousLevel == null ? Math.max(0, (level | 0) - 1) : previousLevel | 0;
60 const lines = [
61 skillLevelUpToastTitle(skillId, level),
62 ...skillUnlockMessages(skillId, prev, level)
63 ];
64 return lines.join("\n");
65}
66
67/** @type {null | Array<{ skillId: string, level: number, message: string }>} */
68let _catalog = null;
69
70function unlockCatalog ()
71{
72 if (!_catalog)
73 { _catalog = buildUnlockCatalog(); }
74 return _catalog;
75}
76
77/** Reset cache (tests). */
78export function clearSkillUnlockCatalogCache ()
79{
80 _catalog = null;
81}
82
83function buildUnlockCatalog ()
84{
85 /** @type {Array<{ skillId: string, level: number, message: string }>} */
86 const out = [];
87 const add = (skillId, level, message) =>
88 {
89 if ((level | 0) <= 1)
90 { return; }
91 out.push({ skillId, level: level | 0, message });
92 };
93
94 for (const metal of MATERIAL_TIER_ORDER)
95 {
96 const name = MATERIAL_DISPLAY_NAME[metal] ?? metal;
97 const wood = woodTierForMetal(metal);
98 const woodName = MATERIAL_DISPLAY_NAME[wood] ?? wood;
99 const equip = tierMinSkillLevel(metal);
100 const craft = tierSmeltSkillLevel(metal);
101
102 add(SkillId.defence, equip, `You can now wear ${name} armour.`);
103 add(SkillId.swordfighting, equip, `You can now equip ${name} swords.`);
104 add(SkillId.axefighting, equip, `You can now equip ${name} war axes.`);
105 add(SkillId.archery, equip, `You can now equip ${woodName} bows and ${name} arrows.`);
106 add(SkillId.woodcutting, equip, `You can now equip ${name} axes.`);
107 add(SkillId.mining, equip, `You can now equip ${name} pickaxes.`);
108 add(SkillId.herbalism, equip, `You can now equip ${name} plant clippers.`);
109 add(SkillId.smithing, craft, `You can now smith ${name} items.`);
110 add(SkillId.crafting, craft, `You can now craft ${name} tools.`);
111 add(SkillId.crafting, equip, `You can now craft ${name} arrows.`);
112 }
113
114 for (const wood of WOOD_TIER_ORDER)
115 {
116 const name = MATERIAL_DISPLAY_NAME[wood] ?? wood;
117 const equip = tierMinSkillLevel(wood);
118 const craft = tierSmeltSkillLevel(wood);
119 const fell = tierMineSkillLevel(wood);
120 const light = firestartingDifficulty(wood);
121
122 add(SkillId.clubfighting, equip, `You can now equip ${name} quarterstaves.`);
123 add(SkillId.magic, equip, `You can now equip ${name} staves.`);
124 add(SkillId.fishing, equip, `You can now equip ${name} fishing rods.`);
125 add(SkillId.crafting, craft, `You can now craft ${name} wood items.`);
126 add(SkillId.crafting, equip, `You can now craft ${name} bows.`);
127 add(SkillId.jewelering, equip, `You can now craft ${name} staves.`);
128 add(SkillId.woodcutting, fell, `You can now chop ${name} trees.`);
129 add(SkillId.firestarting, light, `You can now light ${name} logs.`);
130 }
131
132 for (const leather of LEATHER_TIER_ORDER)
133 {
134 const name = LEATHER_DISPLAY_NAME[leather] ?? leather;
135 const craft = tierSmeltSkillLevel(leather);
136 add(SkillId.leatherworking, craft, `You can now craft ${name}.`);
137 }
138
139 for (const cloth of CLOTH_TIER_ORDER)
140 {
141 const name = CLOTH_DISPLAY_NAME[cloth] ?? cloth;
142 const equip = tierMinSkillLevel(cloth);
143 const craft = tierSmeltSkillLevel(cloth);
144 add(SkillId.defence, equip, `You can now wear ${name} clothing.`);
145 add(SkillId.tailoring, craft, `You can now tailor ${name} goods.`);
146 }
147
148 for (const gem of GEM_TIER_ORDER)
149 {
150 const name = MATERIAL_DISPLAY_NAME[gem] ?? gem;
151 const cut = tierSmeltSkillLevel(gem);
152 add(SkillId.jewelering, cut, `You can now cut ${name}.`);
153 }
154
155 /** @type {Map<number, string[]>} */
156 const mineByLevel = new Map();
157 for (const material of ORE_BEARING_MATERIALS)
158 {
159 if (material === GatherMaterialId.bronze || material === GatherMaterialId.steel)
160 { continue; }
161 const level = tierMineSkillLevel(material);
162 const name = MATERIAL_DISPLAY_NAME[material] ?? material;
163 let label = name;
164 if (material === GatherMaterialId.coal)
165 { label = "Coal"; }
166 else if (!isGemstoneMaterial(material))
167 { label = `${name} ore`; }
168 const list = mineByLevel.get(level) ?? [];
169 list.push(label);
170 mineByLevel.set(level, list);
171 }
172 for (const [level, labels] of mineByLevel)
173 {
174 add(SkillId.mining, level, `You can now mine ${joinNames(labels)}.`);
175 }
176
177 /** @type {Map<number, string[]>} */
178 const herbsByLevel = new Map();
179 for (const herb of Object.values(HERB_DEFINITIONS))
180 {
181 const level = HERB_GATHER_SKILL_LEVEL[herb.tier] ?? 1;
182 const list = herbsByLevel.get(level) ?? [];
183 list.push(herb.displayName);
184 herbsByLevel.set(level, list);
185 }
186 for (const [level, names] of herbsByLevel)
187 {
188 add(SkillId.herbalism, level, `You can now gather ${joinNames(names)}.`);
189 }
190
191 /** @type {Map<number, string[]>} */
192 const spellsByLevel = new Map();
193 for (const spell of Object.values(SPELL_DEFINITIONS))
194 {
195 if (spell.mobOnly || spell.starter)
196 { continue; }
197 const level = Math.max(1, spell.minMagicLevel | 0 || spell.tier | 0 || 1);
198 const list = spellsByLevel.get(level) ?? [];
199 list.push(spell.displayName);
200 spellsByLevel.set(level, list);
201 }
202 for (const [level, names] of spellsByLevel)
203 {
204 if (names.length <= 4)
205 { add(SkillId.magic, level, `You can now cast ${joinNames(names)}.`); }
206 else
207 { add(SkillId.magic, level, `You can now cast Magic level ${level} spells.`); }
208 }
209
210 /** @type {Map<number, string[]>} */
211 const potionsByLevel = new Map();
212 for (const potion of Object.values(ALCHEMY_POTION_DEFINITIONS))
213 {
214 const level = Math.max(1, potion.minAlchemyLevel | 0 || 1);
215 const list = potionsByLevel.get(level) ?? [];
216 list.push(potion.displayName);
217 potionsByLevel.set(level, list);
218 }
219 for (const [level, names] of potionsByLevel)
220 {
221 add(SkillId.alchemy, level, `You can now brew ${joinNames(names)}.`);
222 }
223
224 for (const material of [GatherMaterialId.silver, GatherMaterialId.gold, GatherMaterialId.electrum])
225 {
226 const name = MATERIAL_DISPLAY_NAME[material] ?? material;
227 add(SkillId.smithing, tierSmeltSkillLevel(material), `You can now smith ${name} bars.`);
228 }
229
230 return Object.freeze(out.map((entry) => Object.freeze(entry)));
231}
232
233function joinNames (names)
234{
235 const list = [...names];
236 if (list.length === 0)
237 { return "new materials"; }
238 if (list.length === 1)
239 { return list[0]; }
240 if (list.length === 2)
241 { return `${list[0]} and ${list[1]}`; }
242 return `${list.slice(0, -1).join(", ")}, and ${list[list.length - 1]}`;
243}
shared/skills/state.js +4 −2
@@ -75,12 +75,14 @@ export function addSkillXp (skillsComponent, skillId, amount)
75 75 return skillsComponent.xp[skillId] !== current;
76 76 }
77 77
78 export function skillLevelUpPayload (skillId, level)
78 export function skillLevelUpPayload (skillId, level, previousLevel = null)
79 79 {
80 80 const def = SKILL_DEFINITIONS[skillId];
81 const prev = previousLevel == null ? Math.max(0, (level | 0) - 1) : previousLevel | 0;
81 82 return {
82 83 skillId,
83 84 level,
85 previousLevel: prev,
84 86 displayName: def?.displayName ?? skillId,
85 87 icon: `/assets/skills/${skillId}.svg`
86 88 };
@@ -101,7 +103,7 @@ export function applySkillXp (skillsComponent, skillId, amount)
101 103 { return { changed: true, levelUp: null }; }
102 104 return {
103 105 changed: true,
104 levelUp: skillLevelUpPayload(skillId, afterLevel)
106 levelUp: skillLevelUpPayload(skillId, afterLevel, beforeLevel)
105 107 };
106 108 }
107 109
@@ -75,12 +75,14 @@ export function addSkillXp (skillsComponent, skillId, amount)
75 return skillsComponent.xp[skillId] !== current;
75 return skillsComponent.xp[skillId] !== current;
76}
76}
77
77
78export function skillLevelUpPayload (skillId, level)
78export function skillLevelUpPayload (skillId, level, previousLevel = null)
79{
79{
80 const def = SKILL_DEFINITIONS[skillId];
80 const def = SKILL_DEFINITIONS[skillId];
81 const prev = previousLevel == null ? Math.max(0, (level | 0) - 1) : previousLevel | 0;
81 return {
82 return {
82 skillId,
83 skillId,
83 level,
84 level,
85 previousLevel: prev,
84 displayName: def?.displayName ?? skillId,
86 displayName: def?.displayName ?? skillId,
85 icon: `/assets/skills/${skillId}.svg`
87 icon: `/assets/skills/${skillId}.svg`
86 };
88 };
@@ -101,7 +103,7 @@ export function applySkillXp (skillsComponent, skillId, amount)
101 { return { changed: true, levelUp: null }; }
103 { return { changed: true, levelUp: null }; }
102 return {
104 return {
103 changed: true,
105 changed: true,
104 levelUp: skillLevelUpPayload(skillId, afterLevel)
106 levelUp: skillLevelUpPayload(skillId, afterLevel, beforeLevel)
105 };
107 };
106}
108}
107
109