From 291b909c6f5ad619b6ee4955b1234d5a07778792 Mon Sep 17 00:00:00 2001 From: haunter Date: Mon, 20 Apr 2026 00:41:01 +0300 Subject: [PATCH] nice changes --- GrepolisRemoteControl.user.js | 20 +++++++++++++++++++- routes/dashboard.py | 1 + templates/dashboard.html | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/GrepolisRemoteControl.user.js b/GrepolisRemoteControl.user.js index ceb695a..63eb267 100644 --- a/GrepolisRemoteControl.user.js +++ b/GrepolisRemoteControl.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Grepolis Remote Control // @namespace http://tampermonkey.net/ -// @version 1.0 +// @version 1.1 // @description Polls grepo.haunter-pets.top for remote commands and executes them in-game // @author Dimitrios // @match https://*.grepolis.com/game/* @@ -92,6 +92,23 @@ const bo = town.buildingOrders?.(); if (bo?.models) buildQueue = bo.models.map(m => m.attributes); } catch (e) {} + + let buildDataMap = {}; + try { + const buildDataRaw = uw.MM?.getModels?.()?.BuildingBuildData?.[town.id]?.attributes?.building_data || {}; + for (const k in buildDataRaw) { + buildDataMap[k] = { + buildable: buildDataRaw[k].buildable, + dependencies: buildDataRaw[k].dependencies_fulfilled !== false, + wood: buildDataRaw[k].resources_for?.wood || 0, + stone: buildDataRaw[k].resources_for?.stone || 0, + iron: buildDataRaw[k].resources_for?.iron || 0, + pop: buildDataRaw[k].population_for || 0 + }; + } + } catch (e) { + log(`Failed to gather build data: ${e}`); + } return { town_id: town.id, @@ -106,6 +123,7 @@ buildings, units: unitsObj, buildingOrder: buildQueue, + buildData: buildDataMap, }; }); diff --git a/routes/dashboard.py b/routes/dashboard.py index ef7e853..e62b149 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -50,6 +50,7 @@ def get_towns(): 'points': d.get('points', 0), 'god': d.get('god', None), 'build_queue': d.get('buildingOrder', []), + 'build_data': d.get('buildData', {}), }) return jsonify(towns) diff --git a/templates/dashboard.html b/templates/dashboard.html index e50ef0d..2836e5c 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -506,14 +506,29 @@ function renderBuildingDropdown() { if (!town) return; const bSelect = document.getElementById('building-select'); const bLevels = town.buildings || {}; + const bData = town.build_data || {}; bSelect.innerHTML = ''; for (const [key, nameGr] of Object.entries(BUILDING_NAMES_GR)) { const level = bLevels[key] !== undefined ? bLevels[key] : "?"; + let extraText = ''; + + if (bData[key]) { + const d = bData[key]; + if (!d.dependencies) { + extraText = ' (Απαγορεύεται / Κλειδωμένο)'; + } else { + const r = town.resources; + if (r.wood < d.wood || r.stone < d.stone || r.iron < d.iron || r.population < d.pop) { + extraText = ' (Λείπουν πόροι/πληθ.)'; + } + } + } + const option = document.createElement('option'); option.value = key; - option.textContent = `${nameGr} [Επίπεδο ${level}]`; + option.textContent = `${nameGr} [Επίπεδο ${level}]${extraText}`; bSelect.appendChild(option); } } @@ -556,7 +571,23 @@ async function sendCommand() { let payload = {}; if (type === 'build') { - payload = { building_id: document.getElementById('building-select').value }; + const bid = document.getElementById('building-select').value; + + if (town.build_data && town.build_data[bid]) { + const d = town.build_data[bid]; + if (!d.dependencies) { + return alert("Αδυναμία: Απαιτούνται άλλα κτίρια πρώτα (Το κτίριο είναι κλειδωμένο)."); + } + const r = town.resources; + if (r.wood < d.wood || r.stone < d.stone || r.iron < d.iron) { + return alert(`Αδυναμία: Δεν επαρκούν οι πόροι!\n\nΑπαιτεί:\nΞύλο: ${d.wood}\nΠέτρα: ${d.stone}\nΑσήμι: ${d.iron}`); + } + if (r.population < d.pop) { + return alert(`Αδυναμία: Δεν επαρκεί ο πληθυσμός! (Απαιτεί ${d.pop})`); + } + } + + payload = { building_id: bid }; } else { payload = { unit_id: document.getElementById('unit-select').value,