update: implement security pause and resume functionality for movement
This commit is contained in:
parent
31af5dd592
commit
e68f15f1c7
19
index.js
19
index.js
@ -36,6 +36,7 @@ let emergencyTriggered = false;
|
||||
let securityMonitorInterval = null;
|
||||
let securityArmed = false;
|
||||
let securityArmTimer = null;
|
||||
let securityPausedByMovement = false;
|
||||
let loopStartPosition = null;
|
||||
let pausedByMovementGuard = false;
|
||||
|
||||
@ -66,6 +67,7 @@ function createBotInstance() {
|
||||
spawnerPosition = null;
|
||||
emergencyTriggered = false;
|
||||
securityArmed = false;
|
||||
securityPausedByMovement = false;
|
||||
loopStartPosition = null;
|
||||
pausedByMovementGuard = false;
|
||||
if (securityArmTimer) {
|
||||
@ -293,6 +295,7 @@ function startSecurityMonitor() {
|
||||
|
||||
securityMonitorInterval = setInterval(() => {
|
||||
if (!hasJoined || !bot || emergencyTriggered || !securityArmed) return;
|
||||
if (securityPausedByMovement) return;
|
||||
|
||||
const intruders = getUnauthorizedNearbyPlayers();
|
||||
if (intruders.length > 0) {
|
||||
@ -327,6 +330,18 @@ function armSecurityAfterJoinDelay() {
|
||||
}, SECURITY_ARM_DELAY_MS);
|
||||
}
|
||||
|
||||
function pauseSecurityForMovement() {
|
||||
if (securityPausedByMovement) return;
|
||||
securityPausedByMovement = true;
|
||||
pushLog("security paused: bot moved away from loop start");
|
||||
}
|
||||
|
||||
function resumeSecurityForMovement() {
|
||||
if (!securityPausedByMovement) return;
|
||||
securityPausedByMovement = false;
|
||||
pushLog("security resumed: bot returned to loop start");
|
||||
}
|
||||
|
||||
const webPath = path.join(__dirname, "web", "index.html");
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
@ -1249,6 +1264,7 @@ function bindBotEvents() {
|
||||
!hasJoined ||
|
||||
emergencyTriggered ||
|
||||
!securityArmed ||
|
||||
securityPausedByMovement ||
|
||||
!bot.entity ||
|
||||
!bot.entity.position
|
||||
) {
|
||||
@ -1279,6 +1295,7 @@ function bindBotEvents() {
|
||||
|
||||
const movedDistance = bot.entity.position.distanceTo(guardAnchor);
|
||||
if (movedDistance > MAX_ALLOWED_MOVE_BLOCKS) {
|
||||
pauseSecurityForMovement();
|
||||
pausedByMovementGuard = true;
|
||||
stopSpawnerLoop(
|
||||
`moved ${movedDistance.toFixed(2)} blocks from loop start (> ${MAX_ALLOWED_MOVE_BLOCKS}), pausing loop`,
|
||||
@ -1292,6 +1309,7 @@ function bindBotEvents() {
|
||||
|
||||
const distanceFromAnchor = bot.entity.position.distanceTo(guardAnchor);
|
||||
if (distanceFromAnchor <= LOOP_RESUME_TOLERANCE_BLOCKS) {
|
||||
resumeSecurityForMovement();
|
||||
pushLog(
|
||||
`returned to loop start (<= ${LOOP_RESUME_TOLERANCE_BLOCKS} blocks), re-enabling loop`,
|
||||
);
|
||||
@ -1308,6 +1326,7 @@ function bindBotEvents() {
|
||||
securityArmTimer = null;
|
||||
}
|
||||
securityArmed = false;
|
||||
securityPausedByMovement = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user