This commit is contained in:
2026-04-24 22:07:00 +03:00
parent 864f7d5a4f
commit 1dc96a53ee

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Grepolis Remote Control
// @namespace http://tampermonkey.net/
// @version 3.6.6
// @version 3.6.7
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
// @author Dimitrios
// @match https://*.grepolis.com/game/*
@@ -818,60 +818,48 @@
if (farmSettings.bandit_camp_enabled) {
try {
// player_id already declared above in pollAndExecute scope
// Get any valid town_id — we just need one to make the request
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 {
// 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 || '';
// First try: MM collection (works once camp was opened in-game)
let spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
// 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({
// 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_state',
action_name: 'get_own',
captcha: null,
arguments: {},
town_id: currentTownId,
nl_init: true
})
});
const resp = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}, 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);
},
body: body.toString()
error: function() { resolve(null); }
});
} catch(e) { resolve(null); }
});
let spotData = null;
if (resp.ok) {
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) {}
}
// Fallback: try the MM collection (works if camp was opened once)
// After the gpAjax call, MM might now have the model
if (!spotData) {
const mmModel = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0];
if (mmModel) spotData = mmModel.attributes;
spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
}
}
if (!spotData) {
log(`⚔️ Bandit Camp: Could not load spot data. hash=${hash ? 'found' : 'MISSING'}. Try opening the camp window in-game once.`);
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;