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 securityMonitorInterval = null;
|
||||||
let securityArmed = false;
|
let securityArmed = false;
|
||||||
let securityArmTimer = null;
|
let securityArmTimer = null;
|
||||||
|
let securityPausedByMovement = false;
|
||||||
let loopStartPosition = null;
|
let loopStartPosition = null;
|
||||||
let pausedByMovementGuard = false;
|
let pausedByMovementGuard = false;
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ function createBotInstance() {
|
|||||||
spawnerPosition = null;
|
spawnerPosition = null;
|
||||||
emergencyTriggered = false;
|
emergencyTriggered = false;
|
||||||
securityArmed = false;
|
securityArmed = false;
|
||||||
|
securityPausedByMovement = false;
|
||||||
loopStartPosition = null;
|
loopStartPosition = null;
|
||||||
pausedByMovementGuard = false;
|
pausedByMovementGuard = false;
|
||||||
if (securityArmTimer) {
|
if (securityArmTimer) {
|
||||||
@ -293,6 +295,7 @@ function startSecurityMonitor() {
|
|||||||
|
|
||||||
securityMonitorInterval = setInterval(() => {
|
securityMonitorInterval = setInterval(() => {
|
||||||
if (!hasJoined || !bot || emergencyTriggered || !securityArmed) return;
|
if (!hasJoined || !bot || emergencyTriggered || !securityArmed) return;
|
||||||
|
if (securityPausedByMovement) return;
|
||||||
|
|
||||||
const intruders = getUnauthorizedNearbyPlayers();
|
const intruders = getUnauthorizedNearbyPlayers();
|
||||||
if (intruders.length > 0) {
|
if (intruders.length > 0) {
|
||||||
@ -327,6 +330,18 @@ function armSecurityAfterJoinDelay() {
|
|||||||
}, SECURITY_ARM_DELAY_MS);
|
}, 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 webPath = path.join(__dirname, "web", "index.html");
|
||||||
|
|
||||||
const server = http.createServer(async (req, res) => {
|
const server = http.createServer(async (req, res) => {
|
||||||
@ -1249,6 +1264,7 @@ function bindBotEvents() {
|
|||||||
!hasJoined ||
|
!hasJoined ||
|
||||||
emergencyTriggered ||
|
emergencyTriggered ||
|
||||||
!securityArmed ||
|
!securityArmed ||
|
||||||
|
securityPausedByMovement ||
|
||||||
!bot.entity ||
|
!bot.entity ||
|
||||||
!bot.entity.position
|
!bot.entity.position
|
||||||
) {
|
) {
|
||||||
@ -1279,6 +1295,7 @@ function bindBotEvents() {
|
|||||||
|
|
||||||
const movedDistance = bot.entity.position.distanceTo(guardAnchor);
|
const movedDistance = bot.entity.position.distanceTo(guardAnchor);
|
||||||
if (movedDistance > MAX_ALLOWED_MOVE_BLOCKS) {
|
if (movedDistance > MAX_ALLOWED_MOVE_BLOCKS) {
|
||||||
|
pauseSecurityForMovement();
|
||||||
pausedByMovementGuard = true;
|
pausedByMovementGuard = true;
|
||||||
stopSpawnerLoop(
|
stopSpawnerLoop(
|
||||||
`moved ${movedDistance.toFixed(2)} blocks from loop start (> ${MAX_ALLOWED_MOVE_BLOCKS}), pausing loop`,
|
`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);
|
const distanceFromAnchor = bot.entity.position.distanceTo(guardAnchor);
|
||||||
if (distanceFromAnchor <= LOOP_RESUME_TOLERANCE_BLOCKS) {
|
if (distanceFromAnchor <= LOOP_RESUME_TOLERANCE_BLOCKS) {
|
||||||
|
resumeSecurityForMovement();
|
||||||
pushLog(
|
pushLog(
|
||||||
`returned to loop start (<= ${LOOP_RESUME_TOLERANCE_BLOCKS} blocks), re-enabling loop`,
|
`returned to loop start (<= ${LOOP_RESUME_TOLERANCE_BLOCKS} blocks), re-enabling loop`,
|
||||||
);
|
);
|
||||||
@ -1308,6 +1326,7 @@ function bindBotEvents() {
|
|||||||
securityArmTimer = null;
|
securityArmTimer = null;
|
||||||
}
|
}
|
||||||
securityArmed = false;
|
securityArmed = false;
|
||||||
|
securityPausedByMovement = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user