'use strict'; /* A training batch finished. Payload { unit, count, building, userId }. The POP is settled to the due time at the OLD * power draw, then the units appear (and the draw rises). */ const { loadTown, settle } = require('../state'); const U = require('../military/units'); const P = require('../military/power'); module.exports = function trainDone(ctx, ev) { const { db } = ctx; const { unit, count, userId } = ev.payload; const town = loadTown(db, ev.townId); if (!town) return; settle(db, town, ev.dueAt); U.addHome(db, town.id, { [unit]: count }); P.reschedule(ctx, town.id, ev.dueAt); if (userId) ctx.notify(userId, ev.worldId, 'train_done', { townId: town.id, unit, count }); };