BlueGit

timfa questward

Style quest objectives and leash combat beyond 3× wander range.

Done objectives show green with strikethrough; pending stay amber. Spawner mobs drop chase past three times wander range and walk home.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
bfc56b2ca467979731adfc7c22725539f88788fc
Parent
afd1edd6
4 files changed +152 −5
client/ui/play.css +5 −1
@@ -2816,9 +2816,13 @@ button.friend-account-name:hover {
2816 2816 padding-left: 1.1rem;
2817 2817 }
2818 2818
2819 .quests-objectives li {
2820 color: #e0a84a;
2821 }
2822
2819 2823 .quests-objectives li.done {
2820 2824 text-decoration: line-through;
2821 color: #8a909c;
2825 color: #5cb87a;
2822 2826 }
2823 2827
2824 2828 #dialogue-panel {
@@ -2816,9 +2816,13 @@ button.friend-account-name:hover {
2816 padding-left: 1.1rem;
2816 padding-left: 1.1rem;
2817}
2817}
2818
2818
2819.quests-objectives li {
2820 color: #e0a84a;
2821}
2822
2819.quests-objectives li.done {
2823.quests-objectives li.done {
2820 text-decoration: line-through;
2824 text-decoration: line-through;
2821 color: #8a909c;
2825 color: #5cb87a;
2822}
2826}
2823
2827
2824#dialogue-panel {
2828#dialogue-panel {
server/src/combat/service.js +85 −0
@@ -129,6 +129,74 @@ function dropCombatTarget (world, entity)
129 129 syncCreatureChaseGait(world, entity.handle, 0, false);
130 130 }
131 131
132 /** Euclidean (hemelsbreed) distance from spawn origin for combat leash. */
133 export function spawnOriginDistance (position, origin)
134 {
135 const ox = Number.isInteger(origin?.originTileX) ? origin.originTileX : (position.tileX | 0);
136 const oy = Number.isInteger(origin?.originTileY) ? origin.originTileY : (position.tileY | 0);
137 return Math.hypot((position.tileX | 0) - ox, (position.tileY | 0) - oy);
138 }
139
140 /** Break chase when farther than 3× wander range from the spawner. */
141 export function combatLeashLimit (wanderRangeTiles)
142 {
143 return Math.max(0, wanderRangeTiles | 0) * 3;
144 }
145
146 function creatureWithinWanderHome (world, handle, position)
147 {
148 const origin = world.ecs.get(handle, Component.spawnOrigin);
149 if (!origin)
150 { return true; }
151 const range = Math.max(0, origin.wanderRangeTiles | 0);
152 const ox = Number.isInteger(origin.originTileX) ? origin.originTileX : (position.tileX | 0);
153 const oy = Number.isInteger(origin.originTileY) ? origin.originTileY : (position.tileY | 0);
154 const chebyshevHome = Math.max(
155 Math.abs((position.tileX | 0) - ox),
156 Math.abs((position.tileY | 0) - oy)
157 );
158 return chebyshevHome <= range;
159 }
160
161 /**
162 * Spawner creatures break combat when chased beyond 3× wander range (euclidean).
163 * Ambient mobs without spawnOrigin are not leashed.
164 */
165 function creatureShouldBreakCombatLeash (world, handle, position)
166 {
167 if (!isCombatCreature(world, handle))
168 { return false; }
169 if (world.ecs.get(handle, Component.summon))
170 { return false; }
171 const origin = world.ecs.get(handle, Component.spawnOrigin);
172 if (!origin)
173 { return false; }
174 const range = Math.max(0, origin.wanderRangeTiles | 0);
175 if (range <= 0)
176 { return false; }
177 return spawnOriginDistance(position, origin) > combatLeashLimit(range);
178 }
179
180 function beginCombatLeashReturn (world, entity)
181 {
182 const combat = entity.combat;
183 combat.targetEntityId = null;
184 combat.leashing = true;
185 combat.seekCover = false;
186 combat.fleeFrom = null;
187 clearCombatApproachPath(world.ecs, entity.handle);
188 syncCreatureChaseGait(world, entity.handle, 0, false);
189 }
190
191 function clearLeashingIfHome (world, entity)
192 {
193 const combat = entity.combat;
194 if (!combat?.leashing)
195 { return; }
196 if (creatureWithinWanderHome(world, entity.handle, entity.position))
197 { combat.leashing = false; }
198 }
199
132 200 /**
133 201 * Stop everyone who was attacking / auto-casting at `targetEntityId`
134 202 * (melee engage, spell repeat, pending cast, approach path).
@@ -416,6 +484,7 @@ export function engageTarget (ecs, attackerId, targetId, now = Date.now())
416 484 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0, seekCover: false, fleeFrom: null }); }
417 485 const targetChanged = combat.targetEntityId !== targetId;
418 486 combat.targetEntityId = targetId;
487 combat.leashing = false;
419 488 if (targetChanged)
420 489 {
421 490 // New engage (or switch): allow an immediate swing; keep cadence if already on this target.
@@ -782,6 +851,9 @@ export function stepAggression (world, now = Date.now())
782 851 if (health && health.current <= 0)
783 852 { continue; }
784 853 const combat = world.ecs.get(entity.handle, Component.combat);
854 clearLeashingIfHome(world, { combat, handle: entity.handle, position: entity.position });
855 if (combat?.leashing)
856 { continue; }
785 857 if (combat?.targetEntityId != null)
786 858 { continue; }
787 859
@@ -1063,6 +1135,13 @@ export function stepCombat (world, now = Date.now())
1063 1135 if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
1064 1136 { continue; }
1065 1137 const combat = entity.combat;
1138 clearLeashingIfHome(world, entity);
1139 if (combat.leashing)
1140 {
1141 combat.targetEntityId = null;
1142 syncCreatureChaseGait(world, entity.handle, 0, false);
1143 continue;
1144 }
1066 1145 const targetId = combat.targetEntityId;
1067 1146 if (targetId == null)
1068 1147 { continue; }
@@ -1078,6 +1157,12 @@ export function stepCombat (world, now = Date.now())
1078 1157 continue;
1079 1158 }
1080 1159
1160 if (creatureShouldBreakCombatLeash(world, entity.handle, entity.position))
1161 {
1162 beginCombatLeashReturn(world, entity);
1163 continue;
1164 }
1165
1081 1166 // One combat form at a time: spell cast / auto-cast wins over melee & archery.
1082 1167 if (isSpellCombatBusy(world.ecs, entity.handle))
1083 1168 { continue; }
@@ -129,6 +129,74 @@ function dropCombatTarget (world, entity)
129 syncCreatureChaseGait(world, entity.handle, 0, false);
129 syncCreatureChaseGait(world, entity.handle, 0, false);
130}
130}
131
131
132/** Euclidean (hemelsbreed) distance from spawn origin for combat leash. */
133export function spawnOriginDistance (position, origin)
134{
135 const ox = Number.isInteger(origin?.originTileX) ? origin.originTileX : (position.tileX | 0);
136 const oy = Number.isInteger(origin?.originTileY) ? origin.originTileY : (position.tileY | 0);
137 return Math.hypot((position.tileX | 0) - ox, (position.tileY | 0) - oy);
138}
139
140/** Break chase when farther than 3× wander range from the spawner. */
141export function combatLeashLimit (wanderRangeTiles)
142{
143 return Math.max(0, wanderRangeTiles | 0) * 3;
144}
145
146function creatureWithinWanderHome (world, handle, position)
147{
148 const origin = world.ecs.get(handle, Component.spawnOrigin);
149 if (!origin)
150 { return true; }
151 const range = Math.max(0, origin.wanderRangeTiles | 0);
152 const ox = Number.isInteger(origin.originTileX) ? origin.originTileX : (position.tileX | 0);
153 const oy = Number.isInteger(origin.originTileY) ? origin.originTileY : (position.tileY | 0);
154 const chebyshevHome = Math.max(
155 Math.abs((position.tileX | 0) - ox),
156 Math.abs((position.tileY | 0) - oy)
157 );
158 return chebyshevHome <= range;
159}
160
161/**
162 * Spawner creatures break combat when chased beyond 3× wander range (euclidean).
163 * Ambient mobs without spawnOrigin are not leashed.
164 */
165function creatureShouldBreakCombatLeash (world, handle, position)
166{
167 if (!isCombatCreature(world, handle))
168 { return false; }
169 if (world.ecs.get(handle, Component.summon))
170 { return false; }
171 const origin = world.ecs.get(handle, Component.spawnOrigin);
172 if (!origin)
173 { return false; }
174 const range = Math.max(0, origin.wanderRangeTiles | 0);
175 if (range <= 0)
176 { return false; }
177 return spawnOriginDistance(position, origin) > combatLeashLimit(range);
178}
179
180function beginCombatLeashReturn (world, entity)
181{
182 const combat = entity.combat;
183 combat.targetEntityId = null;
184 combat.leashing = true;
185 combat.seekCover = false;
186 combat.fleeFrom = null;
187 clearCombatApproachPath(world.ecs, entity.handle);
188 syncCreatureChaseGait(world, entity.handle, 0, false);
189}
190
191function clearLeashingIfHome (world, entity)
192{
193 const combat = entity.combat;
194 if (!combat?.leashing)
195 { return; }
196 if (creatureWithinWanderHome(world, entity.handle, entity.position))
197 { combat.leashing = false; }
198}
199
132/**
200/**
133 * Stop everyone who was attacking / auto-casting at `targetEntityId`
201 * Stop everyone who was attacking / auto-casting at `targetEntityId`
134 * (melee engage, spell repeat, pending cast, approach path).
202 * (melee engage, spell repeat, pending cast, approach path).
@@ -416,6 +484,7 @@ export function engageTarget (ecs, attackerId, targetId, now = Date.now())
416 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0, seekCover: false, fleeFrom: null }); }
484 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0, seekCover: false, fleeFrom: null }); }
417 const targetChanged = combat.targetEntityId !== targetId;
485 const targetChanged = combat.targetEntityId !== targetId;
418 combat.targetEntityId = targetId;
486 combat.targetEntityId = targetId;
487 combat.leashing = false;
419 if (targetChanged)
488 if (targetChanged)
420 {
489 {
421 // New engage (or switch): allow an immediate swing; keep cadence if already on this target.
490 // New engage (or switch): allow an immediate swing; keep cadence if already on this target.
@@ -782,6 +851,9 @@ export function stepAggression (world, now = Date.now())
782 if (health && health.current <= 0)
851 if (health && health.current <= 0)
783 { continue; }
852 { continue; }
784 const combat = world.ecs.get(entity.handle, Component.combat);
853 const combat = world.ecs.get(entity.handle, Component.combat);
854 clearLeashingIfHome(world, { combat, handle: entity.handle, position: entity.position });
855 if (combat?.leashing)
856 { continue; }
785 if (combat?.targetEntityId != null)
857 if (combat?.targetEntityId != null)
786 { continue; }
858 { continue; }
787
859
@@ -1063,6 +1135,13 @@ export function stepCombat (world, now = Date.now())
1063 if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
1135 if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
1064 { continue; }
1136 { continue; }
1065 const combat = entity.combat;
1137 const combat = entity.combat;
1138 clearLeashingIfHome(world, entity);
1139 if (combat.leashing)
1140 {
1141 combat.targetEntityId = null;
1142 syncCreatureChaseGait(world, entity.handle, 0, false);
1143 continue;
1144 }
1066 const targetId = combat.targetEntityId;
1145 const targetId = combat.targetEntityId;
1067 if (targetId == null)
1146 if (targetId == null)
1068 { continue; }
1147 { continue; }
@@ -1078,6 +1157,12 @@ export function stepCombat (world, now = Date.now())
1078 continue;
1157 continue;
1079 }
1158 }
1080
1159
1160 if (creatureShouldBreakCombatLeash(world, entity.handle, entity.position))
1161 {
1162 beginCombatLeashReturn(world, entity);
1163 continue;
1164 }
1165
1081 // One combat form at a time: spell cast / auto-cast wins over melee & archery.
1166 // One combat form at a time: spell cast / auto-cast wins over melee & archery.
1082 if (isSpellCombatBusy(world.ecs, entity.handle))
1167 if (isSpellCombatBusy(world.ecs, entity.handle))
1083 { continue; }
1168 { continue; }
server/src/simulation/workerWorld.js +4 −3
@@ -1806,7 +1806,8 @@ export class WorkerWorld
1806 1806 }
1807 1807 }
1808 1808
1809 /** Idle wander for spawner mobs: goals must stay within maxWanderRange of the spawner. Combat chase is unrestricted. */
1809 /** Idle wander for spawner mobs: goals must stay within maxWanderRange of the spawner.
1810 * Combat chase is limited to 3× wander range (euclidean); beyond that they leash home. */
1810 1811 #queueSpawnerWander ()
1811 1812 {
1812 1813 for (const entity of this.ecs.query(Component.position, Component.movement, Component.spawnOrigin))
@@ -1841,9 +1842,9 @@ export class WorkerWorld
1841 1842 Math.abs(entity.position.tileX - originX),
1842 1843 Math.abs(entity.position.tileY - originY)
1843 1844 );
1844 const tooFar = homeDist > range;
1845 const tooFar = homeDist > range || !!combat?.leashing;
1845 1846
1846 // Outside the leash: always try to step home. Inside: mostly idle.
1847 // Outside the leash / returning from combat: always try to step home. Inside: mostly idle.
1847 1848 if (!tooFar && Math.random() > 0.1)
1848 1849 { continue; }
1849 1850
@@ -1806,7 +1806,8 @@ export class WorkerWorld
1806 }
1806 }
1807 }
1807 }
1808
1808
1809 /** Idle wander for spawner mobs: goals must stay within maxWanderRange of the spawner. Combat chase is unrestricted. */
1809 /** Idle wander for spawner mobs: goals must stay within maxWanderRange of the spawner.
1810 * Combat chase is limited to 3× wander range (euclidean); beyond that they leash home. */
1810 #queueSpawnerWander ()
1811 #queueSpawnerWander ()
1811 {
1812 {
1812 for (const entity of this.ecs.query(Component.position, Component.movement, Component.spawnOrigin))
1813 for (const entity of this.ecs.query(Component.position, Component.movement, Component.spawnOrigin))
@@ -1841,9 +1842,9 @@ export class WorkerWorld
1841 Math.abs(entity.position.tileX - originX),
1842 Math.abs(entity.position.tileX - originX),
1842 Math.abs(entity.position.tileY - originY)
1843 Math.abs(entity.position.tileY - originY)
1843 );
1844 );
1844 const tooFar = homeDist > range;
1845 const tooFar = homeDist > range || !!combat?.leashing;
1845
1846
1846 // Outside the leash: always try to step home. Inside: mostly idle.
1847 // Outside the leash / returning from combat: always try to step home. Inside: mostly idle.
1847 if (!tooFar && Math.random() > 0.1)
1848 if (!tooFar && Math.random() > 0.1)
1848 { continue; }
1849 { continue; }
1849
1850
server/tests/combat.test.js +58 −1
@@ -15,7 +15,7 @@ import { SkillId } from "../../shared/definitions/skills.js";
15 15 import { SpellId } from "../../shared/definitions/spells.js";
16 16 import { totalXpForLevel } from "../../shared/skills/progression.js";
17 17 import { GAIT } from "../../shared/protocol/constants.js";
18 import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev, COMBAT_CHASE_RUN_TILES } from "../src/combat/service.js";
18 import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev, COMBAT_CHASE_RUN_TILES, combatLeashLimit, spawnOriginDistance } from "../src/combat/service.js";
19 19 import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
20 20 import { SKULL_KILL_BONUS } from "../../shared/combat/skull.js";
21 21 import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
@@ -1874,3 +1874,60 @@ test("fairy flees to 2 tiles from hit source, then stops until hit again", () =>
1874 1874 finally
1875 1875 { harness.close(); }
1876 1876 });
1877
1878 test("combat leash limit is three times wander range", () =>
1879 {
1880 assert.equal(combatLeashLimit(4), 12);
1881 assert.equal(combatLeashLimit(0), 0);
1882 assert.equal(spawnOriginDistance({ tileX: 8, tileY: 8 }, { originTileX: 8, originTileY: 12 }), 4);
1883 });
1884
1885 test("spawner mobs break combat beyond 3× wander range and leash home", () =>
1886 {
1887 withDamagingCombatRng(() =>
1888 {
1889 const harness = makeSimulation({ workerCount: 1 });
1890 try
1891 {
1892 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
1893 const playerId = harness.simulation.spawnCharacter(1, character);
1894 const ratId = harness.simulation.spawnEntity(mobComponents({
1895 tileX: 10,
1896 tileY: 8,
1897 mobTypeId: MobId.rat,
1898 spawnerId: "leash-rat",
1899 originTileX: 10,
1900 originTileY: 8,
1901 wanderRangeTiles: 2,
1902 aggressive: true
1903 }));
1904 harness.simulation.step();
1905
1906 const worker = workerOf(harness.simulation, ratId);
1907 const world = worker.world;
1908 const handle = world.ecs.handleOf(ratId);
1909 engageTarget(world.ecs, ratId, playerId, Date.now());
1910 assert.equal(world.ecs.get(handle, Component.combat)?.targetEntityId, playerId);
1911
1912 // Euclidean distance 7 > 3×2=6 → break leash.
1913 teleportEntity(worker, ratId, 17, 8);
1914 stepCombat(world, Date.now());
1915 const combat = world.ecs.get(handle, Component.combat);
1916 assert.equal(combat?.targetEntityId, null);
1917 assert.equal(combat?.leashing, true);
1918
1919 stepTimes(harness.simulation, 5);
1920 const path = world.ecs.get(handle, Component.path);
1921 assert.ok(
1922 (path?.tiles?.length ?? 0) > 0 || (() =>
1923 {
1924 const pos = world.ecs.get(handle, Component.position);
1925 return Math.max(Math.abs(pos.tileX - 10), Math.abs(pos.tileY - 8)) <= 2;
1926 })(),
1927 "leashing mob should path toward wander home"
1928 );
1929 }
1930 finally
1931 { harness.close(); }
1932 });
1933 });
@@ -15,7 +15,7 @@ import { SkillId } from "../../shared/definitions/skills.js";
15import { SpellId } from "../../shared/definitions/spells.js";
15import { SpellId } from "../../shared/definitions/spells.js";
16import { totalXpForLevel } from "../../shared/skills/progression.js";
16import { totalXpForLevel } from "../../shared/skills/progression.js";
17import { GAIT } from "../../shared/protocol/constants.js";
17import { GAIT } from "../../shared/protocol/constants.js";
18import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev, COMBAT_CHASE_RUN_TILES } from "../src/combat/service.js";
18import { resolveMeleeSwing, attackProfileOf, hasCombatLineOfSight, queueMeleeApproach, markSeekCover, engageTarget, applyDamageAndKill, markFleeOnHit, stepCombat, chebyshev, COMBAT_CHASE_RUN_TILES, combatLeashLimit, spawnOriginDistance } from "../src/combat/service.js";
19import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
19import { combatDamageRollLevel } from "../../shared/combat/rolls.js";
20import { SKULL_KILL_BONUS } from "../../shared/combat/skull.js";
20import { SKULL_KILL_BONUS } from "../../shared/combat/skull.js";
21import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
21import { makeCharacter, makeSimulation, pinEastSplit, stepTimes } from "./helpers/simulationHarness.js";
@@ -1874,3 +1874,60 @@ test("fairy flees to 2 tiles from hit source, then stops until hit again", () =>
1874 finally
1874 finally
1875 { harness.close(); }
1875 { harness.close(); }
1876});
1876});
1877
1878test("combat leash limit is three times wander range", () =>
1879{
1880 assert.equal(combatLeashLimit(4), 12);
1881 assert.equal(combatLeashLimit(0), 0);
1882 assert.equal(spawnOriginDistance({ tileX: 8, tileY: 8 }, { originTileX: 8, originTileY: 12 }), 4);
1883});
1884
1885test("spawner mobs break combat beyond 3× wander range and leash home", () =>
1886{
1887 withDamagingCombatRng(() =>
1888 {
1889 const harness = makeSimulation({ workerCount: 1 });
1890 try
1891 {
1892 const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
1893 const playerId = harness.simulation.spawnCharacter(1, character);
1894 const ratId = harness.simulation.spawnEntity(mobComponents({
1895 tileX: 10,
1896 tileY: 8,
1897 mobTypeId: MobId.rat,
1898 spawnerId: "leash-rat",
1899 originTileX: 10,
1900 originTileY: 8,
1901 wanderRangeTiles: 2,
1902 aggressive: true
1903 }));
1904 harness.simulation.step();
1905
1906 const worker = workerOf(harness.simulation, ratId);
1907 const world = worker.world;
1908 const handle = world.ecs.handleOf(ratId);
1909 engageTarget(world.ecs, ratId, playerId, Date.now());
1910 assert.equal(world.ecs.get(handle, Component.combat)?.targetEntityId, playerId);
1911
1912 // Euclidean distance 7 > 3×2=6 → break leash.
1913 teleportEntity(worker, ratId, 17, 8);
1914 stepCombat(world, Date.now());
1915 const combat = world.ecs.get(handle, Component.combat);
1916 assert.equal(combat?.targetEntityId, null);
1917 assert.equal(combat?.leashing, true);
1918
1919 stepTimes(harness.simulation, 5);
1920 const path = world.ecs.get(handle, Component.path);
1921 assert.ok(
1922 (path?.tiles?.length ?? 0) > 0 || (() =>
1923 {
1924 const pos = world.ecs.get(handle, Component.position);
1925 return Math.max(Math.abs(pos.tileX - 10), Math.abs(pos.tileY - 8)) <= 2;
1926 })(),
1927 "leashing mob should path toward wander home"
1928 );
1929 }
1930 finally
1931 { harness.close(); }
1932 });
1933});