This commit is contained in:
2026-04-23 18:59:57 +03:00
parent 54ec9a3db6
commit 73037c510c

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Grepolis Remote Control
// @namespace http://tampermonkey.net/
// @version 3.3
// @version 3.4
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
// @author Dimitrios
// @match https://*.grepolis.com/game/*
@@ -418,55 +418,72 @@
const option = parseInt(loot_option) || 1;
const now = Math.floor(Date.now() / 1000);
let farmCollection, relCollection;
let farmModels, relModels;
try {
farmCollection = uw.MM.getOnlyCollectionByName('FarmTown');
relCollection = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation');
farmModels = uw.MM.getOnlyCollectionByName('FarmTown')?.models;
relModels = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation')?.models;
} catch (e) {
return { ok: false, msg: `Cannot access farm collections: ${e.message}` };
}
if (!farmCollection || !relCollection) {
return { ok: false, msg: 'Farm collections not loaded yet' };
if (!farmModels || !relModels) {
return { ok: false, msg: 'Farm collections not loaded yet — open island view first' };
}
const towns = uw.ITowns?.towns || {};
// Build polis list: one town per island, using MM (all towns, not just visible)
const islandsSeen = new Set();
const polisList = []; // one town per island
for (const town of Object.values(towns)) {
const iid = town.attributes?.island_id;
if (town.attributes?.on_small_island || !iid) continue;
if (!islandsSeen.has(iid)) {
islandsSeen.add(iid);
polisList.push(town.id);
const polisList = [];
try {
const allTowns = uw.MM.getCollections().Town[0].models;
for (const town of allTowns) {
const { on_small_island, island_id, id } = town.attributes;
if (on_small_island) continue;
if (!islandsSeen.has(island_id)) {
islandsSeen.add(island_id);
polisList.push(id);
}
}
} catch (e) {
return { ok: false, msg: `Cannot build town list: ${e.message}` };
}
log(`Farm: processing ${polisList.length} islands with option=${option}`);
let claimed = 0;
let skipped = 0;
let errors = 0;
for (const town_id of polisList) {
const town = uw.ITowns.towns[town_id];
if (!town) continue;
const ix = town.getIslandCoordinateX?.();
const iy = town.getIslandCoordinateY?.();
for (let i = 0; i < polisList.length; i++) {
const town_id = polisList[i];
const town = uw.ITowns?.towns?.[town_id];
if (!town) { skipped++; continue; }
// Use the same method as the original script
const ix = town.getIslandCoordinateX();
const iy = town.getIslandCoordinateY();
if (ix == null || iy == null) { skipped++; continue; }
// Find ready farms on this island (mirrors original getLootableFarms exactly)
const readyFarms = [];
farmCollection.models.forEach(farm => {
if (farm.attributes.island_x !== ix || farm.attributes.island_y !== iy) return;
relCollection.models.forEach(rel => {
if (rel.attributes.farm_town_id === farm.attributes.id &&
for (const farm of farmModels) {
if (farm.attributes.island_x !== ix || farm.attributes.island_y !== iy) continue;
for (const rel of relModels) {
if (
rel.attributes.farm_town_id === farm.attributes.id &&
rel.attributes.relation_status === 1 &&
(rel.attributes.lootable_at || 0) <= now) {
(!rel.attributes.lootable_at || now >= rel.attributes.lootable_at)
) {
readyFarms.push({
town_id,
farm_town_id: rel.attributes.farm_town_id,
relation_id: rel.id
});
}
});
});
}
}
if (readyFarms.length === 0) { skipped++; continue; }
log(`Farm: ${readyFarms.length} ready on island of town ${town_id}`);
for (const farm of readyFarms) {
try {
@@ -474,26 +491,30 @@
model_url: `FarmTownPlayerRelation/${farm.relation_id}`,
action_name: 'claim',
arguments: { farm_town_id: farm.farm_town_id, type: 'resources', option },
town_id
town_id: farm.town_id
});
claimed++;
} catch (e) { errors++; }
// Random per-claim delay: 500ms 1500ms
// Random per-claim delay: 500ms 1500ms (never below 500ms)
await sleep(randInt(500, 1500));
}
// Random between-town-group delay: 30s 90s
if (polisList.indexOf(town_id) < polisList.length - 1) {
// Refresh map icons after claiming (same as original)
try { uw.WMap.removeFarmTownLootCooldownIconAndRefreshLootTimers(); } catch(e) {}
// Random between-island delay: 30s 90s (only if more islands remain)
if (i < polisList.length - 1) {
const gap = randInt(30000, 90000);
log(`Farm: done with town ${town_id}. Waiting ${(gap/1000).toFixed(0)}s before next...`);
log(`Farm: island done. Waiting ${(gap/1000).toFixed(0)}s before next island...`);
await sleep(gap);
}
}
return { ok: true, msg: `Farm done: ${claimed} claimed, ${skipped} towns skipped, ${errors} errors` };
return { ok: true, msg: `Farm done: ${claimed} claimed, ${skipped} islands skipped, ${errors} errors` };
}
// ----------------------------------------------------------------
// Execute: Build
// ----------------------------------------------------------------