Fix undock anim playing even if docking was cancelled

...before dock anim could run.

The undock animation would play even if the dock anim
hadn't run (meaning the sequence cancelled before the docking
completed, for example due to refinery death).
This commit is contained in:
reaperrr
2020-10-18 13:46:08 +02:00
committed by abcdefg30
parent 87929b3d91
commit 996029ee38
2 changed files with 15 additions and 4 deletions

View File

@@ -45,10 +45,12 @@ namespace OpenRA.Mods.Cnc.Activities
public override void OnStateUndock(Actor self)
{
dockingState = DockingState.Wait;
if (spriteOverlay != null && !spriteOverlay.Visible)
// If body.Docked wasn't set, we didn't actually dock and have to skip the undock overlay
if (!body.Docked)
dockingState = DockingState.Complete;
else if (spriteOverlay != null && !spriteOverlay.Visible)
{
dockingState = DockingState.Wait;
spriteOverlay.Visible = true;
spriteOverlay.WithOffset.Animation.PlayBackwardsThen(spriteOverlay.Info.Sequence, () =>
{

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Mods.Common.Activities
{
readonly WithSpriteBody wsb;
readonly WithDockingAnimationInfo wda;
protected bool dockAnimPlayed;
public SpriteHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
@@ -32,11 +33,20 @@ namespace OpenRA.Mods.Common.Activities
trait.Docked();
wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence));
dockAnimPlayed = true;
dockingState = DockingState.Loop;
}
public override void OnStateUndock(Actor self)
{
// If dock animation hasn't played, we didn't actually dock and have to skip the undock anim and notification
if (!dockAnimPlayed)
{
dockingState = DockingState.Complete;
return;
}
dockingState = DockingState.Wait;
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence,
() =>
{
@@ -44,7 +54,6 @@ namespace OpenRA.Mods.Common.Activities
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
trait.Undocked();
});
dockingState = DockingState.Wait;
}
}
}