fix: retry gather/attack instead of firing once and giving up
The new server-side "intent rejected" log (from the last commit) caught it in the act: a single "boss out of reach" / "resource out of reach" rejection, then nothing -- the client's walk-to-target flow fires the gather/attack intent exactly once, the instant its (possibly a tick stale) view of the authoritative server position first reads as in-range, then immediately clears pendingAction/walkTo regardless of whether the server actually accepted it. One unlucky frame and the action is silently dead for good, which is exactly what stalled the e2e gather and boss-attack polls waiting on an effect that was never going to happen without another click. Now it keeps retrying (throttled to ~3/s, well under the websocket's input-rate limit and matching the server's own action cooldowns) as long as the character stays in range, instead of clearing on the first attempt. Confirmed locally: normal runs now show the retry harmlessly hitting "resource depleted"/"attack cooldown" for the attempts *after* the one that actually landed, and the full e2e suite (7/7, both spec files) still passes. Also held up under artificial CPU throttling via a CDP session (up to 50x) in manual testing, which the old single-shot code also happened to survive locally -- so this is a fix for a real fragility this log caught directly, not a blind guess. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+10
-2
@@ -18,6 +18,7 @@ let noticeTimer: ReturnType<typeof setTimeout>;
|
||||
let inputElapsed = 0;
|
||||
let walkTo: { x: number; z: number } | undefined;
|
||||
let pendingAction: { op: string; target: string } | undefined;
|
||||
let actionElapsed = 0;
|
||||
let requestedClose = false;
|
||||
const keys = new Set<string>();
|
||||
let view: WorldView;
|
||||
@@ -157,8 +158,15 @@ async function boot() {
|
||||
const p = snapshot.self.entity.position, dx = walkTo.x - p.x, dz = walkTo.z - p.z, distance = Math.hypot(dx, dz);
|
||||
const target = snapshot.entities.find(e => e.id === pendingAction?.target);
|
||||
const range = pendingAction ? pendingAction.op === 'attack' ? config.attackRange + (target?.kind === 'boss' ? 3 : -0.5) : config.gatherRange - 0.5 : 0.8;
|
||||
if (distance <= range) { if (pendingAction) send(pendingAction.op, pendingAction.target); walkTo = undefined; pendingAction = undefined; }
|
||||
else { x = dx / distance; z = dz / distance; }
|
||||
if (distance <= range) {
|
||||
if (!pendingAction) { walkTo = 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. Keep retrying at a conservative cadence
|
||||
// (well under the intent rate limit) instead of giving up forever; the
|
||||
// server's own action cooldown makes repeat attempts harmless.
|
||||
else { actionElapsed += dt; if (actionElapsed >= 0.3) { send(pendingAction.op, pendingAction.target); actionElapsed = 0; } }
|
||||
} else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; }
|
||||
}
|
||||
view.moving = !!(x || z);
|
||||
if (inputElapsed >= 0.05) { send('move', '', x, z); inputElapsed = 0; }
|
||||
|
||||
Reference in New Issue
Block a user