bugfix: training units overwrites their values
[browser-rts.git] / src / repository / city.ts
index 168053c473b80c942c38f5c0aa4cac31ec6754e8..f49b1db9d09226a8ac8fa46536867c28be588e82 100644 (file)
@@ -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);