recruit troop rehaul

This commit is contained in:
2026-04-20 21:26:52 +03:00
parent c34fbb6ab4
commit 3362158cdd
5 changed files with 137 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ window.fetchTowns = async function() {
if (window.selectedTownId) {
window.renderBuildQueuePreview();
window.renderBuildingDropdown();
window.renderUnitDropdown();
window.renderTownDetails();
}
} catch (e) {
@@ -114,10 +115,33 @@ window.sendCommand = async function() {
payload = { building_id };
} else {
payload = {
unit_id: document.getElementById('unit-select').value,
amount: parseInt(document.getElementById('recruit-amount').value) || 1,
};
const unit_id = document.getElementById('unit-select').value;
const amount = parseInt(document.getElementById('recruit-amount').value) || 1;
const uData = town.unit_data?.[unit_id];
// UI Validation logic
if (uData) {
const missingDeps = uData.missing_dependencies || {};
const missingKeys = Object.keys(missingDeps);
// 1. Popup if dependencies are lacking
if (missingKeys.length > 0) {
let msg = '⚠ ΑΔΥΝΑΤΗ Η ΕΚΠΑΙΔΕΥΣΗ: Λείπουν προϋποθέσεις!\n\nΑπαιτείται:\n';
for (const k of missingKeys) {
msg += `- ${missingDeps[k].name || k} (Επίπεδο ${missingDeps[k].needed_level || '1'})\n`;
}
return alert(msg);
}
// 2. Confirmation if resources are lacking for 1x
if (uData.enough_resources === false) {
if (!confirm(`❌ Δεν έχετε αρκετούς πόρους για 1x ${unit_id}!\n\nΘέλετε να προστεθεί στην ουρά αναμονής; Το σύστημα θα εκπαιδεύσει τον στρατό μόλις συγκεντρωθούν οι πόροι.`)) {
return;
}
}
}
payload = { unit_id, amount };
}
try {