Add a range check to Repair.
This commit is contained in:
@@ -19,15 +19,22 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public class Repair : Activity
|
public class Repair : Activity
|
||||||
{
|
{
|
||||||
readonly RepairsUnitsInfo repairsUnits;
|
readonly RepairsUnitsInfo repairsUnits;
|
||||||
readonly Actor host;
|
readonly Target host;
|
||||||
|
readonly WDist closeEnough;
|
||||||
|
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
Health health;
|
Health health;
|
||||||
bool played = false;
|
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>();
|
repairsUnits = host.Info.TraitInfo<RepairsUnitsInfo>();
|
||||||
|
health = self.TraitOrDefault<Health>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
@@ -40,18 +47,17 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host == null || !host.IsInWorld)
|
if (host.Type == TargetType.Invalid || health == null)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
health = self.TraitOrDefault<Health>();
|
if (closeEnough.LengthSquared > 0 && !host.IsInRange(self.CenterPosition, closeEnough))
|
||||||
if (health == null)
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
if (health.DamageState == DamageState.Undamaged)
|
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)
|
if (exp != null)
|
||||||
exp.GiveExperience(repairsUnits.PlayerExperience);
|
exp.GiveExperience(repairsUnits.PlayerExperience);
|
||||||
}
|
}
|
||||||
@@ -80,8 +86,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
self.InflictDamage(self, new Damage(-hpToRepair));
|
self.InflictDamage(self, new Damage(-hpToRepair));
|
||||||
|
|
||||||
foreach (var depot in host.TraitsImplementing<INotifyRepair>())
|
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
|
||||||
depot.Repairing(host, self);
|
depot.Repairing(host.Actor, self);
|
||||||
|
|
||||||
remainingTicks = repairsUnits.Interval;
|
remainingTicks = repairsUnits.Interval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Info.RearmBuildings.Contains(name))
|
if (Info.RearmBuildings.Contains(name))
|
||||||
yield return new Rearm(self);
|
yield return new Rearm(self);
|
||||||
if (Info.RepairBuildings.Contains(name))
|
if (Info.RepairBuildings.Contains(name))
|
||||||
yield return new Repair(a);
|
yield return new Repair(self, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ModifyDeathActorInit(Actor self, TypeDictionary init)
|
public void ModifyDeathActorInit(Actor self, TypeDictionary init)
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (CanRearmAt(order.TargetActor) && CanRearm())
|
if (CanRearmAt(order.TargetActor) && CanRearm())
|
||||||
self.QueueActivity(new Rearm(self));
|
self.QueueActivity(new Rearm(self));
|
||||||
|
|
||||||
self.QueueActivity(new Repair(order.TargetActor));
|
self.QueueActivity(new Repair(self, order.TargetActor));
|
||||||
|
|
||||||
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
||||||
if (rp != null)
|
if (rp != null)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(movement.MoveWithinRange(target, info.CloseEnough));
|
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);
|
self.SetTargetLine(target, Color.Green, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)),
|
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)),
|
||||||
movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget),
|
movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget),
|
||||||
new Rearm(self),
|
new Rearm(self),
|
||||||
new Repair(rearmTarget),
|
new Repair(self, rearmTarget),
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user