refacto: Cooldown is now user-set
This commit is contained in:
@@ -29,6 +29,15 @@ export async function initGameSchema() {
|
||||
PRIMARY KEY (world_seed, team)
|
||||
);
|
||||
`);
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS user_cooldowns (
|
||||
world_seed TEXT NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
team TEXT NOT NULL CHECK (team IN ('blue', 'red')),
|
||||
last_reveal TIMESTAMPTZ,
|
||||
PRIMARY KEY (world_seed, user_id)
|
||||
);
|
||||
`);
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS team_econ_scores (
|
||||
world_seed TEXT NOT NULL,
|
||||
@@ -112,6 +121,7 @@ export async function ensureSeedEpoch() {
|
||||
}
|
||||
await pool.query("TRUNCATE grid_cells RESTART IDENTITY");
|
||||
await pool.query("DELETE FROM team_cooldowns WHERE world_seed != $1", [worldSeed]);
|
||||
await pool.query("DELETE FROM user_cooldowns WHERE world_seed != $1", [worldSeed]);
|
||||
await pool.query("DELETE FROM team_econ_scores WHERE world_seed != $1", [worldSeed]);
|
||||
await pool.query("DELETE FROM team_element_bonus WHERE world_seed != $1", [worldSeed]);
|
||||
console.log(`[world] Slot ${lastSeedSlot} → ${seedSlot}; grid wiped, old cooldowns cleared.`);
|
||||
@@ -170,6 +180,25 @@ export async function upsertTeamCooldown(worldSeed, team) {
|
||||
);
|
||||
}
|
||||
|
||||
// ── User cooldowns (per-user, replaces team-wide cooldown for reveal) ─────────
|
||||
|
||||
export async function getUserCooldown(worldSeed, userId) {
|
||||
const { rows } = await pool.query(
|
||||
`SELECT last_reveal FROM user_cooldowns WHERE world_seed = $1 AND user_id = $2`,
|
||||
[worldSeed, userId]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
export async function upsertUserCooldown(worldSeed, userId, team) {
|
||||
await pool.query(
|
||||
`INSERT INTO user_cooldowns (world_seed, user_id, team, last_reveal)
|
||||
VALUES ($1, $2, $3, NOW())
|
||||
ON CONFLICT (world_seed, user_id) DO UPDATE SET last_reveal = NOW()`,
|
||||
[worldSeed, userId, team]
|
||||
);
|
||||
}
|
||||
|
||||
// ── Economic scores ───────────────────────────────────────────────────────────
|
||||
|
||||
export async function getEconScores(worldSeed) {
|
||||
|
||||
Reference in New Issue
Block a user