This commit is contained in:
2026-04-24 21:46:21 +03:00
parent f2000b5626
commit 3f57eff615
2 changed files with 65 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Grepolis Remote Control // @name Grepolis Remote Control
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 3.6.1 // @version 3.6.2
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player) // @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
// @author Dimitrios // @author Dimitrios
// @match https://*.grepolis.com/game/* // @match https://*.grepolis.com/game/*
@@ -817,18 +817,17 @@
// Auto Bandit Camp: if enabled, attack/claim when ready // Auto Bandit Camp: if enabled, attack/claim when ready
if (farmSettings.bandit_camp_enabled) { if (farmSettings.bandit_camp_enabled) {
try { try {
const spotModels = uw.MM.getModels().PlayerAttackSpot; const spotColl = uw.MM.getOnlyCollectionByName('PlayerAttackSpot');
if (spotModels) { const spotModel = spotColl?.models?.[0];
const spotId = Object.keys(spotModels)[0]; if (spotModel) {
if (spotId) { const spotId = spotModel.id || spotModel.attributes.id;
const spot = spotModels[spotId];
const nowTs = Math.floor(Date.now() / 1000); const nowTs = Math.floor(Date.now() / 1000);
const townId = spot.attributes.town_id; const townId = spotModel.attributes.town_id;
// Debug log to confirm it's checking // Debug log every cycle
log(`⚔️ Bandit Monitor -> Cooldown in: ${Math.max(0, spot.attributes.cooldown_at - nowTs)}s | Reward: ${spot.attributes.reward_available}`); log(`⚔️ Bandit Monitor -> Cooldown in: ${Math.max(0, spotModel.attributes.cooldown_at - nowTs)}s | Reward: ${spotModel.attributes.reward_available} | TownID: ${townId}`);
if (spot.attributes.reward_available) { if (spotModel.attributes.reward_available) {
log('⚔️ Bandit Camp: Reward available! Waiting before claiming...'); log('⚔️ Bandit Camp: Reward available! Waiting before claiming...');
await sleep(randInt(8000, 24000)); await sleep(randInt(8000, 24000));
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', { uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
@@ -840,8 +839,8 @@
nl_init: true nl_init: true
}); });
log('⚔️ Bandit Camp: Reward claimed!'); log('⚔️ Bandit Camp: Reward claimed!');
} else if (spot.attributes.cooldown_at <= nowTs) { } else if (spotModel.attributes.cooldown_at <= nowTs) {
// Check if there are active movements to make sure troops are home // Check if troops are still marching back
let hasMovements = false; let hasMovements = false;
try { try {
const movements = uw.MM.getOnlyCollectionByName('MovementCommand')?.models || []; const movements = uw.MM.getOnlyCollectionByName('MovementCommand')?.models || [];
@@ -849,7 +848,6 @@
} catch (e) {} } catch (e) {}
if (!hasMovements) { if (!hasMovements) {
// Gather troops
const town = uw.ITowns?.getTown?.(townId) || uw.ITowns?.towns?.[townId]; const town = uw.ITowns?.getTown?.(townId) || uw.ITowns?.towns?.[townId];
if (town) { if (town) {
const myUnits = town.units() || {}; const myUnits = town.units() || {};
@@ -857,14 +855,13 @@
const sendUnits = {}; const sendUnits = {};
let totalUnits = 0; let totalUnits = 0;
for (let u of allowedUnits) { for (let u of allowedUnits) {
if (myUnits[u] > 0) { if ((myUnits[u] || 0) > 0) {
sendUnits[u] = myUnits[u]; sendUnits[u] = myUnits[u];
totalUnits += myUnits[u]; totalUnits += myUnits[u];
} }
} }
if (totalUnits > 0) { if (totalUnits > 0) {
log(`⚔️ Bandit Camp: Cooldown over! Preparing to attack with ${totalUnits} units...`); log(`⚔️ Bandit Camp: Cooldown over! Attacking with ${totalUnits} units...`);
await sleep(randInt(8000, 24000)); await sleep(randInt(8000, 24000));
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', { uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: `PlayerAttackSpot/${spotId}`, model_url: `PlayerAttackSpot/${spotId}`,
@@ -875,17 +872,25 @@
nl_init: true nl_init: true
}); });
log('⚔️ Bandit Camp: Attack sent!'); log('⚔️ Bandit Camp: Attack sent!');
} else {
log('⚔️ Bandit Camp: No units available to send.');
}
} else {
log(`⚔️ Bandit Camp: Town ${townId} not found in local state.`);
}
} else {
log('⚔️ Bandit Camp: Troops still marching — waiting for them to return...');
} }
} }
} } else {
} log('⚔️ Bandit Camp: PlayerAttackSpot collection not found in memory. Is the camp open in-game?');
}
} }
} catch (e) { } catch (e) {
log(`Bandit camp error: ${e.message}`); log(`⚔️ Bandit camp error: ${e.message}`);
} }
} }
if (cmdData.sync_requested) { if (cmdData.sync_requested) {
log('Sync requested by server — pushing state immediately'); log('Sync requested by server — pushing state immediately');
pushState(); pushState();

View File

@@ -104,10 +104,11 @@ def get_pending_command():
# Also return current farm settings so TM knows loot_option # Also return current farm settings so TM knows loot_option
farm_row = c.execute( farm_row = c.execute(
'SELECT enabled, loot_option FROM farm_settings WHERE player_id = ?', (player_id,) 'SELECT enabled, bandit_camp_enabled, loot_option FROM farm_settings WHERE player_id = ?', (player_id,)
).fetchone() ).fetchone()
farm_settings = { farm_settings = {
'enabled': bool(farm_row['enabled']) if farm_row else False, 'enabled': bool(farm_row['enabled']) if farm_row else False,
'bandit_camp_enabled': bool(farm_row['bandit_camp_enabled']) if farm_row else False,
'loot_option': farm_row['loot_option'] if farm_row else 1 'loot_option': farm_row['loot_option'] if farm_row else 1
} }