market implement

This commit is contained in:
2026-04-21 20:24:17 +03:00
parent c41eebac87
commit a6af694482
6 changed files with 107 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Grepolis Remote Control
// @namespace http://tampermonkey.net/
// @version 2.6
// @version 2.7
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game
// @author Dimitrios
// @match https://*.grepolis.com/game/*
@@ -414,7 +414,36 @@
}
// ----------------------------------------------------------------
// Poll for and execute pending commands (build + recruit in parallel)
// Execute: Market
// ----------------------------------------------------------------
async function executeMarketOffer(cmd) {
const { town_id, payload } = cmd;
const { offer, offer_type, demand, demand_type, max_delivery_time, visibility } = payload;
const town = uw.ITowns?.getTown?.(town_id) || uw.ITowns?.towns?.[town_id];
if (!town) {
return { ok: false, msg: `Town ${town_id} not found` };
}
const reactionMs = randInt(800, 2500);
log(`Waiting ${reactionMs}ms before firing market offer (reaction time)...`);
await sleep(reactionMs);
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: 'CreateOffers/' + town_id,
action_name: 'createOffer',
captcha: null,
arguments: {
offer, offer_type, demand, demand_type, max_delivery_time, visibility
}
});
await sleep(500);
return { ok: true, msg: `Market offer posted: ${offer} ${offer_type} => ${demand} ${demand_type}` };
}
// ----------------------------------------------------------------
// Poll for and execute pending commands (build + recruit + market)
// ----------------------------------------------------------------
async function pollAndExecute() {
if (paused) return;
@@ -428,9 +457,10 @@
return;
}
// Build queue and Recruit queue are now independent
// Build queue, Recruit queue and Market queue are independent
const buildCmd = cmdData.build;
const recruitCmd = cmdData.recruit;
const marketCmd = cmdData.market;
const execute = async (cmd) => {
if (!cmd) return;
@@ -439,6 +469,7 @@
try {
if (cmd.type === 'build') result = await executeBuild(cmd);
else if (cmd.type === 'recruit') result = await executeRecruit(cmd);
else if (cmd.type === 'market_offer') result = await executeMarketOffer(cmd);
else result = { ok: false, msg: `Unknown type: ${cmd.type}` };
} catch (e) {
result = { ok: false, msg: `Exception: ${e.message}` };
@@ -448,8 +479,8 @@
reportResult(cmd.id, finalStatus, result.msg);
};
// Run both queues concurrently — they do NOT block each other
await Promise.all([execute(buildCmd), execute(recruitCmd)]);
// Run concurrently — they do NOT block each other
await Promise.all([execute(buildCmd), execute(recruitCmd), execute(marketCmd)]);
}
// ----------------------------------------------------------------