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