fix: Fixing the MP power bonus + seed maintenance

This commit is contained in:
gauvainboiche
2026-04-03 14:25:19 +02:00
parent b11446cf56
commit d345c025c0
11 changed files with 349 additions and 132 deletions
+19 -18
View File
@@ -22,9 +22,10 @@ const COLOR_OPPONENT_GREY = "rgba(95, 98, 110, 0.72)";
export const GAME_CONFIG = {
dailyActionQuota: 100,
actionsResetIntervalHours: 12,
actionsResetIntervalSeconds: 3600,
databaseWipeoutIntervalSeconds: 21600,
configReloadIntervalSeconds: 30,
timingEpochSec: 0,
worldSeed: "",
seedPeriodEndsAtUtc: "",
elementWorth: {},
@@ -288,11 +289,12 @@ export function isOwnTile(key) { const m = cellMeta(key); return m !== nul
export function applyConfigPayload(data) {
GAME_CONFIG.dailyActionQuota = Number(data.dailyActionQuota) || 100;
if (data.actionsResetIntervalHours) {
GAME_CONFIG.actionsResetIntervalHours = Number(data.actionsResetIntervalHours) || 12;
if (data.actionsResetIntervalSeconds) {
GAME_CONFIG.actionsResetIntervalSeconds = Number(data.actionsResetIntervalSeconds) || 3600;
}
GAME_CONFIG.databaseWipeoutIntervalSeconds = Number(data.databaseWipeoutIntervalSeconds) || 21600;
GAME_CONFIG.configReloadIntervalSeconds = Math.max(5, Number(data.configReloadIntervalSeconds) || 30);
GAME_CONFIG.timingEpochSec = Number(data.timingEpochSec) || 0;
GAME_CONFIG.worldSeed = String(data.worldSeed ?? "");
GAME_CONFIG.seedPeriodEndsAtUtc = String(data.seedPeriodEndsAtUtc ?? "");
if (data.elementWorth && typeof data.elementWorth === "object") {
@@ -340,20 +342,16 @@ export function updateResetCountdown() {
/** Computes time until next actions-reset based on the configured interval and updates the display. */
export function updateActionsResetCountdown() {
if (!actionsResetCountdownEl) return;
const intervalHours = GAME_CONFIG.actionsResetIntervalHours ?? 12;
const now = Date.now();
const date = new Date(now);
const utcHours = date.getUTCHours();
const slotsPassed = Math.floor(utcHours / intervalHours);
const nextSlotHour = (slotsPassed + 1) * intervalHours;
const next = nextSlotHour < 24
? Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), nextSlotHour, 0, 0, 0)
: Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + 1, 0, 0, 0, 0);
const diff = next - now;
const s = Math.floor(diff / 1000);
const hh = Math.floor(s / 3600);
const mm = Math.floor((s % 3600) / 60);
const ss = s % 60;
const intervalSec = GAME_CONFIG.actionsResetIntervalSeconds ?? 3600;
const epochSec = GAME_CONFIG.timingEpochSec ?? 0;
const nowSec = Math.floor(Date.now() / 1000);
const elapsed = Math.max(0, nowSec - epochSec);
const slot = Math.floor(elapsed / intervalSec);
const nextResetSec = epochSec + (slot + 1) * intervalSec;
const diff = nextResetSec - nowSec;
const hh = Math.floor(diff / 3600);
const mm = Math.floor((diff % 3600) / 60);
const ss = diff % 60;
actionsResetCountdownEl.textContent =
String(hh).padStart(2, "0") + ":" +
String(mm).padStart(2, "0") + ":" +
@@ -1318,13 +1316,16 @@ export async function refreshFromServer() {
const seedChanged = await fetchConfig();
if (seedChanged) {
resetEconScores();
loadEconScores();
details.textContent = "Les stats sont vides jusqu'au clic sur une tuile.";
details.classList.add("details--hidden");
hint.textContent = "Le monde a été réinitilisaté. Vous pouvez cliquer sur une tuile pour recommencer le jeu.";
}
await fetchGridForSeed(seedStr);
await fetchAndApplyActivePlayers();
await loadPlayerNames();
await loadEconScores();
await loadElementBonus();
await loadMilitaryDeductions();
updateEconomyDisplay();
draw();
refreshCursorFromLast();