Goblin slashing melee without equipment; fix deterministic combat tests.
Goblins use a baked-in sword attack profile. Combat integration tests now use roll sequences that deal damage under current rules. Push requires a green npm test run.
@@ -15,6 +15,7 @@ alwaysApply: true
15
15
16
16
“Push” / “naar origin” means this sequence:
17
17
18
0. Run the **full** test suite: `npm test`. **Every test must pass.** Do not merge or push with failing tests — fix failures first (update outdated tests or remove obsolete one-offs; keep generic system coverage).
18
19
1. Merge the feature branch into `master` (fast-forward when possible).
19
20
2. Push `master` to `origin`.
20
21
3. Delete the local (and remote, if it existed) feature branch — it is obsolete after merge.
@@ -15,6 +15,7 @@ alwaysApply: true15
15
16
“Push” / “naar origin” means this sequence:16
“Push” / “naar origin” means this sequence:17
17
18
0. Run the **full** test suite: `npm test`. **Every test must pass.** Do not merge or push with failing tests — fix failures first (update outdated tests or remove obsolete one-offs; keep generic system coverage).18
1. Merge the feature branch into `master` (fast-forward when possible).19
1. Merge the feature branch into `master` (fast-forward when possible).19
2. Push `master` to `origin`.20
2. Push `master` to `origin`.20
3. Delete the local (and remote, if it existed) feature branch — it is obsolete after merge.21
3. Delete the local (and remote, if it existed) feature branch — it is obsolete after merge.@@ -15,6 +15,7 @@ import { SkillId } from "../../shared/definitions/skills.js";
15
15
import { totalXpForLevel } from "../../shared/skills/progression.js";
16
16
import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";
17
17
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
18
import { withDamagingCombatRng, installDamagingCombatRng, installMissDodgeRng, installBlockRng } from "./helpers/combatRng.js";
18
19
19
20
function workerOf (simulation, entityId)
20
21
{
@@ -102,12 +103,7 @@ function runCombatUntilOutcome (harness, playerId, deerId, maxSteps = 600)
102
103
103
104
function withDeterministicCombat (fn)
104
105
{
105
const random = Math.random;
106
Math.random = () => 0;
107
try
108
{ fn(); }
109
finally
110
{ Math.random = random; }
106
withDamagingCombatRng(fn);
111
107
}
112
108
113
109
test("immortal deer auto-attacks until the player dies", () =>
@@ -997,8 +993,7 @@ test("mobs heal to full when their region unloads", () =>
997
993
test("taking damage awards Health XP equal to damage dealt", () =>
998
994
{
999
995
const harness = makeSimulation({ workerCount: 1 });
1000
const random = Math.random;
1001
Math.random = () => 0;
996
const restore = installDamagingCombatRng();
1002
997
try
1003
998
{
1004
999
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -1021,7 +1016,7 @@ test("taking damage awards Health XP equal to damage dealt", () =>
1021
1016
}
1022
1017
finally
1023
1018
{
1024
Math.random = random;
1019
restore();
1025
1020
harness.close();
1026
1021
}
1027
1022
});
@@ -1029,8 +1024,7 @@ test("taking damage awards Health XP equal to damage dealt", () =>
1029
1024
test("lethal damage awards no Health XP", () =>
1030
1025
{
1031
1026
const harness = makeSimulation({ workerCount: 1 });
1032
const random = Math.random;
1033
Math.random = () => 0;
1027
const restore = installDamagingCombatRng();
1034
1028
try
1035
1029
{
1036
1030
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -1057,7 +1051,7 @@ test("lethal damage awards no Health XP", () =>
1057
1051
}
1058
1052
finally
1059
1053
{
1060
Math.random = random;
1054
restore();
1061
1055
harness.close();
1062
1056
}
1063
1057
});
@@ -1065,10 +1059,7 @@ test("lethal damage awards no Health XP", () =>
1065
1059
test("dodging a hit awards Agility XP equal to avoided damage", () =>
1066
1060
{
1067
1061
const harness = makeSimulation({ workerCount: 1 });
1068
let roll = 0;
1069
const seq = [0, 0.5, 0];
1070
const random = Math.random;
1071
Math.random = () => seq[roll++ % seq.length];
1062
const restore = installMissDodgeRng(1);
1072
1063
try
1073
1064
{
1074
1065
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -1092,7 +1083,7 @@ test("dodging a hit awards Agility XP equal to avoided damage", () =>
1092
1083
}
1093
1084
finally
1094
1085
{
1095
Math.random = random;
1086
restore();
1096
1087
harness.close();
1097
1088
}
1098
1089
});
@@ -1100,10 +1091,7 @@ test("dodging a hit awards Agility XP equal to avoided damage", () =>
1100
1091
test("blocking a hit awards Defence XP equal to avoided damage", () =>
1101
1092
{
1102
1093
const harness = makeSimulation({ workerCount: 1 });
1103
let roll = 0;
1104
const seq = [0.9, 0, 0, 0.9];
1105
const random = Math.random;
1106
Math.random = () => seq[roll++ % seq.length];
1094
const restore = installBlockRng(1);
1107
1095
try
1108
1096
{
1109
1097
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -1127,7 +1115,7 @@ test("blocking a hit awards Defence XP equal to avoided damage", () =>
1127
1115
}
1128
1116
finally
1129
1117
{
1130
Math.random = random;
1118
restore();
1131
1119
harness.close();
1132
1120
}
1133
1121
});
@@ -15,6 +15,7 @@ import { SkillId } from "../../shared/definitions/skills.js";15
import { totalXpForLevel } from "../../shared/skills/progression.js";15
import { totalXpForLevel } from "../../shared/skills/progression.js";16
import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";16
import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev } from "../src/combat/service.js";17
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";17
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";18
import { withDamagingCombatRng, installDamagingCombatRng, installMissDodgeRng, installBlockRng } from "./helpers/combatRng.js";18
19
19
function workerOf (simulation, entityId)20
function workerOf (simulation, entityId)20
{21
{@@ -102,12 +103,7 @@ function runCombatUntilOutcome (harness, playerId, deerId, maxSteps = 600)102
103
103
function withDeterministicCombat (fn)104
function withDeterministicCombat (fn)104
{105
{105
const random = Math.random;106
withDamagingCombatRng(fn);106
Math.random = () => 0;107
try108
{ fn(); }109
finally110
{ Math.random = random; }111
}107
}112
108
113
test("immortal deer auto-attacks until the player dies", () =>109
test("immortal deer auto-attacks until the player dies", () =>@@ -997,8 +993,7 @@ test("mobs heal to full when their region unloads", () =>997
test("taking damage awards Health XP equal to damage dealt", () =>993
test("taking damage awards Health XP equal to damage dealt", () =>998
{994
{999
const harness = makeSimulation({ workerCount: 1 });995
const harness = makeSimulation({ workerCount: 1 });1000
const random = Math.random;996
const restore = installDamagingCombatRng();1001
Math.random = () => 0;1002
try997
try1003
{998
{1004
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });999
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -1021,7 +1016,7 @@ test("taking damage awards Health XP equal to damage dealt", () =>1021
}1016
}1022
finally1017
finally1023
{1018
{1024
Math.random = random;1019
restore();1025
harness.close();1020
harness.close();1026
}1021
}1027
});1022
});@@ -1029,8 +1024,7 @@ test("taking damage awards Health XP equal to damage dealt", () =>1029
test("lethal damage awards no Health XP", () =>1024
test("lethal damage awards no Health XP", () =>1030
{1025
{1031
const harness = makeSimulation({ workerCount: 1 });1026
const harness = makeSimulation({ workerCount: 1 });1032
const random = Math.random;1027
const restore = installDamagingCombatRng();1033
Math.random = () => 0;1034
try1028
try1035
{1029
{1036
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });1030
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -1057,7 +1051,7 @@ test("lethal damage awards no Health XP", () =>1057
}1051
}1058
finally1052
finally1059
{1053
{1060
Math.random = random;1054
restore();1061
harness.close();1055
harness.close();1062
}1056
}1063
});1057
});@@ -1065,10 +1059,7 @@ test("lethal damage awards no Health XP", () =>1065
test("dodging a hit awards Agility XP equal to avoided damage", () =>1059
test("dodging a hit awards Agility XP equal to avoided damage", () =>1066
{1060
{1067
const harness = makeSimulation({ workerCount: 1 });1061
const harness = makeSimulation({ workerCount: 1 });1068
let roll = 0;1062
const restore = installMissDodgeRng(1);1069
const seq = [0, 0.5, 0];1070
const random = Math.random;1071
Math.random = () => seq[roll++ % seq.length];1072
try1063
try1073
{1064
{1074
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });1065
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -1092,7 +1083,7 @@ test("dodging a hit awards Agility XP equal to avoided damage", () =>1092
}1083
}1093
finally1084
finally1094
{1085
{1095
Math.random = random;1086
restore();1096
harness.close();1087
harness.close();1097
}1088
}1098
});1089
});@@ -1100,10 +1091,7 @@ test("dodging a hit awards Agility XP equal to avoided damage", () =>1100
test("blocking a hit awards Defence XP equal to avoided damage", () =>1091
test("blocking a hit awards Defence XP equal to avoided damage", () =>1101
{1092
{1102
const harness = makeSimulation({ workerCount: 1 });1093
const harness = makeSimulation({ workerCount: 1 });1103
let roll = 0;1094
const restore = installBlockRng(1);1104
const seq = [0.9, 0, 0, 0.9];1105
const random = Math.random;1106
Math.random = () => seq[roll++ % seq.length];1107
try1095
try1108
{1096
{1109
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });1097
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -1127,7 +1115,7 @@ test("blocking a hit awards Defence XP equal to avoided damage", () =>1127
}1115
}1128
finally1116
finally1129
{1117
{1130
Math.random = random;1118
restore();1131
harness.close();1119
harness.close();1132
}1120
}1133
});1121
});@@ -0,0 +1,45 @@
1
/** Four-roll hit pattern: high hit, low agility, high damage, low defence. */
2
const DAMAGING_PATTERN = Object.freeze([0.99, 0, 0.99, 0]);
3
4
/**
5
* Deterministic Math.random for integration tests: melee hits land with damage.
6
* Matches {@link shared/combat/rolls.js} — damage equals the damage skill roll only.
7
*/
8
export function installDamagingCombatRng ()
9
{
10
const random = Math.random;
11
let i = 0;
12
Math.random = () => DAMAGING_PATTERN[i++ % DAMAGING_PATTERN.length];
13
return () => { Math.random = random; };
14
}
15
16
export function withDamagingCombatRng (fn)
17
{
18
const restore = installDamagingCombatRng();
19
try
20
{ fn(); }
21
finally
22
{ restore(); }
23
}
24
25
/** Miss (agility wins) but attacker rolled non-zero damage for dodge XP. */
26
export function installMissDodgeRng (attackerDamageSkill = 1)
27
{
28
const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99;
29
const pattern = Object.freeze([0, 0.99, damageSample]);
30
let i = 0;
31
const random = Math.random;
32
Math.random = () => pattern[i++ % pattern.length];
33
return () => { Math.random = random; };
34
}
35
36
/** Block after a hit contest; damage roll is non-zero for Defence XP. */
37
export function installBlockRng (attackerDamageSkill = 1)
38
{
39
const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99;
40
const pattern = Object.freeze([0.99, 0, damageSample, 0.99]);
41
let i = 0;
42
const random = Math.random;
43
Math.random = () => pattern[i++ % pattern.length];
44
return () => { Math.random = random; };
45
}
@@ -0,0 +1,45 @@1
/** Four-roll hit pattern: high hit, low agility, high damage, low defence. */2
const DAMAGING_PATTERN = Object.freeze([0.99, 0, 0.99, 0]);3
4
/**5
* Deterministic Math.random for integration tests: melee hits land with damage.6
* Matches {@link shared/combat/rolls.js} — damage equals the damage skill roll only.7
*/8
export function installDamagingCombatRng ()9
{10
const random = Math.random;11
let i = 0;12
Math.random = () => DAMAGING_PATTERN[i++ % DAMAGING_PATTERN.length];13
return () => { Math.random = random; };14
}15
16
export function withDamagingCombatRng (fn)17
{18
const restore = installDamagingCombatRng();19
try20
{ fn(); }21
finally22
{ restore(); }23
}24
25
/** Miss (agility wins) but attacker rolled non-zero damage for dodge XP. */26
export function installMissDodgeRng (attackerDamageSkill = 1)27
{28
const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99;29
const pattern = Object.freeze([0, 0.99, damageSample]);30
let i = 0;31
const random = Math.random;32
Math.random = () => pattern[i++ % pattern.length];33
return () => { Math.random = random; };34
}35
36
/** Block after a hit contest; damage roll is non-zero for Defence XP. */37
export function installBlockRng (attackerDamageSkill = 1)38
{39
const damageSample = attackerDamageSkill <= 1 ? 0.51 : 0.99;40
const pattern = Object.freeze([0.99, 0, damageSample, 0.99]);41
let i = 0;42
const random = Math.random;43
Math.random = () => pattern[i++ % pattern.length];44
return () => { Math.random = random; };45
}@@ -2,6 +2,7 @@ import test from "node:test";
2
2
import assert from "node:assert/strict";
3
3
import { mobCanFight, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";
4
4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";
5
import { SkillId } from "../../shared/definitions/skills.js";
5
6
6
7
test("living targetable mobs can fight except pigeons", () =>
7
8
{
@@ -13,6 +14,16 @@ test("living targetable mobs can fight except pigeons", () =>
13
14
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>
14
15
{
15
16
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
16
assert.equal(profile.mobAttackSkill, 3);
17
assert.equal(profile.mobAttackSkill, 1);
17
18
assert.equal(profile.baseDamage, undefined);
18
19
});
20
21
test("goblins can fight and default to level 5 with slashing melee", () =>
22
{
23
assert.equal(mobCanFight(mobDefinition(MobId.goblin)), true);
24
const profile = mobMeleeAttackProfile(mobDefinition(MobId.goblin), 5);
25
assert.equal(profile.mobAttackSkill, 5);
26
assert.equal(profile.mode, "melee");
27
assert.equal(profile.attackType, "slashing");
28
assert.equal(profile.hitSkillId, SkillId.swordfighting);
29
});
@@ -2,6 +2,7 @@ import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { mobCanFight, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";3
import { mobCanFight, mobMeleeAttackProfile } from "../../shared/definitions/mobCombat.js";4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";4
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";5
import { SkillId } from "../../shared/definitions/skills.js";5
6
6
test("living targetable mobs can fight except pigeons", () =>7
test("living targetable mobs can fight except pigeons", () =>7
{8
{@@ -13,6 +14,16 @@ test("living targetable mobs can fight except pigeons", () =>13
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>14
test("mob attack profile uses one attackSkill for hit and damage rolls", () =>14
{15
{15
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));16
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));16
assert.equal(profile.mobAttackSkill, 3);17
assert.equal(profile.mobAttackSkill, 1);17
assert.equal(profile.baseDamage, undefined);18
assert.equal(profile.baseDamage, undefined);18
});19
});20
21
test("goblins can fight and default to level 5 with slashing melee", () =>22
{23
assert.equal(mobCanFight(mobDefinition(MobId.goblin)), true);24
const profile = mobMeleeAttackProfile(mobDefinition(MobId.goblin), 5);25
assert.equal(profile.mobAttackSkill, 5);26
assert.equal(profile.mode, "melee");27
assert.equal(profile.attackType, "slashing");28
assert.equal(profile.hitSkillId, SkillId.swordfighting);29
});@@ -24,6 +24,7 @@ import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";
24
24
import { mobComponents } from "../src/simulation/spawners.js";
25
25
import { MobId } from "../../shared/definitions/mobs.js";
26
26
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
27
import { installDamagingCombatRng } from "./helpers/combatRng.js";
27
28
28
29
test("enforceMinimumSkillLevels raises Health to 10 and leaves higher XP alone", () =>
29
30
{
@@ -180,8 +181,7 @@ test("combat xp equals damage dealt to hit and damage skills", () =>
180
181
test("successful player melee hits award xp equal to damage", () =>
181
182
{
182
183
const harness = makeSimulation({ workerCount: 1 });
183
const random = Math.random;
184
Math.random = () => 0;
184
const restore = installDamagingCombatRng();
185
185
try
186
186
{
187
187
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -204,7 +204,7 @@ test("successful player melee hits award xp equal to damage", () =>
204
204
}
205
205
finally
206
206
{
207
Math.random = random;
207
restore();
208
208
harness.close();
209
209
}
210
210
});
@@ -24,6 +24,7 @@ import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";24
import { mobComponents } from "../src/simulation/spawners.js";24
import { mobComponents } from "../src/simulation/spawners.js";25
import { MobId } from "../../shared/definitions/mobs.js";25
import { MobId } from "../../shared/definitions/mobs.js";26
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";26
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";27
import { installDamagingCombatRng } from "./helpers/combatRng.js";27
28
28
test("enforceMinimumSkillLevels raises Health to 10 and leaves higher XP alone", () =>29
test("enforceMinimumSkillLevels raises Health to 10 and leaves higher XP alone", () =>29
{30
{@@ -180,8 +181,7 @@ test("combat xp equals damage dealt to hit and damage skills", () =>180
test("successful player melee hits award xp equal to damage", () =>181
test("successful player melee hits award xp equal to damage", () =>181
{182
{182
const harness = makeSimulation({ workerCount: 1 });183
const harness = makeSimulation({ workerCount: 1 });183
const random = Math.random;184
const restore = installDamagingCombatRng();184
Math.random = () => 0;185
try185
try186
{186
{187
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });187
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -204,7 +204,7 @@ test("successful player melee hits award xp equal to damage", () =>204
}204
}205
finally205
finally206
{206
{207
Math.random = random;207
restore();208
harness.close();208
harness.close();209
}209
}210
});210
});@@ -15,6 +15,8 @@ import { mobComponents } from "../src/simulation/spawners.js";
15
15
import { Component } from "../src/ecs/components.js";
16
16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
17
17
import { ItemId } from "../../shared/definitions/items.js";
18
import { attackProfileOf } from "../src/combat/service.js";
19
import { installDamagingCombatRng } from "./helpers/combatRng.js";
18
20
19
21
test("spawner config defaults bounty 0 and level 1", () =>
20
22
{
@@ -36,6 +38,37 @@ test("town guard spawner defaults level, bounty, and equipment", () =>
36
38
assert.equal(config.equipment.weapon, 245);
37
39
});
38
40
41
test("goblin spawner defaults level 5 without equipment", () =>
42
{
43
const config = normalizeSpawnerConfig({ mobTypeId: MobId.goblin }, "goblin-1");
44
assert.equal(config.level, 5);
45
assert.equal(config.bounty, 0);
46
assert.equal(config.equipment.weapon, null);
47
});
48
49
test("goblin spawns with slashing melee profile from mob definition", () =>
50
{
51
const harness = makeSimulation({ workerCount: 1 });
52
try
53
{
54
const config = normalizeSpawnerConfig({ mobTypeId: MobId.goblin }, "goblin-1");
55
const goblinId = harness.simulation.spawnEntity(mobComponents({
56
mobTypeId: MobId.goblin,
57
tileX: 8,
58
tileY: 8,
59
level: config.level
60
}));
61
const worker = harness.simulation.workers[0];
62
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(goblinId));
63
assert.equal(profile.mode, "melee");
64
assert.equal(profile.attackType, "slashing");
65
assert.equal(profile.hitSkillId, SkillId.swordfighting);
66
assert.equal(profile.mobAttackSkill, 5);
67
}
68
finally
69
{ harness.close(); }
70
});
71
39
72
test("humanoid spawners do not buy from players by default", () =>
40
73
{
41
74
const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");
@@ -168,8 +201,7 @@ test("aggressive humanoid stores aggro flag and zero bounty", () =>
168
201
test("killing a bounty mob awards player bounty and can wake town guards", () =>
169
202
{
170
203
const harness = makeSimulation({ workerCount: 1 });
171
const random = Math.random;
172
Math.random = () => 0;
204
const restore = installDamagingCombatRng();
173
205
try
174
206
{
175
207
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
@@ -229,7 +261,7 @@ test("killing a bounty mob awards player bounty and can wake town guards", () =>
229
261
}
230
262
finally
231
263
{
232
Math.random = random;
264
restore();
233
265
harness.close();
234
266
}
235
267
});
@@ -15,6 +15,8 @@ import { mobComponents } from "../src/simulation/spawners.js";15
import { Component } from "../src/ecs/components.js";15
import { Component } from "../src/ecs/components.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";16
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";17
import { ItemId } from "../../shared/definitions/items.js";17
import { ItemId } from "../../shared/definitions/items.js";18
import { attackProfileOf } from "../src/combat/service.js";19
import { installDamagingCombatRng } from "./helpers/combatRng.js";18
20
19
test("spawner config defaults bounty 0 and level 1", () =>21
test("spawner config defaults bounty 0 and level 1", () =>20
{22
{@@ -36,6 +38,37 @@ test("town guard spawner defaults level, bounty, and equipment", () =>36
assert.equal(config.equipment.weapon, 245);38
assert.equal(config.equipment.weapon, 245);37
});39
});38
40
41
test("goblin spawner defaults level 5 without equipment", () =>42
{43
const config = normalizeSpawnerConfig({ mobTypeId: MobId.goblin }, "goblin-1");44
assert.equal(config.level, 5);45
assert.equal(config.bounty, 0);46
assert.equal(config.equipment.weapon, null);47
});48
49
test("goblin spawns with slashing melee profile from mob definition", () =>50
{51
const harness = makeSimulation({ workerCount: 1 });52
try53
{54
const config = normalizeSpawnerConfig({ mobTypeId: MobId.goblin }, "goblin-1");55
const goblinId = harness.simulation.spawnEntity(mobComponents({56
mobTypeId: MobId.goblin,57
tileX: 8,58
tileY: 8,59
level: config.level60
}));61
const worker = harness.simulation.workers[0];62
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(goblinId));63
assert.equal(profile.mode, "melee");64
assert.equal(profile.attackType, "slashing");65
assert.equal(profile.hitSkillId, SkillId.swordfighting);66
assert.equal(profile.mobAttackSkill, 5);67
}68
finally69
{ harness.close(); }70
});71
39
test("humanoid spawners do not buy from players by default", () =>72
test("humanoid spawners do not buy from players by default", () =>40
{73
{41
const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");74
const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");@@ -168,8 +201,7 @@ test("aggressive humanoid stores aggro flag and zero bounty", () =>168
test("killing a bounty mob awards player bounty and can wake town guards", () =>201
test("killing a bounty mob awards player bounty and can wake town guards", () =>169
{202
{170
const harness = makeSimulation({ workerCount: 1 });203
const harness = makeSimulation({ workerCount: 1 });171
const random = Math.random;204
const restore = installDamagingCombatRng();172
Math.random = () => 0;173
try205
try174
{206
{175
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });207
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });@@ -229,7 +261,7 @@ test("killing a bounty mob awards player bounty and can wake town guards", () =>229
}261
}230
finally262
finally231
{263
{232
Math.random = random;264
restore();233
harness.close();265
harness.close();234
}266
}235
});267
});