const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
- energyUsagePerTick: 0,
- energyProductionPerTick: 0
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
return renderKingomOverview({
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
- energyUsagePerTick: 0,
- energyProductionPerTick: 0
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
return renderLandDevelopment(city, buildings, buildQueues) + topbar({...city, ...usage});
});
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
- energyUsagePerTick: 0,
- energyProductionPerTick: 0
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
return renderUnitTraining(city, units, unitTrainingQueues) + topbar({
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
- energyUsagePerTick: 0,
- energyProductionPerTick: 0
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
return renderOverworldMap(await cityRepo.findAllInSector(sector), city, sector) + topbar({
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
- energyUsagePerTick: 0,
- energyProductionPerTick: 0
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
return renderMailroom(await mailRepo.listReceivedMessages(account.id)) + topbar({
-export function coalesce(...args: any[]): any {
+import { isEmpty } from 'lodash';
+
+export function coalesce(...args) {
let found;
while(args.length) {
found = args.shift();
- if(found !== null && found !== undefined && found !== '') {
+ if(found !== null && found !== undefined && !isEmpty(found)) {
return found;
}
}
-}
\ No newline at end of file
+}
+
+export function pluck<T>(arr: T[], field: string): Map<string, T> {
+ const map = new Map<string, T>();
+ arr.forEach(obj => {
+ map[obj[field]] = obj;
+ });
+
+ return map;
+}
</tr>
<tr>
<th>Energy</th>
- <td>${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)</td>
+ <td>
+ ${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)
+ @ 0% Battery Utilization
+ </td>
<th>Special Defenders</th>
<td>${city.sp_defenders.toLocaleString()}</td>
</tr>
import { BuildQueue, BuildQueueRepository } from './build-queue';
import { DateTime, Duration } from 'luxon';
import { UnitTrainingQueue, UnitTrainingQueueRepository } from './training-queue';
-import { coalesce } from '../lib/util';
+import { coalesce, pluck } from '../lib/util';
import { Building, BuildingRepository } from './buildings';
import { Unit, UnitRepository } from './unit';
import _, { random } from 'lodash';
homes: number;
farms: number;
warehouses: number;
+ solar_panels: number;
barracks: number;
special_attacker_trainer: number;
special_defender_trainer: number;
homes: 20,
farms: 5,
warehouses: 5,
+ solar_panels: 5,
barracks: 0,
special_attacker_trainer: 0,
special_defender_trainer: 0,
)
}
- async energyProductionPerTic(city: City): Promise<number> {
- return 0;
+ async energyProductionPerTick(city: City): Promise<number> {
+ return city.solar_panels * 125;
}
async energyUsagePerTick(city: City): Promise<number> {
- return 0;
+ const buildings = await this.buildingRepository.list();
+ const buildingsMap = pluck<Building>(buildings, 'slug');
+ const totalEnergy = _.sum([
+ city.farms * buildingsMap['farms'].energy,
+ city.barracks * buildingsMap['barracks'].energy,
+ city.special_defender_trainer * buildingsMap['special_defender_trainer'].energy,
+ city.special_attacker_trainer * buildingsMap['special_attacker_trainer'].energy,
+ city.homes * buildingsMap['homes'].energy,
+ city.warehouses * buildingsMap['warehouses'].energy,
+ city.solar_panels * buildingsMap['solar_panels'].energy
+ ]);
+ return totalEnergy;
}
async attack(attacker: CityWithLocation, attacked: CityWithLocation, army: Army): Promise<ArmyQueue> {