'use strict'; /* End game: the race (world status), the final results, landing sites (read, feed the stockpile, build the node). Taking a site is * POST /movements (scan / attack at its x,y). */ const { reply } = require('../http'); const { createEndgameQueries } = require('../endgameQueries'); const D = require('../../public/js/data.js'); function register(router, services) { const { commands } = services; const eg = createEndgameQueries(services); const errs = ['unauthorized', 'not_found', 'validation_failed']; router.get('/worlds/:id/status', { summary: 'The state of the world: phase (running, backbone_open, ended), world age, the landing sites with holder, node level, stockpile and build progress, the winner', tag: 'world', response: { $ref: 'WorldStatus' }, errors: errs, }, ({ user, params }) => eg.status(user.id, params.id)); router.get('/worlds/:id/results', { summary: 'The final ranking snapshot (operators, alliances, attackers, defenders, winner); available once the world has ended', tag: 'world', response: { $ref: 'WorldResults' }, errors: errs, }, ({ user, params }) => eg.results(user.id, params.id)); router.get('/backbone/:id', { summary: 'One landing site; members of the holding alliance also see the contribution ledger and what they may do', tag: 'world', response: { $ref: 'LandingSiteResponse' }, errors: errs, }, ({ user, params }) => eg.site(user.id, params.id)); router.post('/backbone/:id/ship', { summary: 'Send resources from one of your POPs to a landing site your alliance holds (a transport: Internet exchange links, 1000 each at world speed 1, times the world speed)', tag: 'world', status: 201, body: { type: 'object', required: ['fromTownId', 'cargo'], properties: { fromTownId: { type: 'integer', minimum: 1 }, cargo: { type: 'object', additionalProperties: true, description: 'fiber/hardware/capital -> amount' } } }, response: { $ref: 'MovementSent' }, errors: errs.concat(['forbidden', 'backbone_closed', 'capacity_exceeded', 'no_transport_link', 'not_enough_resources', 'world_ended']), }, ({ user, params, body }) => reply(201, commands.run('backboneShip', { userId: user.id, siteId: params.id, fromTownId: body.fromTownId, cargo: body.cargo }))); router.post('/backbone/:id/withdraw', { summary: 'Call units of one of your POPs home from a landing site\'s garrison (default: all of them). Only their owner can; works whoever holds the site now. Station units with POST /movements type reinforce at the site\'s x,y (members of the holding alliance only)', tag: 'world', status: 201, body: { type: 'object', required: ['fromTownId'], properties: { fromTownId: { type: 'integer', minimum: 1 }, units: { type: 'object', additionalProperties: true, description: 'defaults to the whole group' } } }, response: { $ref: 'GarrisonWithdrawn' }, errors: errs.concat(['not_enough_units', 'unknown_unit', 'conflict', 'world_ended']), }, ({ user, params, body }) => reply(201, commands.run('withdrawGarrison', { userId: user.id, siteId: params.id, fromTownId: body.fromTownId, units: body.units }))); router.post('/backbone/:id/build', { summary: 'Start the next Backbone node level on a landing site your alliance holds (paid from the site\'s stockpile; one level at a time, up to level ' + D.ENDGAME.maxLevel + ')', tag: 'world', status: 201, response: { $ref: 'BackboneBuildStarted' }, errors: errs.concat(['forbidden', 'backbone_closed', 'max_level', 'already_queued', 'not_enough_resources', 'world_ended']), }, ({ user, params }) => reply(201, commands.run('backboneBuild', { userId: user.id, siteId: params.id }))); } module.exports = { register };