diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 1d58770cc..f46748c62 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -7777,7 +7777,12 @@ static void RequireMainMenuContinueRunState(string root) "entity.RestoreStatGrids(entitySnapshot.StatGrids)", "RestoreThermalExposure((float)entitySnapshot.Heatstroke, (float)entitySnapshot.Hypothermia)", "entity.HeatsinksEnabled = entitySnapshot.HeatsinksEnabled", - "RestoreDroppedPickupsFromDaemonZoneState" + "RestoreDroppedPickupsFromDaemonZoneState", + "TryGetDaemonEntitySnapshot(", + "TryGetDaemonParentSnapshot(", + "parentSnapshot.DockingBayAssignments", + "dockedEntitySnapshot.ChildEntityIndices", + "TryGetObservedEntityFacade(childEntityIndex, out var entity)" }; if (actionGameManager.Contains("_authoritativeDaemonEntities", StringComparison.Ordinal)) @@ -7814,7 +7819,9 @@ static void RequireMainMenuContinueRunState(string root) "UpdateTargetPanel(CurrentEntity.Target.Value)", "var target = CurrentEntity.Target.Value;", "TargetIndicator.Target = CurrentEntity.Target.Value.Position", - "indicator.Target = CurrentEntity.Target.Value.Position" + "indicator.Target = CurrentEntity.Target.Value.Position", + "foreach (var bay in CurrentEntity.Parent.DockingBays)", + "foreach (var entity in DockedEntity.Children)" }; var forbiddenGameplayHits = forbiddenGameplaySymbols diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 79d49d046..394cf39f5 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -3152,6 +3152,46 @@ public class ActionGameManager : MonoBehaviour return FindDaemonZoneSnapshot(CurrentDaemonGalaxyZone); } + private bool TryGetDaemonEntitySnapshot(Entity entity, out AetheriaRuntimeEntitySnapshotCommit snapshot) + { + snapshot = null; + if (entity == null || entity.DaemonEntityIndex < 0) + return false; + + snapshot = (FindCurrentDaemonZoneSnapshot()?.Entities ?? Array.Empty()) + .FirstOrDefault(candidate => candidate != null && candidate.EntityIndex == entity.DaemonEntityIndex); + return snapshot != null; + } + + private bool TryGetDaemonParentSnapshot( + Entity child, + out AetheriaRuntimeEntitySnapshotCommit parentSnapshot, + out Entity parent) + { + parentSnapshot = null; + parent = null; + if (child == null || child.DaemonEntityIndex < 0) + return false; + + foreach (var candidate in FindCurrentDaemonZoneSnapshot()?.Entities ?? Array.Empty()) + { + if (candidate == null) + continue; + + if (!(candidate.ChildEntityIndices ?? Array.Empty()).Contains(child.DaemonEntityIndex) && + !(candidate.DockingBayAssignments ?? Array.Empty()).Contains(child.DaemonEntityIndex)) + { + continue; + } + + parentSnapshot = candidate; + TryGetObservedEntityFacade(candidate.EntityIndex, out parent); + return true; + } + + return false; + } + private bool TryQueryDaemonEntityContact( Entity observer, Entity target, @@ -3469,24 +3509,39 @@ public class ActionGameManager : MonoBehaviour public IEnumerable AvailableCargoBays() { - if (CurrentEntity.Parent != null) + if (!TryGetDaemonParentSnapshot(CurrentEntity, out var parentSnapshot, out var parent)) + yield break; + + var assignments = parentSnapshot.DockingBayAssignments ?? Array.Empty(); + for (var bayIndex = 0; bayIndex < assignments.Count; bayIndex++) { - foreach (var bay in CurrentEntity.Parent.DockingBays) - { - if (bay.DockedShip.IsPlayerShip) yield return bay; - } + var dockedEntityIndex = assignments[bayIndex]; + if (dockedEntityIndex < 0 || + parent == null || + bayIndex >= parent.DockingBays.Count || + !TryGetObservedEntityFacade(dockedEntityIndex, out var dockedEntity) || + !(dockedEntity is Ship { IsPlayerShip: true })) + continue; + + yield return parent.DockingBays[bayIndex]; } } public IEnumerable AvailableEntities() { - if(DockedEntity != null) - foreach (var entity in DockedEntity.Children) + if (DockedEntity != null && TryGetDaemonEntitySnapshot(DockedEntity, out var dockedEntitySnapshot)) + { + foreach (var childEntityIndex in dockedEntitySnapshot.ChildEntityIndices ?? Array.Empty()) { - if (entity is Ship { IsPlayerShip: true }) yield return entity; + if (TryGetObservedEntityFacade(childEntityIndex, out var entity) && + entity is Ship { IsPlayerShip: true }) + yield return entity; } + } else if (CurrentEntity != null) + { yield return CurrentEntity; + } } public void PlayMusic(MusicType type)