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