Move interaction priority into daemon operations
This commit is contained in:
parent
712c34bf52
commit
7e80803a88
7 changed files with 188 additions and 27 deletions
|
|
@ -2000,17 +2000,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
}
|
||||
else if (CurrentEntity.Parent == null)
|
||||
{
|
||||
foreach (var wormhole in ZoneRenderer.WormholeInstances.Keys)
|
||||
{
|
||||
if (!(CultMath.math.length(wormhole.Position - CurrentEntity.CultPositionXZ) < Settings.GameplaySettings.WormholeExitRadius)) continue;
|
||||
RequestEnterWormhole(wormhole);
|
||||
return;
|
||||
}
|
||||
RequestDock();
|
||||
}
|
||||
else RequestUndock();
|
||||
else RequestInteract();
|
||||
};
|
||||
|
||||
Input.Global.MainMenu.performed += context =>
|
||||
|
|
@ -2165,35 +2155,29 @@ public class ActionGameManager : MonoBehaviour
|
|||
foreach (var a in _actionBarActions) a.Disable();
|
||||
}
|
||||
|
||||
private void RequestEnterWormhole(Wormhole wormhole)
|
||||
private void RequestInteract()
|
||||
{
|
||||
TryRequestDaemonEnterWormhole(wormhole);
|
||||
TryRequestDaemonInteract();
|
||||
}
|
||||
|
||||
private bool TryRequestDaemonEnterWormhole(Wormhole wormhole)
|
||||
private bool TryRequestDaemonInteract()
|
||||
{
|
||||
var observer = ResolveDaemonObserver();
|
||||
if (observer == null ||
|
||||
!observer.HasAuthoritativeState ||
|
||||
wormhole == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetZoneIndex = ZoneIndex(wormhole.Target);
|
||||
if (targetZoneIndex < 0)
|
||||
if (observer == null || !observer.HasAuthoritativeState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
observer.Operations.EnterWormhole(targetZoneIndex, wormhole.Position.x, wormhole.Position.y);
|
||||
observer.Operations.Interact(
|
||||
Settings.GameplaySettings.DockingDistance,
|
||||
Settings.GameplaySettings.WormholeExitRadius);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to send Aetheria daemon wormhole operation; operation not submitted: {ex.Message}");
|
||||
Debug.LogWarning($"Failed to send Aetheria daemon interact operation; operation not submitted: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,6 +210,11 @@ public sealed class AetheriaDaemonOperations
|
|||
return Send((client, observed) => client.Undock(observed));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope Interact(double dockDistance, double wormholeDistance)
|
||||
{
|
||||
return Send((client, observed) => client.Interact(observed, dockDistance, wormholeDistance));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope SetDockedCurrentShip(string targetEntityKey)
|
||||
{
|
||||
return Send((client, observed) => client.SetDockedCurrentShip(observed, targetEntityKey));
|
||||
|
|
|
|||
|
|
@ -2003,6 +2003,79 @@ public class DaemonRuntimeDocumentTests
|
|||
CollectionAssert.Contains(run.Zones[0].Entities[1].DockingBayAssignments, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsInteractPrioritizesUndockWormholeThenDock()
|
||||
{
|
||||
var undockRun = RunWithTwoEntities();
|
||||
undockRun.Zones[0].Entities[1].ChildEntityIndices = new[] { 0 };
|
||||
undockRun.Zones[0].Entities[1].DockingBayAssignments = new[] { 0, -1 };
|
||||
var undock = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.Interact,
|
||||
"codex",
|
||||
"session-interact",
|
||||
46,
|
||||
"zone.0.entity.0");
|
||||
undock.ScalarValue = 10;
|
||||
undock.PositionX = 10;
|
||||
|
||||
var undockResult = AetheriaRuntimeDaemonOperations.Execute(undockRun, new[] { undock });
|
||||
Assert.AreEqual(1, undockResult.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(1, undockResult.Intents.Docking.Count);
|
||||
Assert.IsTrue(undockResult.Intents.Docking[0].Undock);
|
||||
CollectionAssert.DoesNotContain(undockRun.Zones[0].Entities[1].DockingBayAssignments, 0);
|
||||
|
||||
var wormholeRun = RunWithTwoEntities();
|
||||
wormholeRun.Zones[0].AdjacentZoneIndices = new[] { 2 };
|
||||
wormholeRun.Zones[0].Entities[0].PositionX = 0;
|
||||
wormholeRun.Zones[0].Entities[0].PositionZ = 0;
|
||||
wormholeRun.Zones = wormholeRun.Zones
|
||||
.Concat(new[]
|
||||
{
|
||||
new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 2,
|
||||
PositionX = 3,
|
||||
PositionY = 4
|
||||
}
|
||||
})
|
||||
.ToArray();
|
||||
var wormhole = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.Interact,
|
||||
"codex",
|
||||
"session-interact",
|
||||
47,
|
||||
"zone.0.entity.0");
|
||||
wormhole.ScalarValue = 10;
|
||||
wormhole.PositionX = 10;
|
||||
|
||||
var wormholeResult = AetheriaRuntimeDaemonOperations.Execute(wormholeRun, new[] { wormhole });
|
||||
Assert.AreEqual(1, wormholeResult.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(1, wormholeResult.Intents.Wormholes.Count);
|
||||
Assert.AreEqual(2, wormholeRun.CurrentZoneIndex);
|
||||
Assert.AreEqual(3, FindZone(wormholeRun, 2).Entities[0].PositionX, 0.0001);
|
||||
Assert.AreEqual(4, FindZone(wormholeRun, 2).Entities[0].PositionZ, 0.0001);
|
||||
|
||||
var dockRun = RunWithTwoEntities();
|
||||
dockRun.Zones[0].Entities[0].PositionX = 0;
|
||||
dockRun.Zones[0].Entities[0].PositionY = 0;
|
||||
dockRun.Zones[0].Entities[1].PositionX = 3;
|
||||
dockRun.Zones[0].Entities[1].PositionY = 4;
|
||||
var dock = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.Interact,
|
||||
"codex",
|
||||
"session-interact",
|
||||
48,
|
||||
"zone.0.entity.0");
|
||||
dock.ScalarValue = 10;
|
||||
dock.PositionX = 1;
|
||||
|
||||
var dockResult = AetheriaRuntimeDaemonOperations.Execute(dockRun, new[] { dock });
|
||||
Assert.AreEqual(1, dockResult.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(1, dockResult.Intents.Docking.Count);
|
||||
Assert.IsTrue(dockResult.Intents.Docking[0].Dock);
|
||||
CollectionAssert.Contains(dockRun.Zones[0].Entities[1].ChildEntityIndices, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsTowsEntityToStationInDaemonState()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue