feat(gameplay): Adding % bonus for planet type
This commit is contained in:
@@ -11,6 +11,10 @@ import {
|
||||
getScores,
|
||||
getEconScores,
|
||||
addEconScore,
|
||||
getElementBonus,
|
||||
setElementBonus,
|
||||
getDbCreatedAt,
|
||||
getVictoryPoints,
|
||||
} from "../db/gameDb.js";
|
||||
import { computeCell, rowToCellPayload } from "../helpers/cell.js";
|
||||
|
||||
@@ -46,6 +50,7 @@ router.get("/config", async (req, res) => {
|
||||
seedPeriodStartsAtUtc: ws.seedPeriodStartsAtUtc,
|
||||
teamCooldownRemaining,
|
||||
resourceWorth: cfg.resourceWorth ?? { common: {}, rare: {} },
|
||||
elementWorth: cfg.elementWorth ?? {},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -180,6 +185,58 @@ router.post("/econ-scores/tick", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/element-bonus
|
||||
router.get("/element-bonus", async (_req, res) => {
|
||||
try {
|
||||
const worldSeed = await ensureSeedEpoch();
|
||||
const bonus = await getElementBonus(worldSeed);
|
||||
res.json(bonus);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: "database_error" });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/element-bonus/tick body: { seed, blue, red }
|
||||
router.post("/element-bonus/tick", async (req, res) => {
|
||||
const seed = String(req.body?.seed ?? "");
|
||||
const blue = Number(req.body?.blue ?? 0);
|
||||
const red = Number(req.body?.red ?? 0);
|
||||
try {
|
||||
const worldSeed = await ensureSeedEpoch();
|
||||
if (seed !== worldSeed) return res.status(410).json({ error: "seed_expired", worldSeed });
|
||||
await setElementBonus(worldSeed, "blue", blue);
|
||||
await setElementBonus(worldSeed, "red", red);
|
||||
const bonus = await getElementBonus(worldSeed);
|
||||
res.json(bonus);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: "database_error" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/db-info
|
||||
router.get("/db-info", async (_req, res) => {
|
||||
try {
|
||||
const createdAt = await getDbCreatedAt();
|
||||
res.json({ createdAt });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: "database_error" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/victory-points
|
||||
router.get("/victory-points", async (_req, res) => {
|
||||
try {
|
||||
const vp = await getVictoryPoints();
|
||||
res.json(vp);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: "database_error" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/scores
|
||||
router.get("/scores", async (_req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user