Add ConsumedByCapture flag to emulate legacy external behaviour.

This commit is contained in:
Paul Chote
2018-09-29 20:48:39 +00:00
committed by abcdefg30
parent 4d2f1f8942
commit 50423b13fb
3 changed files with 39 additions and 14 deletions

View File

@@ -40,9 +40,21 @@ namespace OpenRA.Mods.Common.Activities
protected override bool TryStartEnter(Actor self) protected override bool TryStartEnter(Actor self)
{ {
// CanEnter is only called when the actor is ready to start entering the target. // StartCapture returns false when a capture delay is enabled
// We can (ab)use this as a notification that the capture is starting. // We wait until it returns true before allowing entering the target
return manager.StartCapture(self, actor, targetManager); Captures captures;
if (!manager.StartCapture(self, actor, targetManager, out captures))
return false;
if (!captures.Info.ConsumedByCapture)
{
// Immediately capture without entering or disposing the actor
DoCapture(self, captures);
AbortOrExit(self);
return false;
}
return true;
} }
protected override void OnInside(Actor self) protected override void OnInside(Actor self)
@@ -50,6 +62,16 @@ namespace OpenRA.Mods.Common.Activities
if (!CanReserve(self)) if (!CanReserve(self))
return; return;
// Prioritize capturing over sabotaging
var captures = manager.ValidCapturesWithLowestSabotageThreshold(self, actor, targetManager);
if (captures == null)
return;
DoCapture(self, captures);
}
void DoCapture(Actor self, Captures captures)
{
if (building != null && !building.Lock()) if (building != null && !building.Lock())
return; return;
@@ -58,11 +80,6 @@ namespace OpenRA.Mods.Common.Activities
if (building != null && building.Locked) if (building != null && building.Locked)
building.Unlock(); building.Unlock();
// Prioritize capturing over sabotaging
var captures = manager.ValidCapturesWithLowestSabotageThreshold(self, actor, targetManager);
if (captures == null)
return;
// Sabotage instead of capture // Sabotage instead of capture
if (captures.Info.SabotageThreshold > 0 && !actor.Owner.NonCombatant) if (captures.Info.SabotageThreshold > 0 && !actor.Owner.NonCombatant)
{ {
@@ -74,7 +91,9 @@ namespace OpenRA.Mods.Common.Activities
var damage = (int)((long)health.MaxHP * captures.Info.SabotageHPRemoval / 100); var damage = (int)((long)health.MaxHP * captures.Info.SabotageHPRemoval / 100);
actor.InflictDamage(self, new Damage(damage)); actor.InflictDamage(self, new Damage(damage));
if (captures.Info.ConsumedByCapture)
self.Dispose(); self.Dispose();
return; return;
} }
} }
@@ -97,6 +116,7 @@ namespace OpenRA.Mods.Common.Activities
exp.GiveExperience(captures.Info.PlayerExperience); exp.GiveExperience(captures.Info.PlayerExperience);
} }
if (captures.Info.ConsumedByCapture)
self.Dispose(); self.Dispose();
}); });
} }

View File

@@ -167,8 +167,10 @@ namespace OpenRA.Mods.Common.Traits
/// This method grants the capturing conditions on the captor and target and returns /// This method grants the capturing conditions on the captor and target and returns
/// true if the captor is able to start entering or false if it needs to wait. /// true if the captor is able to start entering or false if it needs to wait.
/// </summary> /// </summary>
public bool StartCapture(Actor self, Actor target, CaptureManager targetManager) public bool StartCapture(Actor self, Actor target, CaptureManager targetManager, out Captures captures)
{ {
captures = null;
if (target != currentTarget) if (target != currentTarget)
{ {
if (currentTarget != null) if (currentTarget != null)
@@ -189,7 +191,7 @@ namespace OpenRA.Mods.Common.Traits
targetManager.beingCapturedToken == ConditionManager.InvalidConditionToken) targetManager.beingCapturedToken == ConditionManager.InvalidConditionToken)
targetManager.beingCapturedToken = targetManager.conditionManager.GrantCondition(target, targetManager.info.BeingCapturedCondition); targetManager.beingCapturedToken = targetManager.conditionManager.GrantCondition(target, targetManager.info.BeingCapturedCondition);
var captures = enabledCaptures captures = enabledCaptures
.OrderBy(c => c.Info.CaptureDelay) .OrderBy(c => c.Info.CaptureDelay)
.FirstOrDefault(c => targetManager.CanBeTargetedBy(target, self, c)); .FirstOrDefault(c => targetManager.CanBeTargetedBy(target, self, c));
@@ -199,7 +201,7 @@ namespace OpenRA.Mods.Common.Traits
if (progressWatchers.Any() || targetManager.progressWatchers.Any()) if (progressWatchers.Any() || targetManager.progressWatchers.Any())
{ {
currentTargetTotal = captures.Info.CaptureDelay; currentTargetTotal = captures.Info.CaptureDelay;
if (move != null) if (move != null && captures.Info.ConsumedByCapture)
{ {
var pos = target.GetTargetablePositions().PositionClosestTo(self.CenterPosition); var pos = target.GetTargetablePositions().PositionClosestTo(self.CenterPosition);
currentTargetTotal += move.EstimatedMoveDuration(self, self.CenterPosition, pos); currentTargetTotal += move.EstimatedMoveDuration(self, self.CenterPosition, pos);

View File

@@ -35,6 +35,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Delay (in ticks) that to wait next to the target before initiating the capture.")] [Desc("Delay (in ticks) that to wait next to the target before initiating the capture.")]
public readonly int CaptureDelay = 0; public readonly int CaptureDelay = 0;
[Desc("Enter the target actor and be consumed by the capture.")]
public readonly bool ConsumedByCapture = true;
[Desc("Experience granted to the capturing player.")] [Desc("Experience granted to the capturing player.")]
public readonly int PlayerExperience = 0; public readonly int PlayerExperience = 0;