BlueGit

timfa questward

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.

timfa Tim Falken · pushed by timfa

Authored 2026-08-26 · 2 months ago

Hash
3cb73567daea2b1f895f693dbad8671cf3f9951a
Parent
42cbd8a1
11 files changed +148 −11
client/assets/skills/agility.svg added +1 −0
@@ -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>
client/scripts/generate-skill-icons.mjs +2 −0
@@ -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",
server/src/combat/service.js +38 −4
@@ -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 equipmentBonusesFromSlots
25 equipmentBonusesFromSlots
26} from "../../../shared/equipment/stats.js";
26} from "../../../shared/equipment/stats.js";
27import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
27import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
28import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
28import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
29import { chunkBoundsAround, findPath } from "../navigation/astar.js";
29import { chunkBoundsAround, findPath } from "../navigation/astar.js";
30import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
30import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
31import { rayReaches } from "../../../shared/lighting/raycast.js";
31import { 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 defenderEquipment
937 defenderEquipment
938 );
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.tileY
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 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.tileY
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 return events;
1010 return events;
977 }
1011 }
978
1012
server/src/skills/service.js +23 −0
@@ -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). */
101export 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}
server/tests/combat.test.js +71 −0
@@ -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";
9import { WorkerMessage } from "../src/simulation/protocol.js";
9import { WorkerMessage } from "../src/simulation/protocol.js";
10import { tileToRegion } from "../src/world/coordinates.js";
10import { tileToRegion } from "../src/world/coordinates.js";
11import { SkillId } from "../../shared/definitions/skills.js";
11import { SkillId } from "../../shared/definitions/skills.js";
12import { totalXpForLevel } from "../../shared/skills/progression.js";
12import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";
13import { resolveMeleeSwing, attackProfileOf } from "../src/combat/service.js";
13import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
14import { 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
882test("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
917test("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});
server/tests/combatRolls.test.js +2 −1
@@ -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", () =>
26test("physical attack miss when agility roll beats hit roll", () =>
26test("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
shared/combat/magic.js +1 −1
@@ -21,7 +21,7 @@ export const ElementMultiplier = Object.freeze({
21 21 /**
22 22 * Whether the caster successfully channels the spell.
23 23 * Magic roll vs a difficulty roll sized by spell.difficulty.
24 * Succeeds on tie or higher (same rule as physical hit vs agility).
24 * Succeeds on tie or higher (same rule as physical hit vs Agility).
25 25 */
26 26 export function resolveSpellCast ({
27 27 magicSkillLevel,
@@ -21,7 +21,7 @@ export const ElementMultiplier = Object.freeze({
21/**
21/**
22 * Whether the caster successfully channels the spell.
22 * Whether the caster successfully channels the spell.
23 * Magic roll vs a difficulty roll sized by spell.difficulty.
23 * Magic roll vs a difficulty roll sized by spell.difficulty.
24 * Succeeds on tie or higher (same rule as physical hit vs agility).
24 * Succeeds on tie or higher (same rule as physical hit vs Agility).
25 */
25 */
26export function resolveSpellCast ({
26export function resolveSpellCast ({
27 magicSkillLevel,
27 magicSkillLevel,
shared/combat/rolls.js +4 −3
@@ -7,8 +7,8 @@ export function rollSkill (skillLevel, rng = Math.random)
7 7
8 8 /**
9 9 * Melee and ranged physical attack resolution (shared rules).
10 * 1. Roll hit skill vs defender agility (Dexterity) — miss if toHitRoll < agilityRoll
11 * 2. On hit: roll damage skill (Strength/Dexterity) for damage
10 * 1. Roll hit skill vs defender Agility — miss if toHitRoll < agilityRoll
11 * 2. Always roll attacker damage skill (for dodge XP even on miss)
12 12 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
13 13 * 4. On hit and not blocked: apply rolled damage
14 14 */
@@ -22,18 +22,19 @@ export function resolvePhysicalAttack ({
22 22 {
23 23 const toHitRoll = rollSkill(hitSkillLevel, rng);
24 24 const agilityRoll = rollSkill(agilitySkillLevel, rng);
25 const damageRoll = rollSkill(damageSkillLevel, rng);
25 26 if (toHitRoll < agilityRoll)
26 27 {
27 28 return {
28 29 outcome: "miss",
29 30 toHitRoll,
30 31 agilityRoll,
32 damageRoll,
31 33 damage: 0,
32 34 blocked: false
33 35 };
34 36 }
35 37
36 const damageRoll = rollSkill(damageSkillLevel, rng);
37 38 const damage = damageRoll;
38 39 const defenceRoll = rollSkill(defenceSkillLevel, rng);
39 40 if (defenceRoll > toHitRoll)
@@ -7,8 +7,8 @@ export function rollSkill (skillLevel, rng = Math.random)
7
7
8/**
8/**
9 * Melee and ranged physical attack resolution (shared rules).
9 * Melee and ranged physical attack resolution (shared rules).
10 * 1. Roll hit skill vs defender agility (Dexterity) — miss if toHitRoll < agilityRoll
10 * 1. Roll hit skill vs defender Agility — miss if toHitRoll < agilityRoll
11 * 2. On hit: roll damage skill (Strength/Dexterity) for damage
11 * 2. Always roll attacker damage skill (for dodge XP even on miss)
12 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
12 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
13 * 4. On hit and not blocked: apply rolled damage
13 * 4. On hit and not blocked: apply rolled damage
14 */
14 */
@@ -22,18 +22,19 @@ export function resolvePhysicalAttack ({
22{
22{
23 const toHitRoll = rollSkill(hitSkillLevel, rng);
23 const toHitRoll = rollSkill(hitSkillLevel, rng);
24 const agilityRoll = rollSkill(agilitySkillLevel, rng);
24 const agilityRoll = rollSkill(agilitySkillLevel, rng);
25 const damageRoll = rollSkill(damageSkillLevel, rng);
25 if (toHitRoll < agilityRoll)
26 if (toHitRoll < agilityRoll)
26 {
27 {
27 return {
28 return {
28 outcome: "miss",
29 outcome: "miss",
29 toHitRoll,
30 toHitRoll,
30 agilityRoll,
31 agilityRoll,
32 damageRoll,
31 damage: 0,
33 damage: 0,
32 blocked: false
34 blocked: false
33 };
35 };
34 }
36 }
35
37
36 const damageRoll = rollSkill(damageSkillLevel, rng);
37 const damage = damageRoll;
38 const damage = damageRoll;
38 const defenceRoll = rollSkill(defenceSkillLevel, rng);
39 const defenceRoll = rollSkill(defenceSkillLevel, rng);
39 if (defenceRoll > toHitRoll)
40 if (defenceRoll > toHitRoll)
shared/definitions/mobCombat.js +1 −1
@@ -64,7 +64,7 @@ export function mobSkillLevels (def)
64 64 const defenceSkill = Math.max(1, def?.defenceSkill ?? attackSkill);
65 65 return {
66 66 [SkillId.unarmed]: attackSkill,
67 [SkillId.dexterity]: agilitySkill,
67 [SkillId.agility]: agilitySkill,
68 68 [SkillId.defence]: defenceSkill
69 69 };
70 70 }
@@ -64,7 +64,7 @@ export function mobSkillLevels (def)
64 const defenceSkill = Math.max(1, def?.defenceSkill ?? attackSkill);
64 const defenceSkill = Math.max(1, def?.defenceSkill ?? attackSkill);
65 return {
65 return {
66 [SkillId.unarmed]: attackSkill,
66 [SkillId.unarmed]: attackSkill,
67 [SkillId.dexterity]: agilitySkill,
67 [SkillId.agility]: agilitySkill,
68 [SkillId.defence]: defenceSkill
68 [SkillId.defence]: defenceSkill
69 };
69 };
70}
70}
shared/definitions/skills.js +3 −0
@@ -7,6 +7,7 @@ export const SkillId = Object.freeze({
7 7 magic: "magic",
8 8 strength: "strength",
9 9 dexterity: "dexterity",
10 agility: "agility",
10 11 mind: "mind",
11 12 defence: "defence",
12 13 health: "health",
@@ -33,6 +34,7 @@ export const ALL_SKILL_IDS = Object.freeze([
33 34 SkillId.magic,
34 35 SkillId.strength,
35 36 SkillId.dexterity,
37 SkillId.agility,
36 38 SkillId.mind,
37 39 SkillId.defence,
38 40 SkillId.health,
@@ -58,6 +60,7 @@ export const SKILL_DEFINITIONS = Object.freeze({
58 60 [SkillId.magic]: Object.freeze({ skillId: SkillId.magic, displayName: "Magic" }),
59 61 [SkillId.strength]: Object.freeze({ skillId: SkillId.strength, displayName: "Strength" }),
60 62 [SkillId.dexterity]: Object.freeze({ skillId: SkillId.dexterity, displayName: "Dexterity" }),
63 [SkillId.agility]: Object.freeze({ skillId: SkillId.agility, displayName: "Agility" }),
61 64 [SkillId.mind]: Object.freeze({ skillId: SkillId.mind, displayName: "Mind" }),
62 65 [SkillId.defence]: Object.freeze({ skillId: SkillId.defence, displayName: "Defence" }),
63 66 [SkillId.health]: Object.freeze({ skillId: SkillId.health, displayName: "Health" }),
@@ -7,6 +7,7 @@ export const SkillId = Object.freeze({
7 magic: "magic",
7 magic: "magic",
8 strength: "strength",
8 strength: "strength",
9 dexterity: "dexterity",
9 dexterity: "dexterity",
10 agility: "agility",
10 mind: "mind",
11 mind: "mind",
11 defence: "defence",
12 defence: "defence",
12 health: "health",
13 health: "health",
@@ -33,6 +34,7 @@ export const ALL_SKILL_IDS = Object.freeze([
33 SkillId.magic,
34 SkillId.magic,
34 SkillId.strength,
35 SkillId.strength,
35 SkillId.dexterity,
36 SkillId.dexterity,
37 SkillId.agility,
36 SkillId.mind,
38 SkillId.mind,
37 SkillId.defence,
39 SkillId.defence,
38 SkillId.health,
40 SkillId.health,
@@ -58,6 +60,7 @@ export const SKILL_DEFINITIONS = Object.freeze({
58 [SkillId.magic]: Object.freeze({ skillId: SkillId.magic, displayName: "Magic" }),
60 [SkillId.magic]: Object.freeze({ skillId: SkillId.magic, displayName: "Magic" }),
59 [SkillId.strength]: Object.freeze({ skillId: SkillId.strength, displayName: "Strength" }),
61 [SkillId.strength]: Object.freeze({ skillId: SkillId.strength, displayName: "Strength" }),
60 [SkillId.dexterity]: Object.freeze({ skillId: SkillId.dexterity, displayName: "Dexterity" }),
62 [SkillId.dexterity]: Object.freeze({ skillId: SkillId.dexterity, displayName: "Dexterity" }),
63 [SkillId.agility]: Object.freeze({ skillId: SkillId.agility, displayName: "Agility" }),
61 [SkillId.mind]: Object.freeze({ skillId: SkillId.mind, displayName: "Mind" }),
64 [SkillId.mind]: Object.freeze({ skillId: SkillId.mind, displayName: "Mind" }),
62 [SkillId.defence]: Object.freeze({ skillId: SkillId.defence, displayName: "Defence" }),
65 [SkillId.defence]: Object.freeze({ skillId: SkillId.defence, displayName: "Defence" }),
63 [SkillId.health]: Object.freeze({ skillId: SkillId.health, displayName: "Health" }),
66 [SkillId.health]: Object.freeze({ skillId: SkillId.health, displayName: "Health" }),
shared/equipment/stats.js +2 −1
@@ -12,7 +12,7 @@ const BONUS_STAT_BY_KIND = Object.freeze({
12 12 [EquipmentKind.bow]: SkillId.dexterity,
13 13 [EquipmentKind.arrowAmmo]: SkillId.dexterity,
14 14 [EquipmentKind.metalArmour]: SkillId.defence,
15 [EquipmentKind.leatherArmour]: SkillId.dexterity,
15 [EquipmentKind.leatherArmour]: SkillId.agility,
16 16 [EquipmentKind.clothArmour]: SkillId.defence,
17 17 [EquipmentKind.wizardCloth]: SkillId.magic,
18 18 [EquipmentKind.shield]: SkillId.defence,
@@ -103,6 +103,7 @@ function emptyBonuses ()
103 103 [SkillId.strength]: 0,
104 104 [SkillId.defence]: 0,
105 105 [SkillId.dexterity]: 0,
106 [SkillId.agility]: 0,
106 107 [SkillId.magic]: 0,
107 108 [SkillId.mind]: 0
108 109 };
@@ -12,7 +12,7 @@ const BONUS_STAT_BY_KIND = Object.freeze({
12 [EquipmentKind.bow]: SkillId.dexterity,
12 [EquipmentKind.bow]: SkillId.dexterity,
13 [EquipmentKind.arrowAmmo]: SkillId.dexterity,
13 [EquipmentKind.arrowAmmo]: SkillId.dexterity,
14 [EquipmentKind.metalArmour]: SkillId.defence,
14 [EquipmentKind.metalArmour]: SkillId.defence,
15 [EquipmentKind.leatherArmour]: SkillId.dexterity,
15 [EquipmentKind.leatherArmour]: SkillId.agility,
16 [EquipmentKind.clothArmour]: SkillId.defence,
16 [EquipmentKind.clothArmour]: SkillId.defence,
17 [EquipmentKind.wizardCloth]: SkillId.magic,
17 [EquipmentKind.wizardCloth]: SkillId.magic,
18 [EquipmentKind.shield]: SkillId.defence,
18 [EquipmentKind.shield]: SkillId.defence,
@@ -103,6 +103,7 @@ function emptyBonuses ()
103 [SkillId.strength]: 0,
103 [SkillId.strength]: 0,
104 [SkillId.defence]: 0,
104 [SkillId.defence]: 0,
105 [SkillId.dexterity]: 0,
105 [SkillId.dexterity]: 0,
106 [SkillId.agility]: 0,
106 [SkillId.magic]: 0,
107 [SkillId.magic]: 0,
107 [SkillId.mind]: 0
108 [SkillId.mind]: 0
108 };
109 };