fix: Economy factors taken in charge in websockets
This commit is contained in:
@@ -70,6 +70,24 @@ const ELEMENT_LABEL_TO_KEY = Object.fromEntries(
|
||||
|
||||
// ── Income computation ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Population-based income multiplier (mirrors public/src/economy.js).
|
||||
* Base factor = billions / 10, plus an efficiency boost for smaller populations:
|
||||
* 0–10 B → ×10, 10–100 B → ×5, 100–1000 B → ×2.5, >1000 B → ×1
|
||||
*
|
||||
* @param {number} billions
|
||||
* @returns {number}
|
||||
*/
|
||||
function populationFactor(billions) {
|
||||
const base = billions / 10;
|
||||
let boost;
|
||||
if (billions < 10) boost = 10;
|
||||
else if (billions < 100) boost = 5;
|
||||
else if (billions < 1000) boost = 2.5;
|
||||
else boost = 1;
|
||||
return base * boost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute total income per second for a team from DB grid rows.
|
||||
*
|
||||
@@ -83,14 +101,15 @@ export function computeTeamIncome(team, rows, resourceWorth) {
|
||||
for (const row of rows) {
|
||||
if (row.discovered_by !== team) continue;
|
||||
if (!row.has_planet || !row.planet_json) continue;
|
||||
const { naturalResources } = row.planet_json;
|
||||
const { naturalResources, population } = row.planet_json;
|
||||
if (!naturalResources) continue;
|
||||
const popFactor = population ? populationFactor(population.billions) : 1;
|
||||
for (const [label, pct] of Object.entries(naturalResources)) {
|
||||
const info = LABEL_TO_RESOURCE.get(label);
|
||||
if (!info) continue;
|
||||
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
|
||||
if (worth === 0) continue;
|
||||
total += (pct / 100) * worth;
|
||||
total += (pct / 100) * worth * popFactor;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
|
||||
Reference in New Issue
Block a user