Wait for authoritative stop before gathering or looting

This commit is contained in:
dingo
2026-09-12 23:24:27 -04:00
parent 9ca58b3101
commit d664e594af
3 changed files with 38 additions and 4 deletions
+19 -3
View File
@@ -27,7 +27,7 @@ let lastNotice = '';
let noticeTimer: ReturnType<typeof setTimeout>;
let inputElapsed = 0;
let walkTo: { x: number; z: number } | undefined;
let pendingAction: { op: string; target: string } | undefined;
let pendingAction: { op: string; target: string; stopSequence?: number } | undefined;
let actionElapsed = 0;
let riskyArmed = "", gatherSent = 0;
// A gather target can stay legitimately, persistently unreachable for a long time (a
@@ -296,8 +296,20 @@ async function boot() {
const target = actionTarget;
const range = pendingAction ? pendingAction.op === 'attack' ? (snapshot.self.attack?.range??config.attackRange) + (target?.id === 'boss' ? 3 : target?.kind==='structure'?Math.max(target.width??0,target.depth??0)/2-.5:-0.5) : config.gatherRange - 0.5 : 0.8;
const reach = pendingAction?.op === 'attack' && target ? Math.hypot(distance, target.position.y-p.y) : distance;
if (reach <= range) {
if (pendingAction?.stopSequence && snapshot.self.ack < pendingAction.stopSequence) {
// Do not reverse course from a pre-stop snapshot either. Wait for the
// authoritative stopped position, sending zero movement below.
} else if (reach <= range) {
if (!pendingAction) { walkTo = undefined; }
// A delayed snapshot can show us in reach while the server is still
// moving. Gather/loot only after a snapshot acknowledges our stop;
// its position then determines whether we need to approach again.
else if (pendingAction.op !== 'attack' && !pendingAction.stopSequence) {
send('move');
pendingAction.stopSequence = sequence;
actionElapsed = 0;
lastProgress = undefined;
}
// A single fire-and-forget attempt can land a hair outside the authoritative
// server position (which may lag a stale/throttled client render) and get
// rejected with no second chance, so retry at a conservative cadence (well
@@ -321,7 +333,11 @@ async function boot() {
} else if(pendingAction.op!=='gather'||!gatherSent) { send(pendingAction.op, pendingAction.target);if(pendingAction.op==='gather')gatherSent=sequence; }
}
}
} else if (distance > .01) { x = dx / distance; z = dz / distance; actionElapsed = 0.3; }
} else if (distance > .01) {
if (pendingAction) delete pendingAction.stopSequence;
lastProgress = undefined;
x = dx / distance; z = dz / distance; actionElapsed = 0.3;
}
}
view.moving = !!(x || z);
if (inputElapsed >= 0.05) { send('move', '', x, z); inputElapsed = 0; }