agoara update
This commit is contained in:
@@ -816,6 +816,84 @@
|
||||
return { ok: true, msg: `Research ${research_id} queued` };
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Execute: Culture (Αγορά)
|
||||
// Fires a Γιορτή πόλης (party) or Παρέλαση θριάμβου (triumph)
|
||||
// celebration for a specific town via building_place/start_celebration.
|
||||
// ----------------------------------------------------------------
|
||||
async function executeCultureCommand(cmd) {
|
||||
const { town_id, payload } = cmd;
|
||||
const { celebration_type } = payload || {};
|
||||
|
||||
if (!celebration_type || !town_id) {
|
||||
return { ok: false, msg: 'Invalid culture payload: missing celebration_type or town_id' };
|
||||
}
|
||||
if (!['party', 'triumph'].includes(celebration_type)) {
|
||||
return { ok: false, msg: `Unknown celebration_type: ${celebration_type}` };
|
||||
}
|
||||
|
||||
const label = celebration_type === 'party' ? 'Γιορτή πόλης' : 'Παρέλαση θριάμβου';
|
||||
log(`[αγορά] Εκτέλεση ${label} για πόλη ${town_id}`);
|
||||
|
||||
// Validate town exists in game memory
|
||||
const town = uw.ITowns?.towns?.[town_id];
|
||||
if (!town) {
|
||||
return { ok: false, msg: `Η πόλη ${town_id} δεν βρέθηκε στη μνήμη του παιχνιδιού.` };
|
||||
}
|
||||
|
||||
// Double-check: no active celebration of this type running
|
||||
try {
|
||||
const celebModels = uw.MM.getModels()?.Celebration;
|
||||
if (celebModels) {
|
||||
const nowTs = Math.floor(Date.now() / 1000);
|
||||
for (const cel of Object.values(celebModels)) {
|
||||
const a = cel.attributes;
|
||||
if (String(a.town_id) === String(town_id)
|
||||
&& a.celebration_type === celebration_type
|
||||
&& (a.finished_at ?? 0) > nowTs) {
|
||||
return { ok: false, msg: `${label} ήδη ενεργή στην πόλη ${town_id}.` };
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) { /* model not loaded — proceed; server already validated */ }
|
||||
|
||||
const reactionMs = randInt(800, 2500);
|
||||
log(`[αγορά] Waiting ${reactionMs}ms (reaction time)...`);
|
||||
await sleep(reactionMs);
|
||||
|
||||
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||
|
||||
// Fire the Grepolis AJAX
|
||||
let ajaxSuccess = false;
|
||||
let ajaxError = null;
|
||||
|
||||
await new Promise(resolve => {
|
||||
try {
|
||||
uw.gpAjax.ajaxPost(
|
||||
'building_place',
|
||||
'start_celebration',
|
||||
{ town_id: parseInt(town_id, 10), celebration_type },
|
||||
false,
|
||||
() => { ajaxSuccess = true; resolve(); },
|
||||
(err) => { ajaxError = err ? JSON.stringify(err) : 'Άγνωστο σφάλμα AJAX'; resolve(); }
|
||||
);
|
||||
} catch (e) {
|
||||
ajaxError = String(e);
|
||||
resolve();
|
||||
}
|
||||
// 12-second safety timeout
|
||||
setTimeout(() => { if (!ajaxSuccess && !ajaxError) ajaxError = 'Timeout (12s)'; resolve(); }, 12000);
|
||||
});
|
||||
|
||||
if (ajaxSuccess) {
|
||||
log(`[αγορά] ✅ ${label} ξεκίνησε επιτυχώς (πόλη ${town_id})`);
|
||||
return { ok: true, msg: `${label} ξεκίνησε επιτυχώς.` };
|
||||
} else {
|
||||
log(`[αγορά] ❌ Αποτυχία: ${ajaxError}`);
|
||||
return { ok: false, msg: ajaxError || 'Αποτυχία εκτέλεσης εορτής.' };
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Poll for and execute pending commands (build + recruit + market)
|
||||
// ----------------------------------------------------------------
|
||||
@@ -841,6 +919,7 @@
|
||||
const researchCmd = cmdData.research;
|
||||
const farmCmd = cmdData.farm;
|
||||
const farmUpgradeCmd = cmdData.farm_upgrade;
|
||||
const cultureCmd = cmdData.culture;
|
||||
|
||||
|
||||
|
||||
@@ -865,6 +944,7 @@
|
||||
else if (cmd.type === 'research') result = await executeResearch(cmd);
|
||||
else if (cmd.type === 'farm_loot') result = await executeFarmLoot(cmd);
|
||||
else if (cmd.type === 'farm_upgrade') result = await executeFarmUpgrade(cmd);
|
||||
else if (cmd.type === 'culture') result = await executeCultureCommand(cmd);
|
||||
else result = { ok: false, msg: `Unknown type: ${cmd.type}` };
|
||||
} catch (e) {
|
||||
result = { ok: false, msg: `Exception: ${e}` };
|
||||
@@ -889,6 +969,7 @@
|
||||
await execute(researchCmd);
|
||||
await execute(farmCmd);
|
||||
await execute(farmUpgradeCmd);
|
||||
await execute(cultureCmd);
|
||||
|
||||
// Auto-farm: if enabled, claim all ready farms (no explicit command needed)
|
||||
const farmSettings = cmdData.farm_settings || {};
|
||||
|
||||
Reference in New Issue
Block a user