From def4a5b906152384b5dd77fe1043df92a437b20e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 11 Jul 2026 19:07:29 +0100 Subject: [PATCH] Make loot pickup capacity checked and exactly once --- Aetheria.State.Daemon.Smoke/Program.cs | 29 +++++++++++++++++++ .../Runtime/AetheriaRuntimeDaemonDocuments.cs | 3 ++ .../AetheriaRuntimeDaemonOperationClient.cs | 4 ++- .../AetheriaRuntimeDaemonOperations.cs | 13 +++++++-- .../AetheriaRuntimeDaemonOperationsClient.cs | 6 ++-- .../AetheriaRuntimeDaemonSimulation.cs | 11 +++++++ .../AetheriaRuntimeSnapshotDocuments.cs | 6 ++++ docs/original-game-migration-matrix.md | 2 +- 8 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index 1ef549dbe..bf2a5760e 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -14,6 +14,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks MissingPhysicsOwnerCannotAdvanceProjectiles(); MissingWorldPhysicsOwnerCannotAdvanceShips(); TractorRampsAndPullsThroughYmirWithoutTeleportingCargo(); + PickupIsCapacityCheckedExactlyOnceAndExpires(); ThermalCellsUseFossilConductionAndRadiation(); MultipleActorsUseTheSameMovementLever(); AgentClaimsAndCompletesExploreTaskThroughCommands(); @@ -815,6 +816,34 @@ internal sealed class AetheriaDaemonYmirSmokeChecks RequireEqual(0, CargoQuantity(ship, "salvage"), "scooping must remain a separate capacity-checked transaction"); } + private static void PickupIsCapacityCheckedExactlyOnceAndExpires() + { + var hull = CatalogItem("pickup-hull"); hull.HullCapacity = PerformanceStat(1); + var salvage = CatalogItem("salvage"); salvage.Volume = 1; + var catalog = new AetheriaRuntimeCatalogSnapshot([hull, salvage], [], []); + var ship = Entity(0, 0, "player"); ship.HullItemKey = hull.ItemKey; ship.CargoContents = [Cargo()]; + var zone = new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [ship], DroppedPickups = [new AetheriaRuntimeDroppedPickupCommit { PickupIndex = 7, PositionX = 10, Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = salvage.ItemKey, Quantity = 1 }, LifetimeSeconds = 30 }] }; + var run = new AetheriaRuntimeRunCheckpointCommit { CurrentZoneIndex = 0, CurrentEntityKey = "zone.0.entity.0", Zones = [zone] }; + AetheriaRuntimeDaemonCommandDocument Pickup(string id, int index) + { + var command = AetheriaRuntimeDaemonCommandDocument.Create(AetheriaRuntimeDaemonCommandKinds.PickUpLoot, "pilot", "pickup-smoke", 0, "zone.0.entity.0"); + command.CommandId = id; command.TargetEntityKey = "zone.0.entity.0"; command.LootPickup.ItemKey = salvage.ItemKey; command.LootPickup.Quantity = 1; command.LootPickup.PickupIndex = index; return command; + } + var first = AetheriaRuntimeDaemonOperations.Execute(run, [Pickup("pickup-first", 7)], new AetheriaRuntimeDaemonOperationContext { Catalog = catalog }); + Require(first.AppliedCommandIds.Contains("pickup-first"), "nearby pickup with capacity must apply"); + RequireEqual(1, CargoQuantity(ship, salvage.ItemKey), "successful pickup must enter cargo"); + var duplicate = AetheriaRuntimeDaemonOperations.Execute(run, [Pickup("pickup-duplicate", 7)], new AetheriaRuntimeDaemonOperationContext { Catalog = catalog }); + Require(duplicate.RejectedCommandIds.Contains("pickup-duplicate"), "consumed pickup identity must reject duplicate collection"); + + zone.DroppedPickups = [new AetheriaRuntimeDroppedPickupCommit { PickupIndex = 8, PositionX = 10, Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = salvage.ItemKey, Quantity = 1 }, LifetimeSeconds = 30 }]; + var full = AetheriaRuntimeDaemonOperations.Execute(run, [Pickup("pickup-full", 8)], new AetheriaRuntimeDaemonOperationContext { Catalog = catalog }); + Require(full.RejectedCommandIds.Contains("pickup-full") && zone.DroppedPickups.Count == 1, + "full cargo must reject without deleting pickup"); + AetheriaRuntimeDaemonTickRunner.Tick(Path.Combine(Path.GetTempPath(), "aetheria-pickup-expiry-smoke.cc"), run, + new AetheriaRuntimeDaemonTickOptions { WorldPhysics = new AetheriaYmirWorldPhysics(), FrameId = 1, FixedDeltaSeconds = 30, SimulationTimeSeconds = 30, ProjectilePhysics = AetheriaRuntimeProjectilePhysicsUnavailable.Instance, BuildPublications = false }); + RequireEqual(0, zone.DroppedPickups.Count, "pickup must expire after the fossil thirty-second lifetime"); + } + private static (AetheriaRuntimeRunCheckpointCommit Run, AetheriaRuntimeZoneSnapshotCommit Zone, AetheriaRuntimeEntitySnapshotCommit Target) Scenario() { var source = Entity(1, -100, "player"); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs index 0b0b709b6..60eb2057a 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs @@ -905,6 +905,9 @@ namespace GameCult.Aetheria.State.Verse [Key(4)] public double PositionZ { get; set; } + + [Key(5)] + public int PickupIndex { get; set; } = -1; } [MessagePackObject] diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs index b1b9f36c8..e9325d92f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs @@ -483,7 +483,8 @@ namespace GameCult.Aetheria.State.Verse int quantity, double positionX, double positionY, - double positionZ) + double positionZ, + int pickupIndex = -1) { var command = Create(AetheriaRuntimeDaemonCommandKinds.PickUpLoot, frame); command.TargetEntityKey = targetEntityKey ?? ""; @@ -497,6 +498,7 @@ namespace GameCult.Aetheria.State.Verse command.LootPickup.PositionX = positionX; command.LootPickup.PositionY = positionY; command.LootPickup.PositionZ = positionZ; + command.LootPickup.PickupIndex = pickupIndex; return Send(command); } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index 3a24d09c0..2219c2487 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -141,7 +141,7 @@ namespace GameCult.Aetheria.State.Verse case AetheriaRuntimeDaemonCommandKinds.StoreItem: return ApplyStoreItem(run, command); case AetheriaRuntimeDaemonCommandKinds.PickUpLoot: - return ApplyPickUpLoot(run, command); + return ApplyPickUpLoot(run, command, context.Catalog); case AetheriaRuntimeDaemonCommandKinds.ToggleHullConductivity: return ApplyToggleHullConductivity(run, command); case AetheriaRuntimeDaemonCommandKinds.TradePurchase: @@ -786,7 +786,8 @@ namespace GameCult.Aetheria.State.Verse private static bool ApplyPickUpLoot( AetheriaRuntimeRunCheckpointCommit run, - AetheriaRuntimeDaemonCommandDocument command) + AetheriaRuntimeDaemonCommandDocument command, + AetheriaRuntimeCatalogSnapshot? catalog) { if (!TryResolveEntity(run, command.TargetEntityKey, out var zoneIndex, out _, out var entity)) return false; @@ -802,6 +803,11 @@ namespace GameCult.Aetheria.State.Verse return false; var pickup = pickups[pickupIndex]; + var quantity = Math.Max(1, pickup.Item?.Quantity ?? command.LootPickup.Quantity); + if (pickup.AgeSeconds >= pickup.LifetimeSeconds || + Math.Pow(pickup.PositionX - entity.PositionX, 2) + Math.Pow(pickup.PositionZ - entity.PositionZ, 2) > 25 * 25 || + quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(entity, catalog, pickup.Item?.ItemKey ?? command.LootPickup.ItemKey)) + return false; pickups.RemoveAt(pickupIndex); zone.DroppedPickups = pickups.ToArray(); @@ -1956,6 +1962,9 @@ namespace GameCult.Aetheria.State.Verse if (pickup == null || !IsItemMatch(pickup.Item, pickupCommand.ItemKey)) return false; + if (pickupCommand.PickupIndex >= 0) + return pickup.PickupIndex == pickupCommand.PickupIndex; + var expectedX = pickupCommand.PositionX; var expectedY = pickupCommand.PositionY; var expectedZ = pickupCommand.PositionZ; diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs index 6ae98880e..6a94a979d 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs @@ -328,7 +328,8 @@ public sealed class AetheriaRuntimeDaemonOperationsClient int quantity, double positionX, double positionY, - double positionZ) + double positionZ, + int pickupIndex = -1) { return Send((client, frame) => client.PickUpLoot( frame, @@ -337,7 +338,8 @@ public sealed class AetheriaRuntimeDaemonOperationsClient quantity, positionX, positionY, - positionZ)); + positionZ, + pickupIndex)); } public CultMeshOperationReceipt RestoreLoadout( diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index b671bbd1c..4a4f5359f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -41,6 +41,8 @@ namespace GameCult.Aetheria.State.Verse if (entities.Length == 0) continue; + StepPickupLifetimes(zone, deltaSeconds); + EnsureStats(entities, settings); foreach (var entity in entities) AetheriaRuntimeThermalSimulation.EnsureState(entity); @@ -57,6 +59,15 @@ namespace GameCult.Aetheria.State.Verse } } + private static void StepPickupLifetimes(AetheriaRuntimeZoneSnapshotCommit zone, double deltaSeconds) + { + foreach (var pickup in zone.DroppedPickups ?? Array.Empty()) + if (pickup != null) pickup.AgeSeconds += deltaSeconds; + zone.DroppedPickups = (zone.DroppedPickups ?? Array.Empty()) + .Where(pickup => pickup != null && pickup.AgeSeconds < pickup.LifetimeSeconds) + .ToArray(); + } + private static void StepTractorPower(IReadOnlyList entities, double deltaSeconds) { foreach (var entity in entities) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs index 3480289c7..755884d9c 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs @@ -592,6 +592,12 @@ namespace GameCult.Aetheria.State.Verse [Key(7)] public AetheriaRuntimeLoadoutItemCommit Item { get; set; } = new AetheriaRuntimeLoadoutItemCommit(); + + [Key(8)] + public double AgeSeconds { get; set; } + + [Key(9)] + public double LifetimeSeconds { get; set; } = 30; } [MessagePackObject] diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 6b9a4d2d6..a71210d94 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -25,7 +25,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Thermal/energy | cell conduction and capacitor/reactor/radiator network | daemon | ship/equipment status and warnings | schematic/post effects | cell conduction/radiation wired; energy network and medical thresholds remain reference | capacitor/reactor/radiator ordering, shared energy and medical timelines | | Weapons | ServerShared behaviors + Unity effects | daemon + Ymir where spatial | action capability, weapon state, attack events | effects/audio/HUD | one synthetic weapon wired; original engine reference-only | each weapon family | | Destruction/drops | entity death and pickup paths | daemon | death/drop events and world entities | effects and pickups | fragments wired; chronology and original drop transaction absent | exactly-once drops and cleanup | -| Tractor/scoop | analog tractor and physical timed pickups | daemon + Ymir | tractor power, target, pickup entity and receipt | beam/interaction feedback | fossil 2/s power ramp and authored radius/traction/distance move targets through Ymir; instant cargo teleport deleted; pickup transaction remains partial | sphere-cast filtering, failed capacity, pickup lifetime and exactly-once receipt | +| Tractor/scoop | analog tractor and physical timed pickups | daemon + Ymir | tractor power, target, pickup entity and receipt | beam/interaction feedback | fossil 2/s power ramp and authored radius/traction/distance move targets through Ymir; pickup uses stable identity, range/capacity validation, exactly-once removal, and 30s daemon lifetime; instant cargo teleport deleted | put dropped pickup trajectories and failed-capacity bounce into the Ymir world; prove runtime feedback | | Dock/undock | wormhole-first interact; first eligible bay; component prerequisites | daemon + Ymir placement | dock commands/context | camera/UI transition | daemon path wired/projected; Ymir placement and parity unproven | priority, eligibility, placement and reconnect | | Inventory/equipment | inventory panels + ServerShared | daemon | inventory/equipment surfaces | generic UI | owner-exists; wired/projected in fragments; not proven | all transfer directions and rejection | | Trade | trade UI/economy | daemon | stock, quote, purchase commands | generic UI | purchase owner wired/projected; not proven | atomic purchase and capacity |