play: unstick preview bots on path (cardinal nudge, skip waypoint, hub snap)

Made-with: Cursor
This commit is contained in:
2026-04-24 13:46:19 +00:00
parent 454c9a6d6b
commit 5358aa8d86
2 changed files with 44 additions and 2 deletions
+43 -1
View File
@@ -2052,6 +2052,16 @@
const pathfindMinGap = editorEmbedReturn ? 280 : 140;
others.forEach((o, id) => {
if (!isPreviewBotId(id)) return;
if (quizCarryFootprintOverlapsHub(o.x, o.y)) {
const sn = snapPositionOutOfQuizCarryHubIfNeeded(o.x, o.y);
if (Math.abs(sn.x - o.x) > 0.02 || Math.abs(sn.y - o.y) > 0.02) {
o.x = sn.x;
o.y = sn.y;
o.botPath = [];
o.botPathStuckTicks = 0;
o.botQuizCarryPathfindAfter = 0;
}
}
if (!o.botPath || o.botPath.length === 0) {
tryQuizCarryInteractionForPlayer(id, o.x, o.y, { silent: true });
}
@@ -5836,11 +5846,43 @@
o.x = nx;
} else if (canWalkLikeLobbyForBot(o.x, ny, o.x, o.y, o)) {
o.y = ny;
} else {
/* เส้นตรงไป waypoint อาจตัดมุม hub / block — ลองก้าวแนวแกนตามทิศหลักอย่างใดอย่างหนึ่ง */
const cstep = Math.min(MOVE_SPEED * 1.2 * pathStepMul, Math.max(Math.abs(dx), Math.abs(dy), 1e-4));
const sx = dx > 1e-4 ? 1 : dx < -1e-4 ? -1 : 0;
const sy = dy > 1e-4 ? 1 : dy < -1e-4 ? -1 : 0;
const tryAxisX = () => {
if (sx === 0) return false;
if (!canWalkLikeLobbyForBot(o.x + sx * cstep, o.y, o.x, o.y, o)) return false;
o.x += sx * cstep;
return true;
};
const tryAxisY = () => {
if (sy === 0) return false;
if (!canWalkLikeLobbyForBot(o.x, o.y + sy * cstep, o.x, o.y, o)) return false;
o.y += sy * cstep;
return true;
};
if (Math.abs(dx) >= Math.abs(dy)) {
if (!tryAxisX()) tryAxisY();
} else {
if (!tryAxisY()) tryAxisX();
}
}
}
o.x = Math.max(0, Math.min(w - 0.01, o.x));
o.y = Math.max(0, Math.min(h - 0.01, o.y));
if (Math.abs(o.x - ox) > 1e-5 || Math.abs(o.y - oy) > 1e-5) o.botIsWalking = true;
if (Math.abs(o.x - ox) > 1e-5 || Math.abs(o.y - oy) > 1e-5) {
o.botIsWalking = true;
o.botPathStuckTicks = 0;
} else {
o.botPathStuckTicks = (o.botPathStuckTicks | 0) + 1;
if ((o.botPathStuckTicks | 0) >= 20) {
o.botPathStuckTicks = 0;
if (path.length) path.shift();
if (isQuizCarry() && previewFillBots) o.botQuizCarryPathfindAfter = 0;
}
}
}
function pickRandomPreviewBotWanderDir() {
+1 -1
View File
@@ -669,7 +669,7 @@
</div>
<script src="/Game/socket.io/socket.io.js"></script>
<script src="js/version.js?v=0.0166"></script>
<script src="js/play.js?v=0.083"></script>
<script src="js/play.js?v=0.084"></script>
<div class="version-tag">v —</div>
</body>
</html>