fix recruit numbers
This commit is contained in:
@@ -376,6 +376,9 @@ window.openUnitModal = function() {
|
|||||||
let costStr = '';
|
let costStr = '';
|
||||||
let clickable = false;
|
let clickable = false;
|
||||||
|
|
||||||
|
let maxBuild = 0;
|
||||||
|
let currentCount = town.units ? (town.units[key] || 0) : 0;
|
||||||
|
|
||||||
const requiredGod = window.UNIT_GODS ? window.UNIT_GODS[key] : null;
|
const requiredGod = window.UNIT_GODS ? window.UNIT_GODS[key] : null;
|
||||||
const isWrongGod = requiredGod && town.god !== requiredGod;
|
const isWrongGod = requiredGod && town.god !== requiredGod;
|
||||||
const isNoGod = key === 'godsent' && !town.god;
|
const isNoGod = key === 'godsent' && !town.god;
|
||||||
@@ -396,6 +399,19 @@ window.openUnitModal = function() {
|
|||||||
const i = window.fmt(data.iron || 0);
|
const i = window.fmt(data.iron || 0);
|
||||||
const pop = data.pop || 0;
|
const pop = data.pop || 0;
|
||||||
|
|
||||||
|
// Calculate max buildable
|
||||||
|
if (!isLocked) {
|
||||||
|
const tRes = town.resources || {};
|
||||||
|
const mWood = data.wood ? Math.floor((tRes.wood || 0) / data.wood) : Infinity;
|
||||||
|
const mStone = data.stone ? Math.floor((tRes.stone || 0) / data.stone) : Infinity;
|
||||||
|
const mIron = data.iron ? Math.floor((tRes.iron || 0) / data.iron) : Infinity;
|
||||||
|
const mPop = data.pop ? Math.floor((tRes.population || 0) / data.pop) : Infinity;
|
||||||
|
const mFavor = data.favor ? Math.floor((tRes.favor || 0) / data.favor) : Infinity;
|
||||||
|
|
||||||
|
maxBuild = Math.min(mWood, mStone, mIron, mPop, mFavor);
|
||||||
|
if (maxBuild === Infinity) maxBuild = 0;
|
||||||
|
}
|
||||||
|
|
||||||
let t = data.build_time || 0;
|
let t = data.build_time || 0;
|
||||||
let tStr = `${t}s`;
|
let tStr = `${t}s`;
|
||||||
if (t > 60) {
|
if (t > 60) {
|
||||||
@@ -410,7 +426,7 @@ window.openUnitModal = function() {
|
|||||||
|
|
||||||
if (isLocked) {
|
if (isLocked) {
|
||||||
statusClass = 'locked'; statusLabel = '🔒 Κλειδωμένο'; cardClass = 'bld-locked';
|
statusClass = 'locked'; statusLabel = '🔒 Κλειδωμένο'; cardClass = 'bld-locked';
|
||||||
} else if (data.enough_resources === false) {
|
} else if (maxBuild <= 0) {
|
||||||
statusClass = 'no-resources'; statusLabel = '❌ Λείπουν Πόροι';
|
statusClass = 'no-resources'; statusLabel = '❌ Λείπουν Πόροι';
|
||||||
} else {
|
} else {
|
||||||
statusClass = 'can-build'; statusLabel = '✅ Διαθέσιμο';
|
statusClass = 'can-build'; statusLabel = '✅ Διαθέσιμο';
|
||||||
@@ -423,11 +439,13 @@ window.openUnitModal = function() {
|
|||||||
|
|
||||||
const onclick = clickable ? `onclick="window.selectUnit('${key}', '${nameGr}')"` : '';
|
const onclick = clickable ? `onclick="window.selectUnit('${key}', '${nameGr}')"` : '';
|
||||||
|
|
||||||
catHtml += `<div class="bld-card ${cardClass}${isSelected ? ' bld-selected' : ''}" ${onclick} style="width:140px; justify-content:flex-start;">
|
catHtml += `<div class="bld-card ${cardClass}${isSelected ? ' bld-selected' : ''}" ${onclick} style="width:140px; justify-content:flex-start; position:relative;">
|
||||||
<span class="bld-icon">${icon}</span>
|
<span class="bld-icon" style="font-size:2rem; margin-bottom: 2px;">${icon}</span>
|
||||||
<span class="bld-name" style="margin-top:6px; font-size:0.85rem;">${nameGr}</span>
|
<div style="position:absolute; top:4px; right:6px; font-weight:bold; font-size:1.1rem; text-shadow: 1px 1px 2px #000; color:#fff;">${currentCount}</div>
|
||||||
<span class="bld-status ${statusClass}">${statusLabel}</span>
|
<div style="position:absolute; top:24px; right:6px; font-weight:bold; font-size:0.85rem; color:#c8a44a; text-shadow: 1px 1px 2px #000;">+${maxBuild}</div>
|
||||||
<span class="bld-cost" style="font-size:0.65rem;">${costStr}</span>
|
<span class="bld-name" style="margin-top:2px; font-size:0.85rem;">${nameGr}</span>
|
||||||
|
<span class="bld-status ${statusClass}" style="margin:2px 0;">${statusLabel}</span>
|
||||||
|
<span class="bld-cost" style="font-size:0.65rem; color:#bbb; text-align:center;">${costStr}</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user