nice changes
This commit is contained in:
@@ -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/*
|
||||
@@ -93,6 +93,23 @@
|
||||
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,
|
||||
town_name: town.name,
|
||||
@@ -106,6 +123,7 @@
|
||||
buildings,
|
||||
units: unitsObj,
|
||||
buildingOrder: buildQueue,
|
||||
buildData: buildDataMap,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user