servername,captca,timestamp,reserve resources
This commit is contained in:
@@ -111,13 +111,48 @@ window.renderTownDetails = function() {
|
||||
return 'color: #fff;';
|
||||
};
|
||||
|
||||
// Calculate resources reserved in the bot's pending queues
|
||||
let reservedWood = 0, reservedStone = 0, reservedIron = 0;
|
||||
if (window.cmds) {
|
||||
window.cmds.forEach(cmd => {
|
||||
if ((cmd.status === 'pending' || cmd.status === 'executing') && cmd.town_id == t.town_id) {
|
||||
if (cmd.type === 'build' && t.build_data) {
|
||||
const p = typeof cmd.payload === 'string' ? JSON.parse(cmd.payload) : cmd.payload;
|
||||
const cost = t.build_data[p.building_id];
|
||||
if (cost) {
|
||||
reservedWood += cost.wood || 0;
|
||||
reservedStone += cost.stone || 0;
|
||||
reservedIron += cost.iron || 0;
|
||||
}
|
||||
} else if (cmd.type === 'recruit' && t.unit_data) {
|
||||
const p = typeof cmd.payload === 'string' ? JSON.parse(cmd.payload) : cmd.payload;
|
||||
const amt = parseInt(p.amount) || 1;
|
||||
const cost = t.unit_data[p.unit_id];
|
||||
if (cost) {
|
||||
reservedWood += (cost.wood || 0) * amt;
|
||||
reservedStone += (cost.stone || 0) * amt;
|
||||
reservedIron += (cost.iron || 0) * amt;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const resHtml = (actual, reserved) => {
|
||||
let base = `<strong style="${getCol(actual)}">${window.fmt(actual)}</strong>`;
|
||||
if (reserved > 0) {
|
||||
base += ` <span style="color:#ff6666; font-size:0.75rem;">(-${window.fmt(reserved)})</span>`;
|
||||
}
|
||||
return base;
|
||||
};
|
||||
|
||||
const capFmt = (t.resources.storage != null && t.resources.storage !== '') ? window.fmt(t.resources.storage) : '?';
|
||||
|
||||
document.getElementById('td-resources').innerHTML = `
|
||||
<div style="font-size:0.75rem; color:#aaa; margin-bottom: 4px;">Χωρητικότητα: <strong style="color:#eee">${capFmt}</strong></div>
|
||||
<div>${window.RES_ICONS.wood} Ξύλο: <strong style="${getCol(t.resources.wood)}">${window.fmt(t.resources.wood)}</strong></div>
|
||||
<div>${window.RES_ICONS.stone} Πέτρα: <strong style="${getCol(t.resources.stone)}">${window.fmt(t.resources.stone)}</strong></div>
|
||||
<div>${window.RES_ICONS.iron} Ασήμι: <strong style="${getCol(t.resources.iron)}">${window.fmt(t.resources.iron)}</strong></div>
|
||||
<div>${window.RES_ICONS.wood} Ξύλο: ${resHtml(t.resources.wood, reservedWood)}</div>
|
||||
<div>${window.RES_ICONS.stone} Πέτρα: ${resHtml(t.resources.stone, reservedStone)}</div>
|
||||
<div>${window.RES_ICONS.iron} Ασήμι: ${resHtml(t.resources.iron, reservedIron)}</div>
|
||||
<div style="margin-top: 6px;">${window.RES_ICONS.pop} Πληθυσμός: <strong style="color:#fff">${t.resources.population}</strong></div>
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user