diff --git a/OpenRA.Mods.Common/Activities/Repair.cs b/OpenRA.Mods.Common/Activities/Repair.cs index b6809c3043..295befa282 100644 --- a/OpenRA.Mods.Common/Activities/Repair.cs +++ b/OpenRA.Mods.Common/Activities/Repair.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -18,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities { public class Repair : Activity { - readonly RepairsUnitsInfo repairsUnits; + readonly RepairsUnits[] allRepairsUnits; readonly Target host; readonly WDist closeEnough; @@ -33,7 +34,7 @@ namespace OpenRA.Mods.Common.Activities { this.host = Target.FromActor(host); this.closeEnough = closeEnough; - repairsUnits = host.Info.TraitInfo(); + allRepairsUnits = host.TraitsImplementing().ToArray(); health = self.TraitOrDefault(); } @@ -47,6 +48,26 @@ namespace OpenRA.Mods.Common.Activities return this; } + // First active. + RepairsUnits repairsUnits = null; + var paused = false; + foreach (var r in allRepairsUnits) + { + if (!r.IsTraitDisabled) + { + if (r.IsTraitPaused) + paused = true; + else + { + repairsUnits = r; + break; + } + } + } + + if (repairsUnits == null) + return paused ? this : NextActivity; + if (host.Type == TargetType.Invalid || health == null) return NextActivity; @@ -59,23 +80,23 @@ namespace OpenRA.Mods.Common.Activities { var exp = host.Actor.Owner.PlayerActor.TraitOrDefault(); if (exp != null) - exp.GiveExperience(repairsUnits.PlayerExperience); + exp.GiveExperience(repairsUnits.Info.PlayerExperience); } - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.FinishRepairingNotification, self.Owner.Faction.InternalName); + Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.Info.FinishRepairingNotification, self.Owner.Faction.InternalName); return NextActivity; } if (remainingTicks == 0) { var unitCost = self.Info.TraitInfo().Cost; - var hpToRepair = repairsUnits.HpPerStep; - var cost = Math.Max(1, (hpToRepair * unitCost * repairsUnits.ValuePercentage) / (health.MaxHP * 100)); + var hpToRepair = repairsUnits.Info.HpPerStep; + var cost = Math.Max(1, (hpToRepair * unitCost * repairsUnits.Info.ValuePercentage) / (health.MaxHP * 100)); if (!played) { played = true; - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.StartRepairingNotification, self.Owner.Faction.InternalName); + Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", repairsUnits.Info.StartRepairingNotification, self.Owner.Faction.InternalName); } if (!self.Owner.PlayerActor.Trait().TakeCash(cost, true)) @@ -89,7 +110,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var depot in host.Actor.TraitsImplementing()) depot.Repairing(host.Actor, self); - remainingTicks = repairsUnits.Interval; + remainingTicks = repairsUnits.Info.Interval; } else --remainingTicks;