This commit is contained in:
2026-04-24 21:56:00 +03:00
parent 9372a42d3a
commit a2a6714188

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.3 // @version 3.6.4
// @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/*
@@ -816,51 +816,67 @@
// 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 to get the collection — it's only loaded if the camp UI was opened.
// If not found, actively fetch it from the game server.
let spotModel = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0];
if (!spotModel) {
// Log available collections once for diagnostics
try {
const allColls = uw.MM.getAllCollections ? uw.MM.getAllCollections() : null;
if (allColls) {
const names = Object.keys(allColls).filter(k => k.toLowerCase().includes('attack') || k.toLowerCase().includes('spot') || k.toLowerCase().includes('bandit'));
if (names.length) log(`⚔️ Bandit: Possible collection names: ${names.join(', ')}`);
}
} catch(e) {}
// Actively fetch the spot state from the game server
log('⚔️ Bandit Camp: Collection not in memory — fetching from server...');
try { try {
const player_id = uw.Game?.player_id; const player_id = uw.Game?.player_id;
const currentTownId = uw.Game?.town_id; const currentTownId = uw.Game?.town_id;
if (player_id && currentTownId) { if (!player_id || !currentTownId) {
await new Promise((resolve) => { log('⚔️ Bandit Camp: No player_id or town_id found in Game globals.');
uw.gpAjax.ajaxPost('frontend_bridge', 'get_own', { } else {
// Build hash param — it's embedded in the page URL or game globals
const hash = uw.Game?.csrf_token || uw.Game?.h || uw.Game?.hash || '';
// Direct fetch of the PlayerAttackSpot model state
const url = `/game/frontend_bridge?town_id=${currentTownId}&action=execute&h=${hash}`;
const body = new URLSearchParams({
json: JSON.stringify({
model_url: `PlayerAttackSpot/${player_id}`, model_url: `PlayerAttackSpot/${player_id}`,
action_name: 'get_state',
captcha: null,
arguments: {},
town_id: currentTownId, town_id: currentTownId,
nl_init: true nl_init: true
})
}); });
setTimeout(resolve, 2000); // wait 2s for the model to load
const resp = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
},
body: body.toString()
}); });
spotModel = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0];
} let spotData = null;
} catch(e) { if (resp.ok) {
log(`⚔️ Bandit fetch error: ${e.message}`); try {
} const raw = await resp.json();
// Try to find the spot data in the response
spotData = raw?.data?.PlayerAttackSpot?.[player_id]
|| raw?.data?.player_attack_spot
|| raw?.PlayerAttackSpot
|| (Array.isArray(raw?.data) ? raw.data[0] : null)
|| raw;
if (spotData?.cooldown_at === undefined) spotData = null;
} catch(e) {}
} }
if (spotModel) { // Fallback: try the MM collection (works if camp was opened once)
const spotId = spotModel.id || spotModel.attributes.id; if (!spotData) {
const mmModel = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0];
if (mmModel) spotData = mmModel.attributes;
}
if (!spotData) {
log(`⚔️ Bandit Camp: Could not load spot data. hash=${hash ? 'found' : 'MISSING'}. Try opening the camp window in-game once.`);
} else {
const nowTs = Math.floor(Date.now() / 1000); const nowTs = Math.floor(Date.now() / 1000);
const townId = spotModel.attributes.town_id; const spotId = spotData.id || player_id;
const townId = spotData.town_id || currentTownId;
// Debug log every cycle log(`⚔️ Bandit Monitor -> Cooldown in: ${Math.max(0, spotData.cooldown_at - nowTs)}s | Reward: ${spotData.reward_available} | Level: ${spotData.level}`);
log(`⚔️ Bandit Monitor -> Cooldown in: ${Math.max(0, spotModel.attributes.cooldown_at - nowTs)}s | Reward: ${spotModel.attributes.reward_available} | TownID: ${townId}`);
if (spotModel.attributes.reward_available) { if (spotData.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', {
@@ -872,8 +888,7 @@
nl_init: true nl_init: true
}); });
log('⚔️ Bandit Camp: Reward claimed!'); log('⚔️ Bandit Camp: Reward claimed!');
} else if (spotModel.attributes.cooldown_at <= nowTs) { } else if (spotData.cooldown_at <= nowTs) {
// 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 || [];
@@ -894,7 +909,7 @@
} }
} }
if (totalUnits > 0) { if (totalUnits > 0) {
log(`⚔️ Bandit Camp: Cooldown over! Attacking with ${totalUnits} units...`); log(`⚔️ Bandit Camp: 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}`,
@@ -906,17 +921,14 @@
}); });
log('⚔️ Bandit Camp: Attack sent!'); log('⚔️ Bandit Camp: Attack sent!');
} else { } else {
log('⚔️ Bandit Camp: No units available to send.'); log('⚔️ Bandit Camp: No units available.');
}
} else {
log(`⚔️ Bandit Camp: Town ${townId} not found in local state.`);
}
} else {
log('⚔️ Bandit Camp: Troops still marching — waiting for them to return...');
} }
} }
} else { } else {
log('⚔️ Bandit Camp: PlayerAttackSpot collection not found in memory. Is the camp open in-game?'); log('⚔️ Bandit Camp: Troops still returning — waiting...');
}
}
}
} }
} catch (e) { } catch (e) {
log(`⚔️ Bandit camp error: ${e.message}`); log(`⚔️ Bandit camp error: ${e.message}`);
@@ -924,6 +936,7 @@
} }
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();