feat(server): achievements pay out server-side, snapshots carry opponent connection state

This commit is contained in:
Benjamin Oezcan
2026-11-19 02:09:12 +01:00
parent 85a19ba242
commit 0202a08b8d
5 changed files with 13 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
'use strict';
const RC = require('../game/robot.js'); // pulls in parts.js, sets globalThis.RC
require('../game/eco.js');
require('../game/progress.js');
const { OnlineSaves, KV } = require('./db');
const Eco = RC.Eco;
@@ -51,8 +52,11 @@ function reward(uid, o) {
const ev = live.event && live.event.prizeMul && Date.now() >= (live.event.from || 0) && Date.now() <= (live.event.to || Infinity) ? live.event.prizeMul : 1;
const r = Eco.pvpReward(Object.assign({}, o, { money: s.money, prizeMul: ev }));
Eco.applyReward(s, r);
// achievements pay credits -> decided here, never on the client (same rules: game/progress.js)
const ach = RC.Progress.check(s, { won: r.won, reason: o.reason, hpPct: (o.hp || 0) / (o.maxHp || 1), dealt: o.dealt || 0, lost: (o.lost || []).length });
for (const a of ach) s.money = Math.min(1e9, s.money + (a.reward | 0));
store(uid, s);
return Object.assign(r, { save: view(s) });
return Object.assign(r, { ach: ach.map(a => ({ id: a.id, reward: a.reward })), save: view(s) });
}
function ranks(n = 20) { return OnlineSaves.top(Math.max(1, Math.min(100, n | 0))); }