Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances, roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map, alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js. Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push, bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
b56b13880e
commit
249818a7aa
111 changed files with 17472 additions and 13 deletions
65
server/routes/movements.js
Normal file
65
server/routes/movements.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
'use strict';
|
||||
/* Movements: send, recall, list (with incoming warnings), withdraw reinforcements, tile info for the send dialog. */
|
||||
const { reply } = require('../http');
|
||||
const { GameError } = require('../errors');
|
||||
const { createMilitaryQueries } = require('../military/views');
|
||||
|
||||
function register(router, services) {
|
||||
const { commands, db, clock, scheduler } = services;
|
||||
const mq = createMilitaryQueries({ db, clock, scheduler });
|
||||
const errs = ['unauthorized', 'not_found', 'validation_failed'];
|
||||
|
||||
router.post('/movements', {
|
||||
summary: 'Send units (scan, raid, attack, takeover, reinforce, settle) or resources (transport) from one of your POPs. Target = toTownId or the tile x,y', tag: 'movements',
|
||||
body: {
|
||||
type: 'object', required: ['fromTownId', 'type'],
|
||||
properties: {
|
||||
fromTownId: { type: 'integer', minimum: 1 },
|
||||
type: { type: 'string', enum: ['scan', 'raid', 'attack', 'takeover', 'reinforce', 'settle', 'transport'] },
|
||||
toTownId: { type: 'integer', minimum: 1 },
|
||||
x: { type: 'integer', minimum: -1000, maximum: 1000 }, y: { type: 'integer', minimum: -1000, maximum: 1000 },
|
||||
units: { type: 'object', additionalProperties: true, description: 'unit id -> count' },
|
||||
cargo: { type: 'object', additionalProperties: true, description: 'transport only: fiber/hardware/capital -> amount' },
|
||||
target: { type: 'string', maxLength: 32, pattern: '^[a-z0-9_]+$', description: 'exploit kits: the building (f1..f18 or an infrastructure type) to damage on a win' },
|
||||
wild: { type: 'array', maxItems: 2, items: { type: 'string', maxLength: 32 }, description: 'settle: the two wild slot field types of the new POP' },
|
||||
confirmEndProtection: { type: 'boolean', description: 'raid/attack/takeover from a protected operator: attacking ends beginner protection' },
|
||||
},
|
||||
},
|
||||
response: { $ref: 'MovementSent' }, status: 201,
|
||||
errors: errs.concat(['unknown_unit', 'not_enough_units', 'units_offline', 'invalid_target', 'target_protected', 'protection_active', 'out_of_range', 'footprint_too_low',
|
||||
'cannot_takeover', 'capacity_exceeded', 'no_transport_link', 'not_enough_resources']),
|
||||
}, ({ user, body }) => {
|
||||
if (body.type === 'transport') {
|
||||
if (body.toTownId === undefined) throw new GameError('validation_failed', { errors: [{ path: 'toTownId', message: 'is required for a transport' }] });
|
||||
return reply(201, commands.run('sendTransport', { userId: user.id, fromTownId: body.fromTownId, toTownId: body.toTownId, cargo: body.cargo }));
|
||||
}
|
||||
return reply(201, commands.run('sendMovement', {
|
||||
userId: user.id, fromTownId: body.fromTownId, type: body.type, toTownId: body.toTownId, x: body.x, y: body.y, units: body.units,
|
||||
target: body.target, wild: body.wild, confirmEndProtection: body.confirmEndProtection,
|
||||
}));
|
||||
});
|
||||
|
||||
router.get('/movements', {
|
||||
summary: 'Your active movements and other operators\' movements heading for your POPs (incoming warnings: origin and ETA only, type hidden)', tag: 'movements',
|
||||
query: { type: 'object', properties: { worldId: { type: 'integer', minimum: 1 } } },
|
||||
response: { $ref: 'MovementList' }, errors: errs,
|
||||
}, ({ user, query }) => mq.movements(user.id, { worldId: query.worldId }));
|
||||
|
||||
router.post('/movements/:id/recall', {
|
||||
summary: 'Turn an outbound movement around within the first 90 seconds', tag: 'movements',
|
||||
response: { $ref: 'RecallResult' }, errors: errs.concat(['conflict', 'recall_expired']),
|
||||
}, ({ user, params }) => commands.run('recallMovement', { userId: user.id, movementId: params.id }));
|
||||
|
||||
router.post('/towns/:id/withdraw', {
|
||||
summary: 'Send reinforcements standing in this POP home (host kicks them out, or the units\' owner calls them back)', tag: 'movements',
|
||||
body: { type: 'object', required: ['ownerTownId'], properties: { ownerTownId: { type: 'integer', minimum: 1 }, units: { type: 'object', additionalProperties: true, description: 'defaults to the whole group' } } },
|
||||
response: { $ref: 'WithdrawResult' }, errors: errs.concat(['not_enough_units', 'unknown_unit']),
|
||||
}, ({ user, params, body }) => commands.run('withdrawStationed', { userId: user.id, hostTownId: params.id, ownerTownId: body.ownerTownId, units: body.units }));
|
||||
|
||||
router.get('/map/tile', {
|
||||
summary: 'Public information about one tile for the send dialog: what is there, owner, distance from your POPs, whether you could settle it', tag: 'map',
|
||||
query: { type: 'object', required: ['x', 'y'], properties: { x: { type: 'integer', minimum: -1000, maximum: 1000 }, y: { type: 'integer', minimum: -1000, maximum: 1000 }, worldId: { type: 'integer', minimum: 1 } } },
|
||||
response: { $ref: 'TileInfo' }, errors: errs,
|
||||
}, ({ user, query }) => mq.tileInfo(user.id, { worldId: query.worldId, x: query.x, y: query.y }));
|
||||
}
|
||||
module.exports = { register };
|
||||
Loading…
Add table
Add a link
Reference in a new issue