Add INotifyClientMoving interface

This commit is contained in:
Gustas
2023-01-24 19:33:42 +02:00
committed by Matthias Mailänder
parent d0974cfdd2
commit 82458b5f7e
6 changed files with 45 additions and 36 deletions

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Activities
readonly BodyOrientation body; readonly BodyOrientation body;
readonly IMove move; readonly IMove move;
readonly CPos targetCell; readonly CPos targetCell;
readonly INotifyHarvesterAction[] notifyHarvesterActions; readonly INotifyHarvestAction[] notifyHarvestActions;
public HarvestResource(Actor self, CPos targetCell) public HarvestResource(Actor self, CPos targetCell)
{ {
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>(); claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
resourceLayer = self.World.WorldActor.Trait<IResourceLayer>(); resourceLayer = self.World.WorldActor.Trait<IResourceLayer>();
this.targetCell = targetCell; this.targetCell = targetCell;
notifyHarvesterActions = self.TraitsImplementing<INotifyHarvesterAction>().ToArray(); notifyHarvestActions = self.TraitsImplementing<INotifyHarvestAction>().ToArray();
} }
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
// Move towards the target cell // Move towards the target cell
if (self.Location != targetCell) if (self.Location != targetCell)
{ {
foreach (var n in notifyHarvesterActions) foreach (var n in notifyHarvestActions)
n.MovingToResources(self, targetCell); n.MovingToResources(self, targetCell);
QueueChild(move.MoveTo(targetCell, 0)); QueueChild(move.MoveTo(targetCell, 0));
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Activities
harv.AcceptResource(self, resource.Type); harv.AcceptResource(self, resource.Type);
foreach (var t in notifyHarvesterActions) foreach (var t in notifyHarvestActions)
t.Harvested(self, resource.Type); t.Harvested(self, resource.Type);
QueueChild(new Wait(harvInfo.BaleLoadDelay)); QueueChild(new Wait(harvInfo.BaleLoadDelay));
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Activities
public override void Cancel(Actor self, bool keepQueue = false) public override void Cancel(Actor self, bool keepQueue = false)
{ {
foreach (var n in notifyHarvesterActions) foreach (var n in notifyHarvestActions)
n.MovementCancelled(self); n.MovementCancelled(self);
base.Cancel(self, keepQueue); base.Cancel(self, keepQueue);

View File

@@ -22,14 +22,14 @@ namespace OpenRA.Mods.Common.Activities
readonly DockClientManager dockClient; readonly DockClientManager dockClient;
Actor dockHostActor; Actor dockHostActor;
IDockHost dockHost; IDockHost dockHost;
readonly INotifyHarvesterAction[] notifyHarvesterActions; readonly INotifyDockClientMoving[] notifyDockClientMoving;
public MoveToDock(Actor self, Actor dockHostActor = null, IDockHost dockHost = null) public MoveToDock(Actor self, Actor dockHostActor = null, IDockHost dockHost = null)
{ {
dockClient = self.Trait<DockClientManager>(); dockClient = self.Trait<DockClientManager>();
this.dockHostActor = dockHostActor; this.dockHostActor = dockHostActor;
this.dockHost = dockHost; this.dockHost = dockHost;
notifyHarvesterActions = self.TraitsImplementing<INotifyHarvesterAction>().ToArray(); notifyDockClientMoving = self.TraitsImplementing<INotifyDockClientMoving>().ToArray();
} }
public override bool Tick(Actor self) public override bool Tick(Actor self)
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Common.Activities
{ {
if (dockHost.QueueMoveActivity(this, dockHostActor, self, dockClient)) if (dockHost.QueueMoveActivity(this, dockHostActor, self, dockClient))
{ {
foreach (var n in notifyHarvesterActions) foreach (var ndcm in notifyDockClientMoving)
n.MovingToRefinery(self, dockHostActor); ndcm.MovingToDock(self, dockHostActor, dockHost);
return false; return false;
} }
@@ -84,8 +84,8 @@ namespace OpenRA.Mods.Common.Activities
public override void Cancel(Actor self, bool keepQueue = false) public override void Cancel(Actor self, bool keepQueue = false)
{ {
dockClient.UnreserveHost(); dockClient.UnreserveHost();
foreach (var n in notifyHarvesterActions) foreach (var ndcm in notifyDockClientMoving)
n.MovementCancelled(self); ndcm.MovementCancelled(self);
base.Cancel(self, keepQueue); base.Cancel(self, keepQueue);
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new CarryableHarvester(); } public override object Create(ActorInitializer init) { return new CarryableHarvester(); }
} }
public class CarryableHarvester : INotifyCreated, INotifyHarvesterAction public class CarryableHarvester : INotifyCreated, INotifyHarvestAction, INotifyDockClientMoving
{ {
ICallForTransport[] transports; ICallForTransport[] transports;
@@ -28,25 +28,30 @@ namespace OpenRA.Mods.Common.Traits
transports = self.TraitsImplementing<ICallForTransport>().ToArray(); transports = self.TraitsImplementing<ICallForTransport>().ToArray();
} }
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) void INotifyHarvestAction.MovingToResources(Actor self, CPos targetCell)
{ {
foreach (var t in transports) foreach (var t in transports)
t.RequestTransport(self, targetCell); t.RequestTransport(self, targetCell);
} }
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor) void INotifyHarvestAction.MovementCancelled(Actor self)
{
var dock = refineryActor.Trait<IDockHost>();
foreach (var t in transports)
t.RequestTransport(self, self.World.Map.CellContaining(dock.DockPosition));
}
void INotifyHarvesterAction.MovementCancelled(Actor self)
{ {
foreach (var t in transports) foreach (var t in transports)
t.MovementCancelled(self); t.MovementCancelled(self);
} }
void INotifyHarvesterAction.Harvested(Actor self, string resourceType) { } void INotifyDockClientMoving.MovingToDock(Actor self, Actor hostActor, IDockHost host)
{
foreach (var t in transports)
t.RequestTransport(self, self.World.Map.CellContaining(host.DockPosition));
}
void INotifyDockClientMoving.MovementCancelled(Actor self)
{
foreach (var t in transports)
t.MovementCancelled(self);
}
void INotifyHarvestAction.Harvested(Actor self, string resourceType) { }
} }
} }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithHarvestAnimation(init, this); } public override object Create(ActorInitializer init) { return new WithHarvestAnimation(init, this); }
} }
public class WithHarvestAnimation : INotifyHarvesterAction public class WithHarvestAnimation : INotifyHarvestAction
{ {
public readonly WithHarvestAnimationInfo Info; public readonly WithHarvestAnimationInfo Info;
readonly WithSpriteBody wsb; readonly WithSpriteBody wsb;
@@ -37,15 +37,14 @@ namespace OpenRA.Mods.Common.Traits.Render
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body); wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
} }
void INotifyHarvesterAction.Harvested(Actor self, string resourceType) void INotifyHarvestAction.Harvested(Actor self, string resourceType)
{ {
var sequence = wsb.NormalizeSequence(self, Info.HarvestSequence); var sequence = wsb.NormalizeSequence(self, Info.HarvestSequence);
if (wsb.DefaultAnimation.HasSequence(sequence) && wsb.DefaultAnimation.CurrentSequence.Name != sequence) if (wsb.DefaultAnimation.HasSequence(sequence) && wsb.DefaultAnimation.CurrentSequence.Name != sequence)
wsb.PlayCustomAnimation(self, sequence); wsb.PlayCustomAnimation(self, sequence);
} }
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) { } void INotifyHarvestAction.MovingToResources(Actor self, CPos targetCell) { }
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor) { } void INotifyHarvestAction.MovementCancelled(Actor self) { }
void INotifyHarvesterAction.MovementCancelled(Actor self) { }
} }
} }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithHarvestOverlay(init.Self, this); } public override object Create(ActorInitializer init) { return new WithHarvestOverlay(init.Self, this); }
} }
sealed class WithHarvestOverlay : INotifyHarvesterAction sealed class WithHarvestOverlay : INotifyHarvestAction
{ {
readonly WithHarvestOverlayInfo info; readonly WithHarvestOverlayInfo info;
readonly Animation anim; readonly Animation anim;
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits.Render
p => ZOffsetFromCenter(self, p, 0)), info.Palette); p => ZOffsetFromCenter(self, p, 0)), info.Palette);
} }
void INotifyHarvesterAction.Harvested(Actor self, string resourceType) void INotifyHarvestAction.Harvested(Actor self, string resourceType)
{ {
if (visible) if (visible)
return; return;
@@ -63,9 +63,8 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.PlayThen(info.Sequence, () => visible = false); anim.PlayThen(info.Sequence, () => visible = false);
} }
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) { } void INotifyHarvestAction.MovingToResources(Actor self, CPos targetCell) { }
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor targetRefinery) { } void INotifyHarvestAction.MovementCancelled(Actor self) { }
void INotifyHarvesterAction.MovementCancelled(Actor self) { }
public static int ZOffsetFromCenter(Actor self, WPos pos, int offset) public static int ZOffsetFromCenter(Actor self, WPos pos, int offset)
{ {

View File

@@ -170,6 +170,13 @@ namespace OpenRA.Mods.Common.Traits
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface INotifyDockClient { void Docked(Actor self, Actor host); void Undocked(Actor self, Actor host); } public interface INotifyDockClient { void Docked(Actor self, Actor host); void Undocked(Actor self, Actor host); }
[RequireExplicitImplementation]
public interface INotifyDockClientMoving
{
void MovingToDock(Actor self, Actor hostActor, IDockHost host);
void MovementCancelled(Actor self);
}
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface INotifyResourceAccepted { void OnResourceAccepted(Actor self, Actor refinery, string resourceType, int count, int value); } public interface INotifyResourceAccepted { void OnResourceAccepted(Actor self, Actor refinery, string resourceType, int count, int value); }
public interface INotifyParachute { void OnParachute(Actor self); void OnLanded(Actor self); } public interface INotifyParachute { void OnParachute(Actor self); void OnLanded(Actor self); }
@@ -202,12 +209,11 @@ namespace OpenRA.Mods.Common.Traits
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface INotifyExitedCargo { void OnExitedCargo(Actor self, Actor cargo); } public interface INotifyExitedCargo { void OnExitedCargo(Actor self, Actor cargo); }
public interface INotifyHarvesterAction public interface INotifyHarvestAction
{ {
void MovingToResources(Actor self, CPos targetCell);
void MovingToRefinery(Actor self, Actor refineryActor);
void MovementCancelled(Actor self);
void Harvested(Actor self, string resourceType); void Harvested(Actor self, string resourceType);
void MovingToResources(Actor self, CPos targetCell);
void MovementCancelled(Actor self);
} }
public interface IDockClientInfo : ITraitInfoInterface { } public interface IDockClientInfo : ITraitInfoInterface { }