Remove TiberianSunRefinery
Also add IDockClientBody interface, move WithDockingOverlay cnc -> common, remove HarvesterDockSequence implementing classes
This commit is contained in:
committed by
Matthias Mailänder
parent
3f0c3a8b9c
commit
049d0283f9
@@ -14,18 +14,21 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public abstract class HarvesterDockSequence : Activity
|
||||
public class HarvesterDockSequence : Activity
|
||||
{
|
||||
protected enum DockingState { Wait, Turn, Drag, Dock, Loop, Undock, Complete }
|
||||
|
||||
protected readonly Actor RefineryActor;
|
||||
protected readonly Refinery Refinery;
|
||||
protected readonly WithDockingOverlay DockHostSpriteOverlay;
|
||||
protected readonly Harvester Harv;
|
||||
protected readonly IDockClientBody DockClientBody;
|
||||
protected readonly WAngle DockAngle;
|
||||
protected readonly bool IsDragRequired;
|
||||
protected readonly WVec DragOffset;
|
||||
@@ -38,16 +41,20 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly INotifyDockClient[] notifyDockClients;
|
||||
readonly INotifyDockHost[] notifyDockHosts;
|
||||
|
||||
bool dockInitiated = false;
|
||||
|
||||
public HarvesterDockSequence(Actor self, Actor refineryActor, Refinery refinery)
|
||||
{
|
||||
dockingState = DockingState.Turn;
|
||||
Refinery = refinery;
|
||||
RefineryActor = refineryActor;
|
||||
DockHostSpriteOverlay = refineryActor.TraitOrDefault<WithDockingOverlay>();
|
||||
DockAngle = refinery.DeliveryAngle;
|
||||
IsDragRequired = refinery.IsDragRequired;
|
||||
DragOffset = refinery.DragOffset;
|
||||
DragLength = refinery.DragLength;
|
||||
Harv = self.Trait<Harvester>();
|
||||
DockClientBody = self.TraitOrDefault<IDockClientBody>();
|
||||
StartDrag = self.CenterPosition;
|
||||
EndDrag = refineryActor.CenterPosition + DragOffset;
|
||||
notifyDockClients = self.TraitsImplementing<INotifyDockClient>().ToArray();
|
||||
@@ -79,7 +86,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
case DockingState.Dock:
|
||||
if (!IsCanceling && RefineryActor.IsInWorld && !RefineryActor.IsDead && !Harv.IsTraitDisabled)
|
||||
{
|
||||
OnStateDock(self);
|
||||
dockInitiated = true;
|
||||
PlayDockAnimations(self);
|
||||
NotifyDocked(self);
|
||||
}
|
||||
else
|
||||
@@ -94,7 +102,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return false;
|
||||
|
||||
case DockingState.Undock:
|
||||
OnStateUndock(self);
|
||||
if (dockInitiated)
|
||||
PlayUndockAnimations(self);
|
||||
else
|
||||
dockingState = DockingState.Complete;
|
||||
|
||||
return false;
|
||||
|
||||
case DockingState.Complete:
|
||||
@@ -110,19 +122,65 @@ namespace OpenRA.Mods.Common.Activities
|
||||
throw new InvalidOperationException("Invalid harvester dock state");
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets(Actor self)
|
||||
public virtual void PlayDockAnimations(Actor self)
|
||||
{
|
||||
yield return Target.FromActor(RefineryActor);
|
||||
PlayDockCientAnimation(self, () =>
|
||||
{
|
||||
if (DockHostSpriteOverlay != null && !DockHostSpriteOverlay.Visible)
|
||||
{
|
||||
dockingState = DockingState.Wait;
|
||||
DockHostSpriteOverlay.Visible = true;
|
||||
DockHostSpriteOverlay.WithOffset.Animation.PlayThen(DockHostSpriteOverlay.Info.Sequence, () =>
|
||||
{
|
||||
dockingState = DockingState.Loop;
|
||||
DockHostSpriteOverlay.Visible = false;
|
||||
});
|
||||
}
|
||||
else
|
||||
dockingState = DockingState.Loop;
|
||||
});
|
||||
}
|
||||
|
||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||
public virtual void PlayDockCientAnimation(Actor self, Action after)
|
||||
{
|
||||
yield return new TargetLineNode(Target.FromActor(RefineryActor), Color.Green);
|
||||
if (DockClientBody != null)
|
||||
{
|
||||
dockingState = DockingState.Wait;
|
||||
DockClientBody.PlayDockAnimation(self, () => after());
|
||||
}
|
||||
else
|
||||
after();
|
||||
}
|
||||
|
||||
public abstract void OnStateDock(Actor self);
|
||||
public virtual void PlayUndockAnimations(Actor self)
|
||||
{
|
||||
if (RefineryActor.IsInWorld && !RefineryActor.IsDead && DockHostSpriteOverlay != null && !DockHostSpriteOverlay.Visible)
|
||||
{
|
||||
dockingState = DockingState.Wait;
|
||||
DockHostSpriteOverlay.Visible = true;
|
||||
DockHostSpriteOverlay.WithOffset.Animation.PlayBackwardsThen(DockHostSpriteOverlay.Info.Sequence, () =>
|
||||
{
|
||||
PlayUndockClientAnimation(self, () =>
|
||||
{
|
||||
dockingState = DockingState.Complete;
|
||||
DockHostSpriteOverlay.Visible = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
PlayUndockClientAnimation(self, () => dockingState = DockingState.Complete);
|
||||
}
|
||||
|
||||
public abstract void OnStateUndock(Actor self);
|
||||
public virtual void PlayUndockClientAnimation(Actor self, Action after)
|
||||
{
|
||||
if (DockClientBody != null)
|
||||
{
|
||||
dockingState = DockingState.Wait;
|
||||
DockClientBody.PlayReverseDockAnimation(self, () => after());
|
||||
}
|
||||
else
|
||||
after();
|
||||
}
|
||||
|
||||
void NotifyDocked(Actor self)
|
||||
{
|
||||
@@ -142,5 +200,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
foreach (var nd in notifyDockHosts)
|
||||
nd.Undocked(RefineryActor, self);
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets(Actor self)
|
||||
{
|
||||
yield return Target.FromActor(RefineryActor);
|
||||
}
|
||||
|
||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||
{
|
||||
yield return new TargetLineNode(Target.FromActor(RefineryActor), Color.Green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class SpriteHarvesterDockSequence : HarvesterDockSequence
|
||||
{
|
||||
readonly WithSpriteBody wsb;
|
||||
readonly WithDockingAnimationInfo wda;
|
||||
protected bool dockAnimPlayed;
|
||||
|
||||
public SpriteHarvesterDockSequence(Actor self, Actor refineryActor, Refinery refinery)
|
||||
: base(self, refineryActor, refinery)
|
||||
{
|
||||
wsb = self.Trait<WithSpriteBody>();
|
||||
wda = self.Info.TraitInfoOrDefault<WithDockingAnimationInfo>();
|
||||
}
|
||||
|
||||
public override void OnStateDock(Actor self)
|
||||
{
|
||||
if (wda != null)
|
||||
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;
|
||||
|
||||
if (wda == null)
|
||||
dockingState = DockingState.Complete;
|
||||
else
|
||||
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => dockingState = DockingState.Complete);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user