This commit is contained in:
2026-04-24 22:14:19 +03:00
parent 1dc96a53ee
commit 9aba81960a
4 changed files with 15 additions and 155 deletions

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Grepolis Remote Control
// @namespace http://tampermonkey.net/
// @version 3.6.7
// @version 3.5.7
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
// @author Dimitrios
// @match https://*.grepolis.com/game/*
@@ -814,120 +814,6 @@
}
}
// Auto Bandit Camp: if enabled, attack/claim when ready
if (farmSettings.bandit_camp_enabled) {
try {
// player_id already declared above in pollAndExecute scope
const currentTownId = uw.ITowns?.getCurrentTown?.()?.id
|| Object.keys(uw.ITowns?.towns || {})[0]
|| null;
if (!player_id || !currentTownId) {
log(`⚔️ Bandit Camp: Missing globals — player_id=${player_id} town_id=${currentTownId}`);
} else {
// First try: MM collection (works once camp was opened in-game)
let spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
// Second try: use gpAjax with a callback — it handles auth/hash internally
if (!spotData) {
spotData = await new Promise((resolve) => {
try {
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: `PlayerAttackSpot/${player_id}`,
action_name: 'get_own',
captcha: null,
arguments: {},
town_id: currentTownId,
nl_init: true
}, false, {
success: function(data) {
// Response may contain the spot data directly
const d = data?.PlayerAttackSpot
|| data?.data?.PlayerAttackSpot?.[player_id]
|| data?.[player_id]
|| data;
resolve((d && d.cooldown_at !== undefined) ? d : null);
},
error: function() { resolve(null); }
});
} catch(e) { resolve(null); }
});
// After the gpAjax call, MM might now have the model
if (!spotData) {
spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
}
}
if (!spotData) {
log('⚔️ Bandit Camp: Could not load spot data. Open the Bandit Camp window in-game once to let the game load it.');
} else {
const nowTs = Math.floor(Date.now() / 1000);
const spotId = spotData.id || player_id;
const townId = spotData.town_id || currentTownId;
log(`⚔️ Bandit Monitor -> Cooldown in: ${Math.max(0, spotData.cooldown_at - nowTs)}s | Reward: ${spotData.reward_available} | Level: ${spotData.level}`);
if (spotData.reward_available) {
log('⚔️ Bandit Camp: Reward available! Waiting before claiming...');
await sleep(randInt(8000, 24000));
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: `PlayerAttackSpot/${spotId}`,
action_name: 'useReward',
captcha: null,
arguments: {},
town_id: townId,
nl_init: true
});
log('⚔️ Bandit Camp: Reward claimed!');
} else if (spotData.cooldown_at <= nowTs) {
let hasMovements = false;
try {
const movements = uw.MM.getOnlyCollectionByName('MovementCommand')?.models || [];
hasMovements = movements.length > 0;
} catch (e) {}
if (!hasMovements) {
const town = uw.ITowns?.getTown?.(townId) || uw.ITowns?.towns?.[townId];
if (town) {
const myUnits = town.units() || {};
const allowedUnits = ['sword', 'slinger', 'archer', 'hoplite', 'rider', 'chariot', 'catapult'];
const sendUnits = {};
let totalUnits = 0;
for (let u of allowedUnits) {
if ((myUnits[u] || 0) > 0) {
sendUnits[u] = myUnits[u];
totalUnits += myUnits[u];
}
}
if (totalUnits > 0) {
log(`⚔️ Bandit Camp: Attacking with ${totalUnits} units...`);
await sleep(randInt(8000, 24000));
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: `PlayerAttackSpot/${spotId}`,
action_name: 'attack',
captcha: null,
arguments: sendUnits,
town_id: townId,
nl_init: true
});
log('⚔️ Bandit Camp: Attack sent!');
} else {
log('⚔️ Bandit Camp: No units available.');
}
}
} else {
log('⚔️ Bandit Camp: Troops still returning — waiting...');
}
}
}
}
} catch (e) {
log(`⚔️ Bandit camp error: ${e.message}`);
}
}
if (cmdData.sync_requested) {
log('Sync requested by server — pushing state immediately');
pushState();