Built: - Economy: raid loot capped to the room the raiders have at home (rest stays with the victim, "lootLeft" in the report); trade escrow reserves its room so refunds always fit; trade accept refuses with no_room_for_goods when the goods would not fit. Loot destroyed per 30-day run 31-61k -> ~1k, refunds clipped ~27k -> 0 (docs/BALANCE.md, 3 seeds). - End game: members of the holding alliance garrison landing sites (migration 005_site_garrison.sql), garrison counts in site defence, 72 h capture shield, withdraw route, POP view lists garrisoned units. Shipping capacity scales with world speed (3x world: winner 76-98 -> ~30-36 days after sites open). Bot runs show real contests (84-194 attacks on held sites at 1x). - Ops: deploy/update.sh (backup, stop, ff-merge, npm ci --ignore-scripts, health check, rollback), deploy/upstream-offsite (rsync only), admin end-world snapshots results, EPIPE fix, docs/workflows/ filled in. - e2e 62 -> 163 checks: units, raids/reports, alliance+messages, trade, end game, nb, PWA, reconnect, slow polling fallback (opt-in). Two app bugs found: message push ignored, "New" button stayed English. Tested: npm test 274/274, openapi check, npm run e2e 163/163 (137 s), bot runs 50x30d seeds 1-3 and 140-day/60-day speed-3 end-game runs INVARIANTS OK, adversarial review pass (findings fixed or documented). NOT tested: update.sh on a real box (systemd, real npm, runuser; stubs only, shellcheck not installed), garrison card/loot text on a phone, Node 22.13, humans. Known leaks left open and documented (BALANCE S6): loot/shipments can still overflow when stock arrives in flight, bounced backbone shipments lose overflow (reported to the sender). Garrison numbers (heldDefenceMult 2, shield 72 h) are first guesses from 2 seeds. Not claimed: balanced. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
22 lines
1.2 KiB
JavaScript
22 lines
1.2 KiB
JavaScript
'use strict';
|
|
/* DELETE /towns/:id/queue/:eventId. Cancels a running build and refunds 80% (rounded down). */
|
|
const D = require('../../public/js/data.js');
|
|
const { GameError } = require('../errors');
|
|
const { settle } = require('../state');
|
|
const { ownedTown } = require('./build');
|
|
|
|
const REFUND = 0.8;
|
|
|
|
module.exports = function cancelBuild(ctx, { userId, townId, eventId }) {
|
|
const { db, now } = ctx;
|
|
const town = ownedTown(db, userId, townId);
|
|
const ev = db.get("SELECT id, payload FROM events WHERE id = ? AND town_id = ? AND type = 'buildDone' AND status = 'pending'", eventId, town.id);
|
|
if (!ev) throw new GameError('not_found', { what: 'queue entry' });
|
|
settle(db, town, now);
|
|
const cost = JSON.parse(ev.payload).cost || {};
|
|
const R = require('../../public/js/rules.js');
|
|
for (const r of D.RESOURCES) town.res[r] = Math.min(Math.max(R.storageCapOf(town, r), town.res[r]), town.res[r] + Math.floor((cost[r] || 0) * REFUND));
|
|
db.run('UPDATE towns SET fiber = ?, hardware = ?, capital = ? WHERE id = ?', town.res.fiber, town.res.hardware, town.res.capital, town.id);
|
|
db.run("UPDATE events SET status = 'cancelled', done_at = ? WHERE id = ?", now, ev.id);
|
|
return { cancelled: ev.id };
|
|
};
|