Moved HarvesterDockSequence notifications to the base class
And fix a minor oversight in VoxelHarvesterDockSequence.cs
This commit is contained in:
@@ -30,11 +30,6 @@ namespace OpenRA.Mods.Cnc.Activities
|
||||
public override void OnStateDock(Actor self)
|
||||
{
|
||||
body.Docked = true;
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDockClient>())
|
||||
nd.Docked(self, Refinery);
|
||||
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDockHost>())
|
||||
nd.Docked(Refinery, self);
|
||||
|
||||
if (spriteOverlay != null && !spriteOverlay.Visible)
|
||||
{
|
||||
@@ -63,26 +58,12 @@ namespace OpenRA.Mods.Cnc.Activities
|
||||
dockingState = DockingState.Complete;
|
||||
body.Docked = false;
|
||||
spriteOverlay.Visible = false;
|
||||
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDockClient>())
|
||||
nd.Undocked(self, Refinery);
|
||||
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDockHost>())
|
||||
nd.Undocked(Refinery, self);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
dockingState = DockingState.Complete;
|
||||
body.Docked = false;
|
||||
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDockClient>())
|
||||
nd.Undocked(self, Refinery);
|
||||
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDockHost>())
|
||||
nd.Undocked(Refinery, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
@@ -33,6 +34,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
protected DockingState dockingState;
|
||||
|
||||
readonly INotifyDockClient[] notifyDockClients;
|
||||
readonly INotifyDockHost[] notifyDockHosts;
|
||||
|
||||
public HarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, in WVec dragOffset, int dragLength)
|
||||
{
|
||||
dockingState = DockingState.Turn;
|
||||
@@ -44,6 +48,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
Harv = self.Trait<Harvester>();
|
||||
StartDrag = self.CenterPosition;
|
||||
EndDrag = refinery.CenterPosition + DragOffset;
|
||||
notifyDockClients = self.TraitsImplementing<INotifyDockClient>().ToArray();
|
||||
notifyDockHosts = refinery.TraitsImplementing<INotifyDockHost>().ToArray();
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
@@ -70,7 +76,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
case DockingState.Dock:
|
||||
if (!IsCanceling && Refinery.IsInWorld && !Refinery.IsDead && !Harv.IsTraitDisabled)
|
||||
{
|
||||
OnStateDock(self);
|
||||
NotifyDocked(self);
|
||||
}
|
||||
else
|
||||
dockingState = DockingState.Undock;
|
||||
|
||||
@@ -89,6 +98,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
case DockingState.Complete:
|
||||
Harv.LastLinkedProc = Harv.LinkedProc;
|
||||
Harv.LinkProc(null);
|
||||
NotifyUndocked(self);
|
||||
if (IsDragRequired)
|
||||
QueueChild(new Drag(self, EndDrag, StartDrag, DragLength));
|
||||
|
||||
@@ -111,5 +121,24 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public abstract void OnStateDock(Actor self);
|
||||
|
||||
public abstract void OnStateUndock(Actor self);
|
||||
|
||||
void NotifyDocked(Actor self)
|
||||
{
|
||||
foreach (var nd in notifyDockClients)
|
||||
nd.Docked(self, Refinery);
|
||||
|
||||
foreach (var nd in notifyDockHosts)
|
||||
nd.Docked(Refinery, self);
|
||||
}
|
||||
|
||||
void NotifyUndocked(Actor self)
|
||||
{
|
||||
foreach (var nd in notifyDockClients)
|
||||
nd.Undocked(self, Refinery);
|
||||
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in notifyDockHosts)
|
||||
nd.Undocked(Refinery, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override void OnStateDock(Actor self)
|
||||
{
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDockClient>())
|
||||
nd.Docked(self, Refinery);
|
||||
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDockHost>())
|
||||
nd.Docked(Refinery, self);
|
||||
|
||||
if (wda != null)
|
||||
wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence));
|
||||
|
||||
@@ -54,20 +48,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
dockingState = DockingState.Wait;
|
||||
|
||||
if (wda == null)
|
||||
NotifyUndock(self);
|
||||
dockingState = DockingState.Complete;
|
||||
else
|
||||
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => NotifyUndock(self));
|
||||
}
|
||||
|
||||
void NotifyUndock(Actor self)
|
||||
{
|
||||
dockingState = DockingState.Complete;
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDockClient>())
|
||||
nd.Undocked(self, Refinery);
|
||||
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDockHost>())
|
||||
nd.Undocked(Refinery, self);
|
||||
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, () => dockingState = DockingState.Complete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user