nice changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Grepolis Remote Control
|
// @name Grepolis Remote Control
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 1.0
|
// @version 1.1
|
||||||
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game
|
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game
|
||||||
// @author Dimitrios
|
// @author Dimitrios
|
||||||
// @match https://*.grepolis.com/game/*
|
// @match https://*.grepolis.com/game/*
|
||||||
@@ -92,6 +92,23 @@
|
|||||||
const bo = town.buildingOrders?.();
|
const bo = town.buildingOrders?.();
|
||||||
if (bo?.models) buildQueue = bo.models.map(m => m.attributes);
|
if (bo?.models) buildQueue = bo.models.map(m => m.attributes);
|
||||||
} catch (e) {}
|
} 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 {
|
return {
|
||||||
town_id: town.id,
|
town_id: town.id,
|
||||||
@@ -106,6 +123,7 @@
|
|||||||
buildings,
|
buildings,
|
||||||
units: unitsObj,
|
units: unitsObj,
|
||||||
buildingOrder: buildQueue,
|
buildingOrder: buildQueue,
|
||||||
|
buildData: buildDataMap,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ def get_towns():
|
|||||||
'points': d.get('points', 0),
|
'points': d.get('points', 0),
|
||||||
'god': d.get('god', None),
|
'god': d.get('god', None),
|
||||||
'build_queue': d.get('buildingOrder', []),
|
'build_queue': d.get('buildingOrder', []),
|
||||||
|
'build_data': d.get('buildData', {}),
|
||||||
})
|
})
|
||||||
return jsonify(towns)
|
return jsonify(towns)
|
||||||
|
|
||||||
|
|||||||
@@ -506,14 +506,29 @@ function renderBuildingDropdown() {
|
|||||||
if (!town) return;
|
if (!town) return;
|
||||||
const bSelect = document.getElementById('building-select');
|
const bSelect = document.getElementById('building-select');
|
||||||
const bLevels = town.buildings || {};
|
const bLevels = town.buildings || {};
|
||||||
|
const bData = town.build_data || {};
|
||||||
|
|
||||||
bSelect.innerHTML = '';
|
bSelect.innerHTML = '';
|
||||||
|
|
||||||
for (const [key, nameGr] of Object.entries(BUILDING_NAMES_GR)) {
|
for (const [key, nameGr] of Object.entries(BUILDING_NAMES_GR)) {
|
||||||
const level = bLevels[key] !== undefined ? bLevels[key] : "?";
|
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');
|
const option = document.createElement('option');
|
||||||
option.value = key;
|
option.value = key;
|
||||||
option.textContent = `${nameGr} [Επίπεδο ${level}]`;
|
option.textContent = `${nameGr} [Επίπεδο ${level}]${extraText}`;
|
||||||
bSelect.appendChild(option);
|
bSelect.appendChild(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -556,7 +571,23 @@ async function sendCommand() {
|
|||||||
let payload = {};
|
let payload = {};
|
||||||
|
|
||||||
if (type === 'build') {
|
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 {
|
} else {
|
||||||
payload = {
|
payload = {
|
||||||
unit_id: document.getElementById('unit-select').value,
|
unit_id: document.getElementById('unit-select').value,
|
||||||
|
|||||||
Reference in New Issue
Block a user