sp*trainer buildings now boost training time for those units
authorxangelo <git@xangelo.ca>
Tue, 24 May 2022 18:03:02 +0000 (14:03 -0400)
committerxangelo <git@xangelo.ca>
Tue, 24 May 2022 18:03:02 +0000 (14:03 -0400)
src/repository/city.ts

index 56b57d030bd8f5a7b82edd73d76f08dccf74fcdb..d54a55c1aae2067998cf3e1d18134e54cbefb280 100644 (file)
@@ -270,9 +270,18 @@ where l.sector_id = ?`, [sector_id]);
         await this.save(city);
 
         // barracks can drop this by 0.01% for each barrack.
-        const barracksOffset = _.round((this.barracksImprovement(city) * unit.time) + unit.time, 2);
 
-        const due = Duration.fromObject({ hours: barracksOffset});
+        let additionalOffset = 0;
+        if(unit.slug === 'sp_attackers') {
+          additionalOffset = (this.spAttackerTraininerBoost(city) * unit.time);
+        }
+        else if(unit.slug === 'sp_defenders') {
+          additionalOffset = (this.spDefenderTraininerBoost(city) * unit.time);
+        }
+
+        const barracksOffset = _.round((this.barracksImprovement(city) * unit.time) + unit.time - additionalOffset, 2);
+
+        const due = Duration.fromObject({ hours: barracksOffset });
 
         const queue = await this.unitTrainigQueue.create(
             city.owner, 
@@ -303,6 +312,14 @@ where l.sector_id = ?`, [sector_id]);
       return city.barracks * 0.0001;
     }
 
+    spAttackerTraininerBoost(city: City): number {
+      return city.special_attacker_trainer * 0.002;
+    }
+
+    spDefenderTraininerBoost(city: City): number {
+      return city.special_defender_trainer * 0.002;
+    }
+
     maxPopulation(city: City): number {
       return city.homes * 25;
     }