fix farm resourses
This commit is contained in:
@@ -78,7 +78,8 @@ async function executeFarmUpgrade(cmd) {
|
|||||||
isLocked ? unlocked++ : upgraded++;
|
isLocked ? unlocked++ : upgraded++;
|
||||||
} catch (e) { errors++; }
|
} catch (e) { errors++; }
|
||||||
|
|
||||||
await sleep(randInt(1200, 2500));
|
await sleep(randInt(4000, 10000));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,17 +205,10 @@ async function executeFarmLoot(cmd) {
|
|||||||
claimed++;
|
claimed++;
|
||||||
} catch (e) { errors++; }
|
} catch (e) { errors++; }
|
||||||
|
|
||||||
await sleep(randInt(1000, 2200));
|
await sleep(randInt(500, 1500));
|
||||||
}
|
}
|
||||||
|
|
||||||
try { uw.WMap.removeFarmTownLootCooldownIconAndRefreshLootTimers(); } catch (e) {}
|
try { uw.WMap.removeFarmTownLootCooldownIconAndRefreshLootTimers(); } catch (e) {}
|
||||||
|
|
||||||
if (i < islandList.length - 1) {
|
|
||||||
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
|
||||||
const gap = randInt(30000, 90000);
|
|
||||||
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} islands skipped, ${errors} errors` };
|
return { ok: true, msg: `Farm done: ${claimed} claimed, ${skipped} islands skipped, ${errors} errors` };
|
||||||
|
|||||||
@@ -9,6 +9,26 @@
|
|||||||
let farmLootRunning = false;
|
let farmLootRunning = false;
|
||||||
let lastKnownFarmSettings = {};
|
let lastKnownFarmSettings = {};
|
||||||
|
|
||||||
|
// Loot option → cooldown ms (matches game's farm timer options)
|
||||||
|
const LOOT_TIMINGS = { 1: 300000, 2: 1200000, 3: 5400000, 4: 14400000 };
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// scheduleNextFarm — fires autoFarmLoop once, then reschedules
|
||||||
|
// Delay = loot_option cooldown + random 30-120s human jitter.
|
||||||
|
// This mirrors ModernBot's pattern: run exactly when farms are ready.
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
function scheduleNextFarm() {
|
||||||
|
const option = lastKnownFarmSettings.loot_option || 1;
|
||||||
|
const baseMs = LOOT_TIMINGS[option] || 300000;
|
||||||
|
const jitterMs = randInt(30000, 120000); // +30 to +120 s
|
||||||
|
const totalMs = baseMs + jitterMs;
|
||||||
|
log(`⏰ Next auto-farm in ${(totalMs / 60000).toFixed(1)} min (option ${option} + ${(jitterMs/1000).toFixed(0)}s jitter)`);
|
||||||
|
setTimeout(async () => {
|
||||||
|
await autoFarmLoop();
|
||||||
|
scheduleNextFarm();
|
||||||
|
}, totalMs);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// pollAndExecute — runs every 8–18 s (main command loop)
|
// pollAndExecute — runs every 8–18 s (main command loop)
|
||||||
// Handles builds, recruits, market, research, explicit farm commands.
|
// Handles builds, recruits, market, research, explicit farm commands.
|
||||||
@@ -196,7 +216,7 @@ function boot() {
|
|||||||
setTimeout(pushState, 5000);
|
setTimeout(pushState, 5000);
|
||||||
jitterLoop(pushState, 60000, 120000); // state sync every 1–2 min
|
jitterLoop(pushState, 60000, 120000); // state sync every 1–2 min
|
||||||
jitterLoop(pollAndExecute, 8000, 18000); // command poll every 8–18 s
|
jitterLoop(pollAndExecute, 8000, 18000); // command poll every 8–18 s
|
||||||
jitterLoop(autoFarmLoop, 60000, 120000); // auto-farm every 1–2 min
|
scheduleNextFarm(); // auto-farm timer-based (loot_option + 30–120s)
|
||||||
jitterLoop(autoBootcampLoop, 720000, 1320000); // bootcamp every 12–22 min
|
jitterLoop(autoBootcampLoop, 720000, 1320000); // bootcamp every 12–22 min
|
||||||
jitterLoop(autoRuralTradeLoop, 1500000, 2700000); // rural trade every 25–45 min
|
jitterLoop(autoRuralTradeLoop, 1500000, 2700000); // rural trade every 25–45 min
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user