import { createBullBoard } from '@bull-board/api';
import { BullAdapter } from '@bull-board/api/bullAdapter';
import _ from 'lodash';
-import { renderMailroom, renderMessage } from './render/mail';
+import { renderCost } from './render/costs';
+import {renderMailroom, renderMessage} from './render/mail';
+import {topbar} from './render/topbar';
const server = new HttpServer(config.API_PORT);
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
- return renderKingomOverview(city, account);
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: 0,
+ energyProductionPerTick: 0
+ }
+
+ return renderKingomOverview({
+ ...city,
+ ...usage
+ }, account) + topbar({...city, ...usage});
});
server.get<{}, string>('/poll/construction', async req => {
const buildings = await cityRepo.buildingRepository.list();
const buildQueues = await cityRepo.getBuildQueues(account.id);
- return renderLandDevelopment(city, buildings, buildQueues);
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: 0,
+ energyProductionPerTick: 0
+ }
+ return renderLandDevelopment(city, buildings, buildQueues) + topbar({...city, ...usage});
});
server.get<{}, string>('/poll/unit-training', async req => {
const unitTrainingQueues = await cityRepo.getUnitTrainingQueues(account.id);
const units = await cityRepo.unitRepository.list();
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: 0,
+ energyProductionPerTick: 0
+ }
- return renderUnitTraining(city, units, unitTrainingQueues);
+ return renderUnitTraining(city, units, unitTrainingQueues) + topbar({
+ ...city,
+ ...usage
+ });
});
server.post<{body: {sector: string}}, string>('/poll/map', async req => {
}
}
- console.log('Checking cities in sector', sector);
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: 0,
+ energyProductionPerTick: 0
+ }
- return renderOverworldMap(await cityRepo.findAllInSector(sector), city, sector);
+ return renderOverworldMap(await cityRepo.findAllInSector(sector), city, sector) + topbar({
+ ...city,
+ ...usage
+ });
});
server.get<{}, string>('/poll/mailroom', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
+ const city = await cityRepo.getUsersCity(account.id);
- return renderMailroom(await mailRepo.listReceivedMessages(account.id));
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: 0,
+ energyProductionPerTick: 0
+ }
+
+ return renderMailroom(await mailRepo.listReceivedMessages(account.id)) + topbar({
+ ...city,
+ ...usage
+ });
});
}
}, string>('/cost/construction', async req => {
const amount = parseInt(req.body.amount.trim(), 10);
- console.log('checking amount', amount);
if(isNaN(amount) || amount < 1) {
return '';
throw new NotFoundError(`Invalid building type ${req.body.building_type}`, ERROR_CODE.INVALID_BUILDING);
}
- return JSON.stringify({
- gold: building.gold * amount,
- ore: building.ore * amount,
- logs: building.logs * amount,
+ const cost = {
+ credits: building.credits * amount,
+ alloys: building.alloys * amount,
+ energy: building.energy * amount,
land: building.land * amount,
time: building.time
- });
+ };
+
+ return renderCost(cost);
});
server.post<{
}
}, string>('/cost/training', async req => {
const amount = parseInt(req.body.amount, 10);
- const unit = await cityRepo.unitRepository.findBySlug(req.body.type);
+ if(isNaN(amount) || amount < 1) {
+ return '';
+ }
+
+ const unit = await cityRepo.unitRepository.findBySlug(req.body.type);
if(!unit) {
throw new NotFoundError(`Invalid unit type ${req.body.type}`, ERROR_CODE.INVALID_UNIT);
}
- return JSON.stringify({
+ return renderCost({
population: unit.population * amount,
soldiers: unit.soldiers * amount,
attackers: unit.attackers * amount,
defenders: unit.defenders * amount,
- gold: unit.gold * amount,
- bushels: unit.bushels * amount
+ credits: unit.credits * amount,
+ food: unit.food * amount,
+ time: unit.time * amount
});
});
building_type: string,
}
}, void>('/build', async req => {
- const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
- const city = await cityRepo.getUsersCity(account.id);
+ const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
+ const city = await cityRepo.getUsersCity(account.id);
- const amount = parseInt(req.body.amount, 10);
- const building = await cityRepo.buildingRepository.findBySlug(req.body.building_type);
+ const amount = parseInt(req.body.amount, 10);
+ const building = await cityRepo.buildingRepository.findBySlug(req.body.building_type);
- if(!building) {
- throw new NotFoundError(`Invalid building type ${req.body.building_type}`, ERROR_CODE.INVALID_BUILDING);
- }
+ if(!building) {
+ throw new NotFoundError(`Invalid building type ${req.body.building_type}`, ERROR_CODE.INVALID_BUILDING);
+ }
- const queueData = await cityRepo.buildBuilding(building, amount ,city);
+ const queueData = await cityRepo.buildBuilding(building, amount, city);
construction.trigger(queueData, { delay: queueData.due });
}, 'reload-construction-queue');