Add a range check to Repair.

This commit is contained in:
Paul Chote
2016-09-21 18:25:23 +01:00
parent c1e1ee0938
commit 323ed98a15
5 changed files with 20 additions and 14 deletions

View File

@@ -19,15 +19,22 @@ namespace OpenRA.Mods.Common.Activities
public class Repair : Activity
{
readonly RepairsUnitsInfo repairsUnits;
readonly Actor host;
readonly Target host;
readonly WDist closeEnough;
int remainingTicks;
Health health;
bool played = false;
public Repair(Actor host)
public Repair(Actor self, Actor host)
: this(self, host, WDist.Zero) { }
public Repair(Actor self, Actor host, WDist closeEnough)
{
this.host = host;
this.host = Target.FromActor(host);
this.closeEnough = closeEnough;
repairsUnits = host.Info.TraitInfo<RepairsUnitsInfo>();
health = self.TraitOrDefault<Health>();
}
public override Activity Tick(Actor self)
@@ -40,18 +47,17 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
if (host == null || !host.IsInWorld)
if (host.Type == TargetType.Invalid || health == null)
return NextActivity;
health = self.TraitOrDefault<Health>();
if (health == null)
if (closeEnough.LengthSquared > 0 && !host.IsInRange(self.CenterPosition, closeEnough))
return NextActivity;
if (health.DamageState == DamageState.Undamaged)
{
if (host.Owner != self.Owner)
if (host.Actor.Owner != self.Owner)
{
var exp = host.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
var exp = host.Actor.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
if (exp != null)
exp.GiveExperience(repairsUnits.PlayerExperience);
}
@@ -80,8 +86,8 @@ namespace OpenRA.Mods.Common.Activities
self.InflictDamage(self, new Damage(-hpToRepair));
foreach (var depot in host.TraitsImplementing<INotifyRepair>())
depot.Repairing(host, self);
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
depot.Repairing(host.Actor, self);
remainingTicks = repairsUnits.Interval;
}

View File

@@ -341,7 +341,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.RearmBuildings.Contains(name))
yield return new Rearm(self);
if (Info.RepairBuildings.Contains(name))
yield return new Repair(a);
yield return new Repair(self, a);
}
public void ModifyDeathActorInit(Actor self, TypeDictionary init)

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits
if (CanRearmAt(order.TargetActor) && CanRearm())
self.QueueActivity(new Rearm(self));
self.QueueActivity(new Repair(order.TargetActor));
self.QueueActivity(new Repair(self, order.TargetActor));
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
if (rp != null)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
self.QueueActivity(movement.MoveWithinRange(target, info.CloseEnough));
self.QueueActivity(new Repair(order.TargetActor));
self.QueueActivity(new Repair(self, order.TargetActor, info.CloseEnough));
self.SetTargetLine(target, Color.Green, false);
}

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Activities
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)),
movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget),
new Rearm(self),
new Repair(rearmTarget),
new Repair(self, rearmTarget),
this);
}