Make Repair activity halt if RepairsUnit is paused or abort if disabled.
This commit is contained in:
@@ -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<RepairsUnitsInfo>();
|
||||
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
|
||||
health = self.TraitOrDefault<Health>();
|
||||
}
|
||||
|
||||
@@ -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<PlayerExperience>();
|
||||
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<ValuedInfo>().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<PlayerResources>().TakeCash(cost, true))
|
||||
@@ -89,7 +110,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
|
||||
depot.Repairing(host.Actor, self);
|
||||
|
||||
remainingTicks = repairsUnits.Interval;
|
||||
remainingTicks = repairsUnits.Info.Interval;
|
||||
}
|
||||
else
|
||||
--remainingTicks;
|
||||
|
||||
Reference in New Issue
Block a user