refacto: Changing display of revenues per planet by default + fixing WS for revenues
This commit is contained in:
+22
-1
@@ -1,7 +1,7 @@
|
||||
import { pool } from "./pools.js";
|
||||
import { loadConfigFile, getConfig } from "../configLoader.js";
|
||||
import { computeWorldSeedState } from "../worldSeed.js";
|
||||
import { nextNoonUtc, resetAllUserActions } from "./usersDb.js";
|
||||
import { nextNoonUtc, resetAllUserActions, getUsersByIds } from "./usersDb.js";
|
||||
|
||||
let lastSeedSlot = null;
|
||||
|
||||
@@ -455,6 +455,27 @@ export async function getActivePlayerIds(worldSeed) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns per-team sorted lists of usernames who have been active this seed epoch.
|
||||
* Uses a two-step lookup because users live in a separate database.
|
||||
*/
|
||||
export async function getActivePlayerNames(worldSeed) {
|
||||
const playerIds = await getActivePlayerIds(worldSeed);
|
||||
const allIds = [...playerIds.blue, ...playerIds.red];
|
||||
const users = await getUsersByIds(allIds);
|
||||
const teamOf = {};
|
||||
for (const id of playerIds.blue) teamOf[id] = "blue";
|
||||
for (const id of playerIds.red) teamOf[id] = "red";
|
||||
const result = { blue: [], red: [] };
|
||||
for (const user of users) {
|
||||
const team = teamOf[user.id];
|
||||
if (team) result[team].push(user.username);
|
||||
}
|
||||
result.blue.sort((a, b) => a.localeCompare(b));
|
||||
result.red.sort((a, b) => a.localeCompare(b));
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── Team action quota (daily, independent of world seed) ─────────────────────
|
||||
|
||||
export async function getTeamActionsRow(team) {
|
||||
|
||||
@@ -3,24 +3,47 @@ import {
|
||||
getElementBonus,
|
||||
getMilitaryDeductions,
|
||||
getActivePlayerCounts,
|
||||
getActivePlayerNames,
|
||||
getVictoryPoints,
|
||||
getGridCells,
|
||||
} from "./db/gameDb.js";
|
||||
import { getConfig } from "./configLoader.js";
|
||||
import { computeTeamIncome, computeTeamMilitaryPower } from "./helpers/economy.js";
|
||||
|
||||
export async function buildRealtimeSnapshot(worldSeed) {
|
||||
const [scores, elementBonus, militaryDeductions, activePlayers, victoryPoints] = await Promise.all([
|
||||
const [scores, elementBonus, militaryDeductions, activePlayers, playerNames, victoryPoints, rows] = await Promise.all([
|
||||
getEconScores(worldSeed),
|
||||
getElementBonus(worldSeed),
|
||||
getMilitaryDeductions(worldSeed),
|
||||
getActivePlayerCounts(worldSeed),
|
||||
getActivePlayerNames(worldSeed),
|
||||
getVictoryPoints(),
|
||||
getGridCells(worldSeed),
|
||||
]);
|
||||
|
||||
const cfg = getConfig();
|
||||
const resourceWorth = cfg.resourceWorth ?? { common: {}, rare: {} };
|
||||
const militaryPowerCfg = cfg.militaryPower ?? {};
|
||||
|
||||
const incomePerSecond = {
|
||||
blue: computeTeamIncome("blue", rows, resourceWorth),
|
||||
red: computeTeamIncome("red", rows, resourceWorth),
|
||||
};
|
||||
|
||||
const militaryPowerGross = {
|
||||
blue: computeTeamMilitaryPower("blue", rows, militaryPowerCfg),
|
||||
red: computeTeamMilitaryPower("red", rows, militaryPowerCfg),
|
||||
};
|
||||
|
||||
return {
|
||||
worldSeed,
|
||||
scores,
|
||||
elementBonus,
|
||||
militaryDeductions,
|
||||
activePlayers,
|
||||
playerNames,
|
||||
victoryPoints,
|
||||
incomePerSecond,
|
||||
militaryPowerGross,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user