From eb5ad7ba9d5acdbfb1561f0b31483139977bf65c Mon Sep 17 00:00:00 2001 From: xangelo Date: Thu, 26 May 2022 13:34:39 -0400 Subject: [PATCH] bugfix: training units overwrites their values When training units it was writing all unit values to null resulting in you being unable to train any units. --- src/render/unit-training.ts | 10 +++++----- src/repository/city.ts | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/render/unit-training.ts b/src/render/unit-training.ts index 351bc79..686b57b 100644 --- a/src/render/unit-training.ts +++ b/src/render/unit-training.ts @@ -27,7 +27,7 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Soldiers - ${city.population} + ${city.soldiers}
@@ -39,7 +39,7 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Attackers - ${city.soldiers} + ${city.attackers} @@ -51,7 +51,7 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Defenders - ${city.soldiers} + ${city.defenders} @@ -63,7 +63,7 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Attackers - ${city.attackers} + ${city.sp_attackers} @@ -76,7 +76,7 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Defenders - ${city.defenders} + ${city.sp_defenders} diff --git a/src/repository/city.ts b/src/repository/city.ts index 168053c..f49b1db 100644 --- a/src/repository/city.ts +++ b/src/repository/city.ts @@ -265,6 +265,9 @@ where l.sector_id = ?`, [sector_id]); throw new InsufficientResourceError('defenders', unit.defenders, city.defenders); } + console.log(city); + console.log(unit, amount); + // validate that they have enough of the buildings to support this // ok they have everything, lets update their city @@ -272,10 +275,12 @@ where l.sector_id = ?`, [sector_id]); city.credits -= unit.credits * amount; city.food -= unit.food * amount; - city.population -= coalesce(unit.population, 0) * amount; - city.soldiers -= coalesce(unit.soldiers, 0) * amount; - city.attackers -= coalesce(unit.attackers, 0) * amount; - city.defenders -= coalesce(unit.defenders, 0) * amount; + city.population -= unit.population * amount; + city.soldiers -= unit.soldiers * amount; + city.attackers -= unit.attackers * amount; + city.defenders -= unit.defenders * amount; + + console.log(city); await this.save(city); -- 2.25.1