fix crash in Activities.Repair
This commit is contained in:
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return new Wait(20);
|
||||
|
||||
return new Move(((1 / 24f) * rearmTarget.CenterLocation).ToInt2(), rearmTarget)
|
||||
{ NextActivity = new Rearm() { NextActivity = new Repair() { NextActivity = this } } };
|
||||
{ NextActivity = new Rearm() { NextActivity = new Repair(rearmTarget) { NextActivity = this } } };
|
||||
}
|
||||
|
||||
var ml = self.traits.Get<Minelayer>();
|
||||
|
||||
@@ -29,20 +29,20 @@ namespace OpenRA.Mods.RA.Activities
|
||||
public IActivity NextActivity { get; set; }
|
||||
bool isCanceled;
|
||||
int remainingTicks;
|
||||
Actor host;
|
||||
|
||||
public Repair(Actor host) { this.host = host; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (isCanceled) return NextActivity;
|
||||
if (remainingTicks == 0)
|
||||
{
|
||||
var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation)
|
||||
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
|
||||
|
||||
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var hp = self.Info.Traits.Get<OwnedActorInfo>().HP;
|
||||
|
||||
var costPerHp = (hostBuilding.Info.Traits.Get<RepairsUnitsInfo>().URepairPercent * unitCost) / hp;
|
||||
var hpToRepair = Math.Min(hostBuilding.Info.Traits.Get<RepairsUnitsInfo>().URepairStep, hp - self.Health);
|
||||
var costPerHp = (host.Info.Traits.Get<RepairsUnitsInfo>().URepairPercent * unitCost) / hp;
|
||||
var hpToRepair = Math.Min(host.Info.Traits.Get<RepairsUnitsInfo>().URepairStep, hp - self.Health);
|
||||
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
|
||||
if (!self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(cost))
|
||||
{
|
||||
@@ -54,9 +54,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (self.Health == hp)
|
||||
return NextActivity;
|
||||
|
||||
if (hostBuilding != null)
|
||||
hostBuilding.traits.Get<RenderBuilding>()
|
||||
.PlayCustomAnim(hostBuilding, "active");
|
||||
if (host != null)
|
||||
host.traits.Get<RenderBuilding>()
|
||||
.PlayCustomAnim(host, "active");
|
||||
|
||||
remainingTicks = (int)(self.World.Defaults.RepairRate * 60 * 25);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(new Turn(self.Info.Traits.GetOrDefault<UnitInfo>().InitialFacing));
|
||||
self.QueueActivity(new HeliLand(false));
|
||||
self.QueueActivity(self.Info.Traits.Get<HelicopterInfo>().RearmBuildings.Contains(order.TargetActor.Info.Name)
|
||||
? (IActivity)new Rearm() : new Repair());
|
||||
? (IActivity)new Rearm() : new Repair(order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||
self.QueueActivity(
|
||||
info.RearmBuildings.Contains(order.TargetActor.Info.Name)
|
||||
? (IActivity)new Rearm() : new Repair());
|
||||
? (IActivity)new Rearm() : new Repair(order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(((1 / 24f) * order.TargetActor.CenterLocation).ToInt2(), order.TargetActor));
|
||||
self.QueueActivity(new Rearm());
|
||||
self.QueueActivity(new Repair());
|
||||
self.QueueActivity(new Repair(order.TargetActor));
|
||||
|
||||
if (rp != null)
|
||||
self.QueueActivity(new CallFunc(
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor, 1));
|
||||
self.QueueActivity(new Repair());
|
||||
self.QueueActivity(new Repair(order.TargetActor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user