fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Grepolis Remote Control
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 2.3
|
||||
// @version 2.4
|
||||
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game
|
||||
// @author Dimitrios
|
||||
// @match https://*.grepolis.com/game/*
|
||||
@@ -406,52 +406,11 @@
|
||||
await Promise.all([execute(buildCmd), execute(recruitCmd)]);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Observers — instant triggers on meaningful game events
|
||||
// ----------------------------------------------------------------
|
||||
function setupObservers() {
|
||||
try {
|
||||
// 1. Town switch — instant dashboard sync when you click a different town
|
||||
uw.$.Observer(uw.GameEvents.town.town_switch).subscribe(() => {
|
||||
log('Observer: town switched — pushing state');
|
||||
pushState();
|
||||
});
|
||||
} catch(e) { log(`Observer town_switch failed: ${e}`); }
|
||||
|
||||
try {
|
||||
// 2. Building finished — push state AND immediately try the next build command
|
||||
uw.$.Observer(uw.GameEvents.town.building.order_completed).subscribe(() => {
|
||||
log('Observer: building completed — pushing state + polling');
|
||||
pushState();
|
||||
pollAndExecute();
|
||||
});
|
||||
} catch(e) { log(`Observer building.order_completed failed: ${e}`); }
|
||||
|
||||
try {
|
||||
// 3. Troops finished training — same logic for the recruit queue
|
||||
uw.$.Observer(uw.GameEvents.town.unit.order_completed).subscribe(() => {
|
||||
log('Observer: unit order completed — pushing state + polling');
|
||||
pushState();
|
||||
pollAndExecute();
|
||||
});
|
||||
} catch(e) { log(`Observer unit.order_completed failed: ${e}`); }
|
||||
|
||||
try {
|
||||
// 4. Points changed — fires when a building finishes (extra safety net)
|
||||
uw.$.Observer(uw.GameEvents.player.points.changed).subscribe(() => {
|
||||
log('Observer: player points changed — pushing state');
|
||||
pushState();
|
||||
});
|
||||
} catch(e) { log(`Observer player.points.changed failed: ${e}`); }
|
||||
|
||||
log('Observers registered successfully');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Boot
|
||||
// ----------------------------------------------------------------
|
||||
window.addEventListener('load', () => {
|
||||
log('Grepolis Remote Control v2.3 loaded');
|
||||
log('Grepolis Remote Control v2.4 loaded');
|
||||
|
||||
// Push state once after load, then every 45–90 seconds (randomized)
|
||||
setTimeout(pushState, 5000);
|
||||
@@ -459,9 +418,6 @@
|
||||
|
||||
// Poll for commands every 8–18 seconds (randomized jitter)
|
||||
jitterLoop(pollAndExecute, 8000, 18000);
|
||||
|
||||
// Wire up game event observers after a short delay to ensure game is ready
|
||||
setTimeout(setupObservers, 6000);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user