Added HpPerStep to Repairable for enable repair speed to be changed per unit.

This commit is contained in:
teinarss
2018-05-04 21:20:50 +02:00
committed by reaperrr
parent c5e36636ae
commit dcc11c7a41
2 changed files with 12 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Activities
readonly RepairsUnits[] allRepairsUnits;
readonly Target host;
readonly WDist closeEnough;
readonly Repairable repairable;
int remainingTicks;
bool played = false;
@@ -33,6 +34,7 @@ namespace OpenRA.Mods.Common.Activities
this.closeEnough = closeEnough;
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
health = self.TraitOrDefault<Health>();
repairable = self.TraitOrDefault<Repairable>();
}
protected override void OnFirstRun(Actor self)
@@ -97,7 +99,7 @@ namespace OpenRA.Mods.Common.Activities
if (remainingTicks == 0)
{
var unitCost = self.Info.TraitInfo<ValuedInfo>().Cost;
var hpToRepair = repairsUnits.Info.HpPerStep;
var hpToRepair = repairable != null && repairable.Info.HpPerStep > 0 ? repairable.Info.HpPerStep : repairsUnits.Info.HpPerStep;
// Cast to long to avoid overflow when multiplying by the health
var cost = Math.Max(1, (int)(((long)hpToRepair * unitCost * repairsUnits.Info.ValuePercentage) / (health.MaxHP * 100L)));