fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Grepolis Remote Control
|
// @name Grepolis Remote Control
|
||||||
// @namespace http://tampermonkey.net/
|
// @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)
|
// @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/*
|
||||||
@@ -418,55 +418,72 @@
|
|||||||
const option = parseInt(loot_option) || 1;
|
const option = parseInt(loot_option) || 1;
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
let farmCollection, relCollection;
|
let farmModels, relModels;
|
||||||
try {
|
try {
|
||||||
farmCollection = uw.MM.getOnlyCollectionByName('FarmTown');
|
farmModels = uw.MM.getOnlyCollectionByName('FarmTown')?.models;
|
||||||
relCollection = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation');
|
relModels = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation')?.models;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return { ok: false, msg: `Cannot access farm collections: ${e.message}` };
|
return { ok: false, msg: `Cannot access farm collections: ${e.message}` };
|
||||||
}
|
}
|
||||||
if (!farmCollection || !relCollection) {
|
if (!farmModels || !relModels) {
|
||||||
return { ok: false, msg: 'Farm collections not loaded yet' };
|
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 islandsSeen = new Set();
|
||||||
const polisList = []; // one town per island
|
const polisList = [];
|
||||||
for (const town of Object.values(towns)) {
|
try {
|
||||||
const iid = town.attributes?.island_id;
|
const allTowns = uw.MM.getCollections().Town[0].models;
|
||||||
if (town.attributes?.on_small_island || !iid) continue;
|
for (const town of allTowns) {
|
||||||
if (!islandsSeen.has(iid)) {
|
const { on_small_island, island_id, id } = town.attributes;
|
||||||
islandsSeen.add(iid);
|
if (on_small_island) continue;
|
||||||
polisList.push(town.id);
|
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 claimed = 0;
|
||||||
let skipped = 0;
|
let skipped = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
for (const town_id of polisList) {
|
for (let i = 0; i < polisList.length; i++) {
|
||||||
const town = uw.ITowns.towns[town_id];
|
const town_id = polisList[i];
|
||||||
if (!town) continue;
|
const town = uw.ITowns?.towns?.[town_id];
|
||||||
const ix = town.getIslandCoordinateX?.();
|
if (!town) { skipped++; continue; }
|
||||||
const iy = town.getIslandCoordinateY?.();
|
|
||||||
|
|
||||||
|
// 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 = [];
|
const readyFarms = [];
|
||||||
farmCollection.models.forEach(farm => {
|
for (const farm of farmModels) {
|
||||||
if (farm.attributes.island_x !== ix || farm.attributes.island_y !== iy) return;
|
if (farm.attributes.island_x !== ix || farm.attributes.island_y !== iy) continue;
|
||||||
relCollection.models.forEach(rel => {
|
for (const rel of relModels) {
|
||||||
if (rel.attributes.farm_town_id === farm.attributes.id &&
|
if (
|
||||||
|
rel.attributes.farm_town_id === farm.attributes.id &&
|
||||||
rel.attributes.relation_status === 1 &&
|
rel.attributes.relation_status === 1 &&
|
||||||
(rel.attributes.lootable_at || 0) <= now) {
|
(!rel.attributes.lootable_at || now >= rel.attributes.lootable_at)
|
||||||
|
) {
|
||||||
readyFarms.push({
|
readyFarms.push({
|
||||||
|
town_id,
|
||||||
farm_town_id: rel.attributes.farm_town_id,
|
farm_town_id: rel.attributes.farm_town_id,
|
||||||
relation_id: rel.id
|
relation_id: rel.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (readyFarms.length === 0) { skipped++; continue; }
|
if (readyFarms.length === 0) { skipped++; continue; }
|
||||||
|
log(`Farm: ${readyFarms.length} ready on island of town ${town_id}`);
|
||||||
|
|
||||||
for (const farm of readyFarms) {
|
for (const farm of readyFarms) {
|
||||||
try {
|
try {
|
||||||
@@ -474,26 +491,30 @@
|
|||||||
model_url: `FarmTownPlayerRelation/${farm.relation_id}`,
|
model_url: `FarmTownPlayerRelation/${farm.relation_id}`,
|
||||||
action_name: 'claim',
|
action_name: 'claim',
|
||||||
arguments: { farm_town_id: farm.farm_town_id, type: 'resources', option },
|
arguments: { farm_town_id: farm.farm_town_id, type: 'resources', option },
|
||||||
town_id
|
town_id: farm.town_id
|
||||||
});
|
});
|
||||||
claimed++;
|
claimed++;
|
||||||
} catch (e) { errors++; }
|
} catch (e) { errors++; }
|
||||||
|
|
||||||
// Random per-claim delay: 500ms – 1500ms
|
// Random per-claim delay: 500ms – 1500ms (never below 500ms)
|
||||||
await sleep(randInt(500, 1500));
|
await sleep(randInt(500, 1500));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Random between-town-group delay: 30s – 90s
|
// Refresh map icons after claiming (same as original)
|
||||||
if (polisList.indexOf(town_id) < polisList.length - 1) {
|
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);
|
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);
|
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
|
// Execute: Build
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user