import { Account } from "../repository/accounts";
-import { CityWithLocation } from "../repository/city";
+import { CityWithLocation, CityRepository } from "../repository/city";
import * as _ from 'lodash';
type Usage = {
energyProductionPerTick: number;
}
+const cityRepo = new CityRepository();
+
export function renderKingomOverview(city: CityWithLocation & Usage, account: Account): string {
const foodRateOfChange = city.foodProductionPerTick - city.foodUsagePerTick;
const energyRateOfChange = city.energyProductionPerTick - city.energyUsagePerTick;
<th>Captain</th>
<td>${account.username}</td>
<th>Population</th>
- <td>${city.population.toLocaleString()}/${_.max([city.farms * 70, city.population])}</td>
+ <td>${city.population.toLocaleString()}/${cityRepo.maxPopulation(city)}</td>
</tr>
<tr>
<th>Space</th>
defenders: number;
sp_attackers: number;
sp_defenders: number;
+ homes: number;
farms: number;
barracks: number;
special_attacker_trainer: number;
defenders: 0,
sp_attackers: 0,
sp_defenders: 0,
+ homes: 20,
farms: 0,
barracks: 0,
special_attacker_trainer: 0,
return sample.sector_id;
}
- async save(city: Partial<City>) {
- await this.Save(city, {id: city.id});
- return city;
+ async save(city: City) {
+ const fieldsToSave = [
+ 'totalSpace', 'usedSpace', 'credits', 'alloys', 'energy', 'food',
+ 'poulation', 'soldiers', 'attackers', 'defenders', 'sp_attackers', 'sp_defenders',
+ 'homes', 'farms', 'barracks', 'special_attacker_trainer', 'special_defender_trainer'
+ ];
+
+ const finalData = {};
+
+ fieldsToSave.forEach(field => {
+ if(city.hasOwnProperty(field)) {
+ finalData[field] = city[field];
+ }
+ });
+
+ await this.Save(finalData, {id: city.id});
+ return city;
}
async findById(cityId: string): Promise<CityWithLocation> {
return power
}
+ maxPopulation(city: City): number {
+ return city.homes * 25;
+ }
+
async foodProductionPerTick(city: City): Promise<number> {
// eventually we should supply the warehouse formula
// to calculate the max amount of food created per tick