diff --git a/client/src/main.ts b/client/src/main.ts index 9f8e85b..8b95adb 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -18,6 +18,7 @@ let noticeTimer: ReturnType; 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(); 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; }