BlueGit

timfa questward

ts

timfa Tim Falken · pushed by timfa

Authored 2026-08-28 · 2 months ago

Hash
f27d79264e96f81889cae144e5ef0655495e0b5d
Parent
e2760fc5
4 files changed +35 −33
client/src/play/inventory.js +11 −11
@@ -1,15 +1,15 @@
1 1 import
2 {
3 itemDefinition,
4 itemDescription,
5 itemOriginSummary,
6 itemAssetPathForStack,
7 itemDisplayName,
8 formatQuantity,
9 ItemId,
10 EQUIPMENT_SLOT,
11 LETTER_MAX_BODY_CHARS
12 } from "/shared/definitions/items.js";
2 {
3 itemDefinition,
4 itemDescription,
5 itemOriginSummary,
6 itemAssetPathForStack,
7 itemDisplayName,
8 formatQuantity,
9 ItemId,
10 EQUIPMENT_SLOT,
11 LETTER_MAX_BODY_CHARS
12 } from "/shared/definitions/items.js";
13 13 import { formatLetterSignature } from "/shared/courier/systemLetters.js";
14 14 import { applyItemIcon } from "../render/potionIcon.js";
15 15
@@ -1,15 +1,15 @@
1import
1import
2 {
2{
3 itemDefinition,
3 itemDefinition,
4 itemDescription,
4 itemDescription,
5 itemOriginSummary,
5 itemOriginSummary,
6 itemAssetPathForStack,
6 itemAssetPathForStack,
7 itemDisplayName,
7 itemDisplayName,
8 formatQuantity,
8 formatQuantity,
9 ItemId,
9 ItemId,
10 EQUIPMENT_SLOT,
10 EQUIPMENT_SLOT,
11 LETTER_MAX_BODY_CHARS
11 LETTER_MAX_BODY_CHARS
12 } from "/shared/definitions/items.js";
12} from "/shared/definitions/items.js";
13import { formatLetterSignature } from "/shared/courier/systemLetters.js";
13import { formatLetterSignature } from "/shared/courier/systemLetters.js";
14import { applyItemIcon } from "../render/potionIcon.js";
14import { applyItemIcon } from "../render/potionIcon.js";
15
15
server/tests/combatRolls.test.js +16 −14
@@ -2,15 +2,17 @@ import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { resolvePhysicalAttack, rollSkill } from "../../shared/combat/rolls.js";
4 4
5 test("rollSkill returns values within 1..skillLevel", () =>
5 test("rollSkill returns values within 0..skillLevel", () =>
6 6 {
7 7 const seen = new Set();
8 for (let i = 0; i < 200; i++)
8 for (let i = 0; i < 400; i++)
9 9 { seen.add(rollSkill(5, () => Math.random())); }
10 10 for (const value of seen)
11 11 {
12 assert.ok(value >= 1 && value <= 5);
12 assert.ok(value >= 0 && value <= 5);
13 13 }
14 assert.ok(seen.has(0));
15 assert.ok(seen.has(5));
14 16 });
15 17
16 18 test("deterministic rng produces stable rolls", () =>
@@ -18,9 +20,9 @@ test("deterministic rng produces stable rolls", () =>
18 20 let i = 0;
19 21 const seq = [0, 0.99, 0.5];
20 22 const rng = () => seq[i++ % seq.length];
21 assert.equal(rollSkill(4, rng), 1);
23 assert.equal(rollSkill(4, rng), 0);
22 24 assert.equal(rollSkill(4, rng), 4);
23 assert.equal(rollSkill(4, rng), 3);
25 assert.equal(rollSkill(4, rng), 2);
24 26 });
25 27
26 28 test("physical attack miss when agility roll beats hit roll", () =>
@@ -35,9 +37,9 @@ test("physical attack miss when agility roll beats hit roll", () =>
35 37 rng
36 38 });
37 39 assert.equal(result.outcome, "miss");
38 assert.equal(result.toHitRoll, 2);
39 assert.equal(result.agilityRoll, 5);
40 assert.equal(result.damageRoll, 1);
40 assert.equal(result.toHitRoll, 1);
41 assert.equal(result.agilityRoll, 4);
42 assert.equal(result.damageRoll, 0);
41 43 assert.equal(result.damage, 0);
42 44 });
43 45
@@ -76,7 +78,7 @@ test("physical attack block prevents damage after winning the hit contest", () =
76 78 test("physical attack hit applies rolled damage when not blocked", () =>
77 79 {
78 80 let i = 0;
79 const rolls = [0.9, 0, 0, 0];
81 const rolls = [0.9, 0, 0.5, 0];
80 82 const rng = () => rolls[i++];
81 83 const result = resolvePhysicalAttack({
82 84 hitSkillLevel: 10,
@@ -86,7 +88,7 @@ test("physical attack hit applies rolled damage when not blocked", () =>
86 88 rng
87 89 });
88 90 assert.equal(result.outcome, "hit");
89 assert.equal(result.damage, 1);
91 assert.equal(result.damage, 3);
90 92 });
91 93
92 94 test("physical damage is the damage skill roll only", () =>
@@ -102,8 +104,8 @@ test("physical damage is the damage skill roll only", () =>
102 104 rng
103 105 });
104 106 assert.equal(result.outcome, "hit");
105 assert.equal(result.damageRoll, 3);
106 assert.equal(result.damage, 3);
107 assert.equal(result.damageRoll, 2);
108 assert.equal(result.damage, 2);
107 109 });
108 110
109 111 test("skill level 1 contest can still land a hit on equal agility", () =>
@@ -116,6 +118,6 @@ test("skill level 1 contest can still land a hit on equal agility", () =>
116 118 rng: () => 0
117 119 });
118 120 assert.equal(result.outcome, "hit");
119 assert.equal(result.toHitRoll, 1);
120 assert.equal(result.agilityRoll, 1);
121 assert.equal(result.toHitRoll, 0);
122 assert.equal(result.agilityRoll, 0);
121 123 });
@@ -2,15 +2,17 @@ import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { resolvePhysicalAttack, rollSkill } from "../../shared/combat/rolls.js";
3import { resolvePhysicalAttack, rollSkill } from "../../shared/combat/rolls.js";
4
4
5test("rollSkill returns values within 1..skillLevel", () =>
5test("rollSkill returns values within 0..skillLevel", () =>
6{
6{
7 const seen = new Set();
7 const seen = new Set();
8 for (let i = 0; i < 200; i++)
8 for (let i = 0; i < 400; i++)
9 { seen.add(rollSkill(5, () => Math.random())); }
9 { seen.add(rollSkill(5, () => Math.random())); }
10 for (const value of seen)
10 for (const value of seen)
11 {
11 {
12 assert.ok(value >= 1 && value <= 5);
12 assert.ok(value >= 0 && value <= 5);
13 }
13 }
14 assert.ok(seen.has(0));
15 assert.ok(seen.has(5));
14});
16});
15
17
16test("deterministic rng produces stable rolls", () =>
18test("deterministic rng produces stable rolls", () =>
@@ -18,9 +20,9 @@ test("deterministic rng produces stable rolls", () =>
18 let i = 0;
20 let i = 0;
19 const seq = [0, 0.99, 0.5];
21 const seq = [0, 0.99, 0.5];
20 const rng = () => seq[i++ % seq.length];
22 const rng = () => seq[i++ % seq.length];
21 assert.equal(rollSkill(4, rng), 1);
23 assert.equal(rollSkill(4, rng), 0);
22 assert.equal(rollSkill(4, rng), 4);
24 assert.equal(rollSkill(4, rng), 4);
23 assert.equal(rollSkill(4, rng), 3);
25 assert.equal(rollSkill(4, rng), 2);
24});
26});
25
27
26test("physical attack miss when agility roll beats hit roll", () =>
28test("physical attack miss when agility roll beats hit roll", () =>
@@ -35,9 +37,9 @@ test("physical attack miss when agility roll beats hit roll", () =>
35 rng
37 rng
36 });
38 });
37 assert.equal(result.outcome, "miss");
39 assert.equal(result.outcome, "miss");
38 assert.equal(result.toHitRoll, 2);
40 assert.equal(result.toHitRoll, 1);
39 assert.equal(result.agilityRoll, 5);
41 assert.equal(result.agilityRoll, 4);
40 assert.equal(result.damageRoll, 1);
42 assert.equal(result.damageRoll, 0);
41 assert.equal(result.damage, 0);
43 assert.equal(result.damage, 0);
42});
44});
43
45
@@ -76,7 +78,7 @@ test("physical attack block prevents damage after winning the hit contest", () =
76test("physical attack hit applies rolled damage when not blocked", () =>
78test("physical attack hit applies rolled damage when not blocked", () =>
77{
79{
78 let i = 0;
80 let i = 0;
79 const rolls = [0.9, 0, 0, 0];
81 const rolls = [0.9, 0, 0.5, 0];
80 const rng = () => rolls[i++];
82 const rng = () => rolls[i++];
81 const result = resolvePhysicalAttack({
83 const result = resolvePhysicalAttack({
82 hitSkillLevel: 10,
84 hitSkillLevel: 10,
@@ -86,7 +88,7 @@ test("physical attack hit applies rolled damage when not blocked", () =>
86 rng
88 rng
87 });
89 });
88 assert.equal(result.outcome, "hit");
90 assert.equal(result.outcome, "hit");
89 assert.equal(result.damage, 1);
91 assert.equal(result.damage, 3);
90});
92});
91
93
92test("physical damage is the damage skill roll only", () =>
94test("physical damage is the damage skill roll only", () =>
@@ -102,8 +104,8 @@ test("physical damage is the damage skill roll only", () =>
102 rng
104 rng
103 });
105 });
104 assert.equal(result.outcome, "hit");
106 assert.equal(result.outcome, "hit");
105 assert.equal(result.damageRoll, 3);
107 assert.equal(result.damageRoll, 2);
106 assert.equal(result.damage, 3);
108 assert.equal(result.damage, 2);
107});
109});
108
110
109test("skill level 1 contest can still land a hit on equal agility", () =>
111test("skill level 1 contest can still land a hit on equal agility", () =>
@@ -116,6 +118,6 @@ test("skill level 1 contest can still land a hit on equal agility", () =>
116 rng: () => 0
118 rng: () => 0
117 });
119 });
118 assert.equal(result.outcome, "hit");
120 assert.equal(result.outcome, "hit");
119 assert.equal(result.toHitRoll, 1);
121 assert.equal(result.toHitRoll, 0);
120 assert.equal(result.agilityRoll, 1);
122 assert.equal(result.agilityRoll, 0);
121});
123});
server/tests/magic.test.js +5 −5
@@ -9,8 +9,8 @@ test("spell cast fails when difficulty roll beats magic roll", () =>
9 9 const rng = () => [0.25, 0.45][i++];
10 10 const cast = resolveSpellCast({ magicSkillLevel: 5, spellDifficulty: 10, rng });
11 11 assert.equal(cast.success, false);
12 assert.equal(cast.magicRoll, 2);
13 assert.equal(cast.difficultyRoll, 5);
12 assert.equal(cast.magicRoll, 1);
13 assert.equal(cast.difficultyRoll, 4);
14 14 });
15 15
16 16 test("spell cast succeeds on equal magic and difficulty rolls", () =>
@@ -40,7 +40,7 @@ test("fizzled magic attack deals no damage", () =>
40 40 test("successful magic attack rolls mind damage and elemental multiplier", () =>
41 41 {
42 42 let i = 0;
43 const rng = () => [0.9, 0, 0][i++];
43 const rng = () => [0.9, 0, 0.4][i++];
44 44 const neutral = resolveMagicAttack({
45 45 magicSkillLevel: 10,
46 46 spellDifficulty: 1,
@@ -51,10 +51,10 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
51 51 });
52 52 assert.equal(neutral.outcome, "hit");
53 53 assert.equal(neutral.multiplier, 1);
54 assert.equal(neutral.damage, 1);
54 assert.equal(neutral.damage, 2);
55 55
56 56 let j = 0;
57 const rngWeak = () => [0.9, 0, 0][j++];
57 const rngWeak = () => [0.9, 0, 0.4][j++];
58 58 const weak = resolveMagicAttack({
59 59 magicSkillLevel: 10,
60 60 spellDifficulty: 1,
@@ -9,8 +9,8 @@ test("spell cast fails when difficulty roll beats magic roll", () =>
9 const rng = () => [0.25, 0.45][i++];
9 const rng = () => [0.25, 0.45][i++];
10 const cast = resolveSpellCast({ magicSkillLevel: 5, spellDifficulty: 10, rng });
10 const cast = resolveSpellCast({ magicSkillLevel: 5, spellDifficulty: 10, rng });
11 assert.equal(cast.success, false);
11 assert.equal(cast.success, false);
12 assert.equal(cast.magicRoll, 2);
12 assert.equal(cast.magicRoll, 1);
13 assert.equal(cast.difficultyRoll, 5);
13 assert.equal(cast.difficultyRoll, 4);
14});
14});
15
15
16test("spell cast succeeds on equal magic and difficulty rolls", () =>
16test("spell cast succeeds on equal magic and difficulty rolls", () =>
@@ -40,7 +40,7 @@ test("fizzled magic attack deals no damage", () =>
40test("successful magic attack rolls mind damage and elemental multiplier", () =>
40test("successful magic attack rolls mind damage and elemental multiplier", () =>
41{
41{
42 let i = 0;
42 let i = 0;
43 const rng = () => [0.9, 0, 0][i++];
43 const rng = () => [0.9, 0, 0.4][i++];
44 const neutral = resolveMagicAttack({
44 const neutral = resolveMagicAttack({
45 magicSkillLevel: 10,
45 magicSkillLevel: 10,
46 spellDifficulty: 1,
46 spellDifficulty: 1,
@@ -51,10 +51,10 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
51 });
51 });
52 assert.equal(neutral.outcome, "hit");
52 assert.equal(neutral.outcome, "hit");
53 assert.equal(neutral.multiplier, 1);
53 assert.equal(neutral.multiplier, 1);
54 assert.equal(neutral.damage, 1);
54 assert.equal(neutral.damage, 2);
55
55
56 let j = 0;
56 let j = 0;
57 const rngWeak = () => [0.9, 0, 0][j++];
57 const rngWeak = () => [0.9, 0, 0.4][j++];
58 const weak = resolveMagicAttack({
58 const weak = resolveMagicAttack({
59 magicSkillLevel: 10,
59 magicSkillLevel: 10,
60 spellDifficulty: 1,
60 spellDifficulty: 1,
shared/combat/rolls.js +3 −3
@@ -1,8 +1,8 @@
1 /** Uniform integer roll in [1, skillLevel]. */
1 /** Uniform integer roll in [0, skillLevel]. */
2 2 export function rollSkill (skillLevel, rng = Math.random)
3 3 {
4 const max = Math.max(1, Math.floor(Number(skillLevel)) || 1);
5 return 1 + Math.floor(rng() * max);
4 const max = Math.max(0, Math.floor(Number(skillLevel)) || 0);
5 return Math.floor(rng() * (max + 1));
6 6 }
7 7
8 8 /**
@@ -1,8 +1,8 @@
1/** Uniform integer roll in [1, skillLevel]. */
1/** Uniform integer roll in [0, skillLevel]. */
2export function rollSkill (skillLevel, rng = Math.random)
2export function rollSkill (skillLevel, rng = Math.random)
3{
3{
4 const max = Math.max(1, Math.floor(Number(skillLevel)) || 1);
4 const max = Math.max(0, Math.floor(Number(skillLevel)) || 0);
5 return 1 + Math.floor(rng() * max);
5 return Math.floor(rng() * (max + 1));
6}
6}
7
7
8/**
8/**