Split Agility from Dexterity and award avoidance combat XP.
Evasion contests use Agility; Dexterity stays ranged damage. Blocking and dodging grant Defence and Agility XP equal to avoided damage. Leather armour bonuses map to Agility.
@@ -0,0 +1 @@
1
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#50a080"/><text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">AG</text></svg>
@@ -0,0 +1 @@1
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#50a080"/><text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">AG</text></svg>@@ -10,6 +10,7 @@ const labels = {
10
10
magic: "MG",
11
11
strength: "ST",
12
12
dexterity: "DX",
13
agility: "AG",
13
14
mind: "MN",
14
15
defence: "DF",
15
16
health: "HP",
@@ -35,6 +36,7 @@ const colors = {
35
36
magic: "#6050a0",
36
37
strength: "#a04040",
37
38
dexterity: "#4080a0",
39
agility: "#50a080",
38
40
mind: "#8060a0",
39
41
defence: "#506080",
40
42
health: "#a03030",
@@ -10,6 +10,7 @@ const labels = {10
magic: "MG",10
magic: "MG",11
strength: "ST",11
strength: "ST",12
dexterity: "DX",12
dexterity: "DX",13
agility: "AG",13
mind: "MN",14
mind: "MN",14
defence: "DF",15
defence: "DF",15
health: "HP",16
health: "HP",@@ -35,6 +36,7 @@ const colors = {35
magic: "#6050a0",36
magic: "#6050a0",36
strength: "#a04040",37
strength: "#a04040",37
dexterity: "#4080a0",38
dexterity: "#4080a0",39
agility: "#50a080",38
mind: "#8060a0",40
mind: "#8060a0",39
defence: "#506080",41
defence: "#506080",40
health: "#a03030",42
health: "#a03030",@@ -25,7 +25,7 @@ import {
25
25
equipmentBonusesFromSlots
26
26
} from "../../../shared/equipment/stats.js";
27
27
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
28
import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
28
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
29
29
import { chunkBoundsAround, findPath } from "../navigation/astar.js";
30
30
import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
31
31
import { rayReaches } from "../../../shared/lighting/raycast.js";
@@ -100,7 +100,7 @@ function playerCombatLevels (ecs, handle, profile)
100
100
return {
101
101
hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),
102
102
damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),
103
agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
103
agilityLevel: effectiveSkillLevel(skills, SkillId.agility, bonuses),
104
104
defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
105
105
};
106
106
}
@@ -361,7 +361,7 @@ function attackerCombatLevels (ecs, attackerHandle, profile)
361
361
return {
362
362
hitLevel: attackerSkillLevel(skills, profile, profile.hitSkillId),
363
363
damageLevel: attackerSkillLevel(skills, profile, profile.damageSkillId),
364
agilityLevel: skillLevel(skills, SkillId.dexterity),
364
agilityLevel: skillLevel(skills, SkillId.agility),
365
365
defenceLevel: skillLevel(skills, SkillId.defence)
366
366
};
367
367
}
@@ -933,7 +933,7 @@ function applyLocalMeleeHit (
933
933
934
934
const agilityLevel = defenderSkillLevel(
935
935
defenderSkills,
936
SkillId.dexterity,
936
SkillId.agility,
937
937
defenderEquipment
938
938
);
939
939
const defenceLevel = defenderSkillLevel(
@@ -961,6 +961,23 @@ function applyLocalMeleeHit (
961
961
tileX: to.tileX,
962
962
tileY: to.tileY
963
963
});
964
const dodgeXp = awardCombatAvoidanceXp(
965
world.ecs,
966
targetHandle,
967
SkillId.agility,
968
resolved.damageRoll
969
);
970
if (dodgeXp)
971
{
972
events.push({
973
type: "skills-updated",
974
entityId: targetId,
975
characterId: dodgeXp.characterId,
976
skills: dodgeXp.view,
977
stored: dodgeXp.stored,
978
levelUps: dodgeXp.levelUps ?? []
979
});
980
}
964
981
return events;
965
982
}
966
983
@@ -973,6 +990,23 @@ function applyLocalMeleeHit (
973
990
tileX: to.tileX,
974
991
tileY: to.tileY
975
992
});
993
const blockXp = awardCombatAvoidanceXp(
994
world.ecs,
995
targetHandle,
996
SkillId.defence,
997
resolved.damageRoll
998
);
999
if (blockXp)
1000
{
1001
events.push({
1002
type: "skills-updated",
1003
entityId: targetId,
1004
characterId: blockXp.characterId,
1005
skills: blockXp.view,
1006
stored: blockXp.stored,
1007
levelUps: blockXp.levelUps ?? []
1008
});
1009
}
976
1010
return events;
977
1011
}
978
1012
@@ -25,7 +25,7 @@ import {25
equipmentBonusesFromSlots25
equipmentBonusesFromSlots26
} from "../../../shared/equipment/stats.js";26
} from "../../../shared/equipment/stats.js";27
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";27
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";28
import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";28
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";29
import { chunkBoundsAround, findPath } from "../navigation/astar.js";29
import { chunkBoundsAround, findPath } from "../navigation/astar.js";30
import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";30
import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";31
import { rayReaches } from "../../../shared/lighting/raycast.js";31
import { rayReaches } from "../../../shared/lighting/raycast.js";@@ -100,7 +100,7 @@ function playerCombatLevels (ecs, handle, profile)100
return {100
return {101
hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),101
hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),102
damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),102
damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),103
agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),103
agilityLevel: effectiveSkillLevel(skills, SkillId.agility, bonuses),104
defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)104
defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)105
};105
};106
}106
}@@ -361,7 +361,7 @@ function attackerCombatLevels (ecs, attackerHandle, profile)361
return {361
return {362
hitLevel: attackerSkillLevel(skills, profile, profile.hitSkillId),362
hitLevel: attackerSkillLevel(skills, profile, profile.hitSkillId),363
damageLevel: attackerSkillLevel(skills, profile, profile.damageSkillId),363
damageLevel: attackerSkillLevel(skills, profile, profile.damageSkillId),364
agilityLevel: skillLevel(skills, SkillId.dexterity),364
agilityLevel: skillLevel(skills, SkillId.agility),365
defenceLevel: skillLevel(skills, SkillId.defence)365
defenceLevel: skillLevel(skills, SkillId.defence)366
};366
};367
}367
}@@ -933,7 +933,7 @@ function applyLocalMeleeHit (933
933
934
const agilityLevel = defenderSkillLevel(934
const agilityLevel = defenderSkillLevel(935
defenderSkills,935
defenderSkills,936
SkillId.dexterity,936
SkillId.agility,937
defenderEquipment937
defenderEquipment938
);938
);939
const defenceLevel = defenderSkillLevel(939
const defenceLevel = defenderSkillLevel(@@ -961,6 +961,23 @@ function applyLocalMeleeHit (961
tileX: to.tileX,961
tileX: to.tileX,962
tileY: to.tileY962
tileY: to.tileY963
});963
});964
const dodgeXp = awardCombatAvoidanceXp(965
world.ecs,966
targetHandle,967
SkillId.agility,968
resolved.damageRoll969
);970
if (dodgeXp)971
{972
events.push({973
type: "skills-updated",974
entityId: targetId,975
characterId: dodgeXp.characterId,976
skills: dodgeXp.view,977
stored: dodgeXp.stored,978
levelUps: dodgeXp.levelUps ?? []979
});980
}964
return events;981
return events;965
}982
}966
983
@@ -973,6 +990,23 @@ function applyLocalMeleeHit (973
tileX: to.tileX,990
tileX: to.tileX,974
tileY: to.tileY991
tileY: to.tileY975
});992
});993
const blockXp = awardCombatAvoidanceXp(994
world.ecs,995
targetHandle,996
SkillId.defence,997
resolved.damageRoll998
);999
if (blockXp)1000
{1001
events.push({1002
type: "skills-updated",1003
entityId: targetId,1004
characterId: blockXp.characterId,1005
skills: blockXp.view,1006
stored: blockXp.stored,1007
levelUps: blockXp.levelUps ?? []1008
});1009
}976
return events;1010
return events;977
}1011
}978
1012
@@ -96,3 +96,26 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)
96
96
levelUps: result.levelUp ? [result.levelUp] : []
97
97
};
98
98
}
99
100
/** XP for avoiding damage — Defence on block, Agility on dodge (players only). */
101
export function awardCombatAvoidanceXp (ecs, targetHandle, skillId, avoidedDamage)
102
{
103
const amount = combatDamageXp(avoidedDamage);
104
if (!amount)
105
{ return null; }
106
const character = ecs.get(targetHandle, Component.character);
107
if (!character)
108
{ return null; }
109
const skills = ecs.get(targetHandle, Component.skills);
110
if (!skills?.xp)
111
{ return null; }
112
const result = applySkillXp(skills, skillId, amount);
113
if (!result.changed)
114
{ return null; }
115
return {
116
characterId: character.characterId,
117
view: publicSkillsView(skills),
118
stored: storedSkillXp(skills),
119
levelUps: result.levelUp ? [result.levelUp] : []
120
};
121
}
@@ -96,3 +96,26 @@ export function awardDamageHealthXp (ecs, targetHandle, damage)96
levelUps: result.levelUp ? [result.levelUp] : []96
levelUps: result.levelUp ? [result.levelUp] : []97
};97
};98
}98
}99
100
/** XP for avoiding damage — Defence on block, Agility on dodge (players only). */101
export function awardCombatAvoidanceXp (ecs, targetHandle, skillId, avoidedDamage)102
{103
const amount = combatDamageXp(avoidedDamage);104
if (!amount)105
{ return null; }106
const character = ecs.get(targetHandle, Component.character);107
if (!character)108
{ return null; }109
const skills = ecs.get(targetHandle, Component.skills);110
if (!skills?.xp)111
{ return null; }112
const result = applySkillXp(skills, skillId, amount);113
if (!result.changed)114
{ return null; }115
return {116
characterId: character.characterId,117
view: publicSkillsView(skills),118
stored: storedSkillXp(skills),119
levelUps: result.levelUp ? [result.levelUp] : []120
};121
}@@ -9,6 +9,7 @@ import { tileKey } from "../src/world/coordinates.js";
9
9
import { WorkerMessage } from "../src/simulation/protocol.js";
10
10
import { tileToRegion } from "../src/world/coordinates.js";
11
11
import { SkillId } from "../../shared/definitions/skills.js";
12
import { totalXpForLevel } from "../../shared/skills/progression.js";
12
13
import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";
13
14
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
14
15
@@ -877,3 +878,73 @@ test("taking damage awards Health XP equal to damage dealt", () =>
877
878
harness.close();
878
879
}
879
880
});
881
882
test("dodging a hit awards Agility XP equal to avoided damage", () =>
883
{
884
const harness = makeSimulation({ workerCount: 1 });
885
let roll = 0;
886
const seq = [0, 0.5, 0];
887
const random = Math.random;
888
Math.random = () => seq[roll++ % seq.length];
889
try
890
{
891
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
892
const playerId = harness.simulation.spawnCharacter(1, character);
893
const ratId = harness.simulation.spawnEntity(mobComponents({
894
mobTypeId: MobId.rat,
895
tileX: 9,
896
tileY: 8
897
}));
898
const worker = harness.simulation.workers[0];
899
const playerHandle = worker.world.ecs.handleOf(playerId);
900
const skills = worker.world.ecs.get(playerHandle, Component.skills);
901
skills.xp[SkillId.agility] = totalXpForLevel(10);
902
const before = skills.xp[SkillId.agility] | 0;
903
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(ratId));
904
const events = resolveMeleeSwing(worker.world, ratId, playerId, profile, Date.now());
905
assert.ok(events.find((event) => event.type === "combat-miss"));
906
const updated = events.find((event) => event.type === "skills-updated" && event.entityId === playerId);
907
assert.ok(updated);
908
assert.equal(updated.stored[SkillId.agility] - before, 1);
909
}
910
finally
911
{
912
Math.random = random;
913
harness.close();
914
}
915
});
916
917
test("blocking a hit awards Defence XP equal to avoided damage", () =>
918
{
919
const harness = makeSimulation({ workerCount: 1 });
920
let roll = 0;
921
const seq = [0.9, 0, 0, 0.9];
922
const random = Math.random;
923
Math.random = () => seq[roll++ % seq.length];
924
try
925
{
926
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
927
const playerId = harness.simulation.spawnCharacter(1, character);
928
const ratId = harness.simulation.spawnEntity(mobComponents({
929
mobTypeId: MobId.rat,
930
tileX: 9,
931
tileY: 8
932
}));
933
const worker = harness.simulation.workers[0];
934
const playerHandle = worker.world.ecs.handleOf(playerId);
935
const skills = worker.world.ecs.get(playerHandle, Component.skills);
936
skills.xp[SkillId.defence] = totalXpForLevel(10);
937
const before = skills.xp[SkillId.defence] | 0;
938
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(ratId));
939
const events = resolveMeleeSwing(worker.world, ratId, playerId, profile, Date.now());
940
assert.ok(events.find((event) => event.type === "combat-block"));
941
const updated = events.find((event) => event.type === "skills-updated" && event.entityId === playerId);
942
assert.ok(updated);
943
assert.equal(updated.stored[SkillId.defence] - before, 1);
944
}
945
finally
946
{
947
Math.random = random;
948
harness.close();
949
}
950
});
@@ -9,6 +9,7 @@ import { tileKey } from "../src/world/coordinates.js";9
import { WorkerMessage } from "../src/simulation/protocol.js";9
import { WorkerMessage } from "../src/simulation/protocol.js";10
import { tileToRegion } from "../src/world/coordinates.js";10
import { tileToRegion } from "../src/world/coordinates.js";11
import { SkillId } from "../../shared/definitions/skills.js";11
import { SkillId } from "../../shared/definitions/skills.js";12
import { totalXpForLevel } from "../../shared/skills/progression.js";12
import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";13
import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";13
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";14
import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";14
15
@@ -877,3 +878,73 @@ test("taking damage awards Health XP equal to damage dealt", () =>877
harness.close();878
harness.close();878
}879
}879
});880
});881
882
test("dodging a hit awards Agility XP equal to avoided damage", () =>883
{884
const harness = makeSimulation({ workerCount: 1 });885
let roll = 0;886
const seq = [0, 0.5, 0];887
const random = Math.random;888
Math.random = () => seq[roll++ % seq.length];889
try890
{891
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });892
const playerId = harness.simulation.spawnCharacter(1, character);893
const ratId = harness.simulation.spawnEntity(mobComponents({894
mobTypeId: MobId.rat,895
tileX: 9,896
tileY: 8897
}));898
const worker = harness.simulation.workers[0];899
const playerHandle = worker.world.ecs.handleOf(playerId);900
const skills = worker.world.ecs.get(playerHandle, Component.skills);901
skills.xp[SkillId.agility] = totalXpForLevel(10);902
const before = skills.xp[SkillId.agility] | 0;903
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(ratId));904
const events = resolveMeleeSwing(worker.world, ratId, playerId, profile, Date.now());905
assert.ok(events.find((event) => event.type === "combat-miss"));906
const updated = events.find((event) => event.type === "skills-updated" && event.entityId === playerId);907
assert.ok(updated);908
assert.equal(updated.stored[SkillId.agility] - before, 1);909
}910
finally911
{912
Math.random = random;913
harness.close();914
}915
});916
917
test("blocking a hit awards Defence XP equal to avoided damage", () =>918
{919
const harness = makeSimulation({ workerCount: 1 });920
let roll = 0;921
const seq = [0.9, 0, 0, 0.9];922
const random = Math.random;923
Math.random = () => seq[roll++ % seq.length];924
try925
{926
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });927
const playerId = harness.simulation.spawnCharacter(1, character);928
const ratId = harness.simulation.spawnEntity(mobComponents({929
mobTypeId: MobId.rat,930
tileX: 9,931
tileY: 8932
}));933
const worker = harness.simulation.workers[0];934
const playerHandle = worker.world.ecs.handleOf(playerId);935
const skills = worker.world.ecs.get(playerHandle, Component.skills);936
skills.xp[SkillId.defence] = totalXpForLevel(10);937
const before = skills.xp[SkillId.defence] | 0;938
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(ratId));939
const events = resolveMeleeSwing(worker.world, ratId, playerId, profile, Date.now());940
assert.ok(events.find((event) => event.type === "combat-block"));941
const updated = events.find((event) => event.type === "skills-updated" && event.entityId === playerId);942
assert.ok(updated);943
assert.equal(updated.stored[SkillId.defence] - before, 1);944
}945
finally946
{947
Math.random = random;948
harness.close();949
}950
});@@ -26,7 +26,7 @@ test("deterministic rng produces stable rolls", () =>
26
26
test("physical attack miss when agility roll beats hit roll", () =>
27
27
{
28
28
let i = 0;
29
const rng = () => [0.25, 0.45][i++];
29
const rng = () => [0.25, 0.45, 0][i++];
30
30
const result = resolvePhysicalAttack({
31
31
hitSkillLevel: 5,
32
32
agilitySkillLevel: 10,
@@ -37,6 +37,7 @@ test("physical attack miss when agility roll beats hit roll", () =>
37
37
assert.equal(result.outcome, "miss");
38
38
assert.equal(result.toHitRoll, 2);
39
39
assert.equal(result.agilityRoll, 5);
40
assert.equal(result.damageRoll, 1);
40
41
assert.equal(result.damage, 0);
41
42
});
42
43
@@ -26,7 +26,7 @@ test("deterministic rng produces stable rolls", () =>26
test("physical attack miss when agility roll beats hit roll", () =>26
test("physical attack miss when agility roll beats hit roll", () =>27
{27
{28
let i = 0;28
let i = 0;29
const rng = () => [0.25, 0.45][i++];29
const rng = () => [0.25, 0.45, 0][i++];30
const result = resolvePhysicalAttack({30
const result = resolvePhysicalAttack({31
hitSkillLevel: 5,31
hitSkillLevel: 5,32
agilitySkillLevel: 10,32
agilitySkillLevel: 10,@@ -37,6 +37,7 @@ test("physical attack miss when agility roll beats hit roll", () =>37
assert.equal(result.outcome, "miss");37
assert.equal(result.outcome, "miss");38
assert.equal(result.toHitRoll, 2);38
assert.equal(result.toHitRoll, 2);39
assert.equal(result.agilityRoll, 5);39
assert.equal(result.agilityRoll, 5);40
assert.equal(result.damageRoll, 1);40
assert.equal(result.damage, 0);41
assert.equal(result.damage, 0);41
});42
});42
43