This commit is contained in:
2026-04-26 01:45:26 +03:00
parent 8fd711f5a1
commit b577c95f7c
4 changed files with 47 additions and 35 deletions

View File

@@ -792,47 +792,59 @@
async function executeScanMarket(cmd) { async function executeScanMarket(cmd) {
const { town_id } = cmd; const { town_id } = cmd;
const reactionMs = randInt(1500, 3000); await sleep(randInt(1500, 3000));
log(`Waiting ${reactionMs}ms before scanning market...`);
await sleep(reactionMs);
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' }; if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
return new Promise((resolve) => { return new Promise((resolve) => {
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', { let intercepted = false;
model_url: 'BuildingMarket', let timeoutId;
action_name: 'getData',
arguments: { // Wrap gpAjax to intercept ANY response that looks like market data
limit: 20, const origAjaxPost = uw.gpAjax.ajaxPost.bind(uw.gpAjax);
offset: 0, uw.gpAjax.ajaxPost = function(controller, action, params, loader, callbacks) {
demand_type: 'all_but_gold', const wrappedCallbacks = callbacks && typeof callbacks === 'object' ? {
offer_type: 'all_but_gold', success: function(resp) {
max_ratio: 3, // Market data has an 'offers' array
max_delivery_time: 172800, if (!intercepted && resp && resp.offers) {
visibility: 2, intercepted = true;
order_by: 'ratio', clearTimeout(timeoutId);
order_direction: 'desc' uw.gpAjax.ajaxPost = origAjaxPost; // restore
}, fetch(`${BASE_URL}/api/market_data?player_id=${uw.Game.player_id}`, {
town_id: town_id,
nl_init: true
}, false, {
success: async function(resp) {
try {
// Send the data back to our backend
await fetch(`${BASE_URL}/api/market_data?player_id=${uw.Game.player_id}`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(resp) body: JSON.stringify(resp)
}); })
resolve({ ok: true, msg: 'Market scanned and data uploaded' }); .then(() => resolve({ ok: true, msg: `Market scanned: ${resp.offers.length} offers` }))
} catch (e) { .catch(e => resolve({ ok: false, msg: 'Upload failed: ' + e }));
resolve({ ok: false, msg: 'Failed to upload market data: ' + e });
} }
if (callbacks.success) callbacks.success(resp);
}, },
error: function() { error: callbacks.error
resolve({ ok: false, msg: 'Failed to fetch market data from game' }); } : callbacks;
} return origAjaxPost(controller, action, params, loader, wrappedCallbacks);
};
// Trigger the getData
origAjaxPost('frontend_bridge', 'execute', {
model_url: 'BuildingMarket',
action_name: 'getData',
arguments: {
limit: 20, offset: 0,
demand_type: 'all_but_gold', offer_type: 'all_but_gold',
max_ratio: 3, max_delivery_time: 172800,
visibility: 2, order_by: 'ratio', order_direction: 'desc'
},
town_id: town_id,
nl_init: true
}); });
// Timeout after 15 seconds
timeoutId = setTimeout(() => {
if (!intercepted) {
uw.gpAjax.ajaxPost = origAjaxPost; // restore
resolve({ ok: false, msg: 'Market scan timed out' });
}
}, 15000);
}); });
} }

View File

@@ -77,7 +77,7 @@ window.updateClientStatus = function(online) {
el.className = 'conn-badge offline'; el.className = 'conn-badge offline';
} }
// Enable/disable the Send button // Enable/disable the Send button
const btn = document.querySelector('#command-form-wrap .btn-gold'); const btn = document.getElementById('btn-send');
if (btn) { if (btn) {
btn.disabled = !online; btn.disabled = !online;
btn.title = online ? '' : 'Script is offline — cannot send commands'; btn.title = online ? '' : 'Script is offline — cannot send commands';

View File

@@ -12,7 +12,7 @@ window.onCmdTypeChange = function() {
}; };
// Building emoji icons for the visual grid // Building emoji icons for the visual grid
const BUILDING_ICONS = { window.BUILDING_ICONS = {
main: '🏛️', storage: '🏚️', farm: '🌾', academy: '📜', main: '🏛️', storage: '🏚️', farm: '🌾', academy: '📜',
temple: '⛩️', barracks: '⚔️', docks: '⚓', market: '🛒', temple: '⛩️', barracks: '⚔️', docks: '⚓', market: '🛒',
hide: '🕳️', lumber: '🪵', stoner: '🪨', ironer: '⛏️', wall: '🧱' hide: '🕳️', lumber: '🪵', stoner: '🪨', ironer: '⛏️', wall: '🧱'
@@ -35,7 +35,7 @@ window.openBuildingModal = function() {
grid.innerHTML = Object.entries(window.BUILDING_NAMES_GR).map(([key, nameGr]) => { grid.innerHTML = Object.entries(window.BUILDING_NAMES_GR).map(([key, nameGr]) => {
const level = bLevels[key] !== undefined ? bLevels[key] : '?'; const level = bLevels[key] !== undefined ? bLevels[key] : '?';
const data = bData[key]; const data = bData[key];
const icon = BUILDING_ICONS[key] || '🏗️'; const icon = window.BUILDING_ICONS[key] || '🏗️';
const isSelected = key === window.selectedBuildingId; const isSelected = key === window.selectedBuildingId;
if (!data) { if (!data) {

View File

@@ -223,7 +223,7 @@
<input type="number" id="recruit-amount" value="1" min="1" max="9999" style="width:80px;"> <input type="number" id="recruit-amount" value="1" min="1" max="9999" style="width:80px;">
</div> </div>
<button class="btn btn-gold" onclick="sendCommand()">Send ⚡</button> <button id="btn-send" class="btn btn-gold" onclick="window.sendCommand()">Send ⚡</button>
</div> </div>
<div id="build-queue-preview"></div> <div id="build-queue-preview"></div>