From: xangelo Date: Tue, 24 May 2022 15:30:29 +0000 (-0400) Subject: new building: homes X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=94edfb691f9596d2d1e3c9f83b31fe9c5e99bee7;p=browser-rts.git new building: homes Homes give you 25 pop cap increase. --- diff --git a/src/render/kingdom-overview.ts b/src/render/kingdom-overview.ts index c035f7c..2712e76 100644 --- a/src/render/kingdom-overview.ts +++ b/src/render/kingdom-overview.ts @@ -1,5 +1,5 @@ import { Account } from "../repository/accounts"; -import { CityWithLocation } from "../repository/city"; +import { CityWithLocation, CityRepository } from "../repository/city"; import * as _ from 'lodash'; type Usage = { @@ -9,6 +9,8 @@ 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; @@ -20,7 +22,7 @@ export function renderKingomOverview(city: CityWithLocation & Usage, account: Ac Captain ${account.username} Population - ${city.population.toLocaleString()}/${_.max([city.farms * 70, city.population])} + ${city.population.toLocaleString()}/${cityRepo.maxPopulation(city)} Space diff --git a/src/repository/city.ts b/src/repository/city.ts index 43e1b7a..9c2153c 100644 --- a/src/repository/city.ts +++ b/src/repository/city.ts @@ -26,6 +26,7 @@ export type City = { defenders: number; sp_attackers: number; sp_defenders: number; + homes: number; farms: number; barracks: number; special_attacker_trainer: number; @@ -72,6 +73,7 @@ export class CityRepository extends Repository { defenders: 0, sp_attackers: 0, sp_defenders: 0, + homes: 20, farms: 0, barracks: 0, special_attacker_trainer: 0, @@ -118,9 +120,23 @@ export class CityRepository extends Repository { return sample.sector_id; } - async save(city: Partial) { - 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 { @@ -279,6 +295,10 @@ where l.sector_id = ?`, [sector_id]); return power } + maxPopulation(city: City): number { + return city.homes * 25; + } + async foodProductionPerTick(city: City): Promise { // eventually we should supply the warehouse formula // to calculate the max amount of food created per tick