diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index f66511d53..d34b3c87d 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -161,6 +161,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks CanonicalCatalogPublishesRecoveredMineLauncher, EnergyFundedShieldInterceptsDamageBeforeHull, ArmorCellsResolveBeforeEquipmentAndHull, + EquipmentDestructionDisablesBehaviorAndCockpitKillsBeforeHull, DestructionDropsLootExactlyOnce, DaemonSimulationTreatsYmirHitAsPresentationOnly, ProjectileContactCannotKill, @@ -1301,6 +1302,116 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "Eve world projection must expose the exact daemon-owned schematic grid"); } + private static void EquipmentDestructionDisablesBehaviorAndCockpitKillsBeforeHull() + { + var source = Entity(0, -100, "player"); + var target = Entity(1, 0, "neutral"); + target.HullItemKey = "equipment-damage-hull"; + target.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 0, Y = 0, + Item = new AetheriaRuntimeLoadoutItemCommit + { ItemKey = "damageable-weapon", Quality = 1, Durability = 1, Enabled = true } + }]; + target.WeaponStates = [new AetheriaRuntimeWeaponStateCommit + { + OwnerKind = AetheriaRuntimeBehaviorStateProjector.EquipmentOwnerKind, + OwnerIndex = 0, BehaviorIndex = 0, BehaviorKind = "InstantWeapon", + Firing = true, TriggerPending = true, BurstRemaining = 2, + Charging = true, Charged = true, Charge = 1, + LockProgress = 1, LockTargetEntityIndex = source.EntityIndex + }]; + var hull = HullCatalogItem("equipment-damage-hull", 1, 1, 0); + var weapon = CatalogItem("damageable-weapon", new AetheriaRuntimeBehaviorPayload( + 0, "InstantWeapon", 0, [])); + weapon.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + var catalog = new AetheriaRuntimeCatalogSnapshot([hull, weapon], [], []); + var zone = new AetheriaRuntimeZoneSnapshotCommit + { + ZoneIndex = 0, Entities = [source, target], PhysicalPayloads = [new AetheriaRuntimePhysicalPayloadCommit + { + PayloadId = "equipment-destruction", PayloadKind = "mine", WeaponItemKey = "test-cannon", + SourceEntityIndex = source.EntityIndex, PositionX = target.PositionX, PositionZ = target.PositionZ, + LifetimeSeconds = 30, BlastRadius = 200, PayloadMagnitude = 1, + TriggeredAtSeconds = 0, DetonationDelaySeconds = 0, Stationary = true, Active = true + }] + }; + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "equipment-destruction-smoke", CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", Zones = [zone] + }; + + AetheriaRuntimeDaemonSimulation.Step(run, new AetheriaRuntimeDaemonIntentState(), 0.1, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault, NewPhysics(), catalog, 1, 0.1); + + Require(target.IsActive && Math.Abs(Stat(target, "hull") - 100) < 0.000001, + "destroying ordinary equipment must not manufacture hull damage or destroy the entity"); + RequireNear(0, target.Equipment.Single().Item.Durability, 0.000001, + "equipment damage must durably cross into the fossil destroyed state"); + RequireEqual(1, AetheriaRuntimeEquippedBehaviorQueries.Find(target, catalog, "InstantWeapon").Count, + "destroyed equipment must remain installed as durable loadout state"); + RequireEqual(0, AetheriaRuntimeEquippedBehaviorQueries.FindOperational(target, catalog, "InstantWeapon").Count, + "destroyed equipment behavior must stop contributing immediately"); + var destroyedWeaponState = target.WeaponStates.Single(); + Require(!destroyedWeaponState.Firing && !destroyedWeaponState.TriggerPending && + !destroyedWeaponState.Charging && !destroyedWeaponState.Charged && + destroyedWeaponState.BurstRemaining == 0 && destroyedWeaponState.LockTargetEntityIndex < 0, + "destroyed weapon state must deactivate atomically instead of publishing a ghost firing effect"); + RequireEqual(1, run.GameEvents.Count(value => value.Kind == "equipment.destroyed" && + value.TargetEntityIndex == target.EntityIndex && value.ItemKey == "damageable-weapon"), + "the durability crossing must publish exactly one generic equipment destruction fact"); + var surface = AetheriaRuntimeDaemonGameSurfaceBuilder.Build( + new AetheriaRuntimeDaemonFrameDocument { FrameId = 1, Run = run }, + new AetheriaRuntimeDaemonHealthDocument(), + AetheriaRuntimeDaemonCommandBoundaryDocument.Create("daemon")); + Require(Flatten(surface.Surface.Root).Any(node => node.Kind == "feedback.event" && + node.Props["eventKind"] == "equipment.destroyed" && + node.Props["itemKey"] == "damageable-weapon"), + "generic Eve clients must receive equipment destruction through provider feedback facts"); + + var cockpitTarget = Entity(2, 0, "neutral"); + cockpitTarget.HullItemKey = "cockpit-damage-hull"; + cockpitTarget.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit + { + X = 0, Y = 0, + Item = new AetheriaRuntimeLoadoutItemCommit + { ItemKey = "damageable-cockpit", Quality = 1, Durability = 1, Enabled = true } + }]; + var cockpitHull = HullCatalogItem("cockpit-damage-hull", 1, 1, 0); + var cockpit = CatalogItem("damageable-cockpit", new AetheriaRuntimeBehaviorPayload(0, "Cockpit", 0, [])); + cockpit.ShapeCells = [new AetheriaRuntimeShapeCell(0, 0)]; + var cockpitCatalog = new AetheriaRuntimeCatalogSnapshot([cockpitHull, cockpit], [], []); + var cockpitZone = new AetheriaRuntimeZoneSnapshotCommit + { + ZoneIndex = 0, Entities = [source, cockpitTarget], PhysicalPayloads = [new AetheriaRuntimePhysicalPayloadCommit + { + PayloadId = "cockpit-destruction", PayloadKind = "mine", WeaponItemKey = "test-cannon", + SourceEntityIndex = source.EntityIndex, PositionX = cockpitTarget.PositionX, PositionZ = cockpitTarget.PositionZ, + LifetimeSeconds = 30, BlastRadius = 200, PayloadMagnitude = 1, + TriggeredAtSeconds = 0, DetonationDelaySeconds = 0, Stationary = true, Active = true + }] + }; + var cockpitRun = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "cockpit-destruction-smoke", CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", Zones = [cockpitZone] + }; + + AetheriaRuntimeDaemonSimulation.Step(cockpitRun, new AetheriaRuntimeDaemonIntentState(), 0.1, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault, NewPhysics(), cockpitCatalog, 1, 0.1); + + Require(!cockpitTarget.IsActive && cockpitTarget.CauseOfDeath == "cockpit-destroyed", + "cockpit durability crossing must use the fossil cockpit death path before hull depletion"); + RequireNear(100, Stat(cockpitTarget, "hull"), 0.000001, + "cockpit destruction must not counterfeit scalar hull depletion"); + var chronology = cockpitRun.GameEvents.Where(value => + value.Kind == "equipment.destroyed" || value.Kind == "entity.destroyed") + .Select(value => value.Kind).ToArray(); + RequireEqual("equipment.destroyed,entity.destroyed", string.Join(",", chronology), + "equipment destruction feedback must precede the cause-specific entity destruction fact"); + } + private static void DestructionDropsLootExactlyOnce() { var source = Entity(0, -100, "player"); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs index 201809715..483ac4f82 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs @@ -544,7 +544,7 @@ namespace GameCult.Aetheria.State.Verse }) }; } - var tool = AetheriaRuntimeEquippedBehaviorQueries.Find(agent, catalog, "MiningTool").FirstOrDefault(); + var tool = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(agent, catalog, "MiningTool").FirstOrDefault(); var bodyKey = (task.TargetBodyKeys ?? Array.Empty()).FirstOrDefault() ?? ""; var body = (zone.Bodies ?? Array.Empty()) .FirstOrDefault(candidate => candidate != null && string.Equals(candidate.BodyKey, bodyKey, StringComparison.Ordinal)); @@ -592,7 +592,7 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeCatalogSnapshot? catalog, double simulationTimeSeconds) { - var scanner = AetheriaRuntimeEquippedBehaviorQueries.Find(agent, catalog, "ResourceScanner").FirstOrDefault(); + var scanner = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(agent, catalog, "ResourceScanner").FirstOrDefault(); if (scanner == null) { Fail(task, agent); return Array.Empty(); } var minimumDensity = scanner.EvaluateStat(2); var surveyed = new HashSet((run.CorporationSurveys ?? Array.Empty()) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index 63a3f0a7e..599f8ad14 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -594,9 +594,12 @@ namespace GameCult.Aetheria.State.Verse Reason = payload.DamageType, PositionX = payload.PositionX, PositionZ = payload.PositionZ }); - if (aliveBefore && !IsAlive(target)) + PublishEquipmentDestroyedEvents(run, zone, target, damage, + payload.SourceEntityIndex, payload.PayloadId, frameId); + if (aliveBefore && (damage.CockpitDestroyed || !IsAlive(target))) CommitDestruction(run, zone, target, payload.SourceEntityIndex, - payload.PayloadId, payload.WeaponItemKey, frameId, settings); + payload.PayloadId, payload.WeaponItemKey, frameId, settings, + damage.CockpitDestroyed ? "cockpit-destroyed" : "hull-destroyed"); } AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit { EventId = $"physical-payload:{payload.PayloadId}:detonated", Kind = "deployable.detonated", FrameId = frameId, ZoneIndex = zone.ZoneIndex, SourceEntityIndex = payload.SourceEntityIndex, SubjectKey = payload.PayloadId, ItemKey = payload.WeaponItemKey, Reason = payload.TriggerReason, ScalarValue = payload.PayloadMagnitude, PositionX = payload.PositionX, PositionZ = payload.PositionZ }); } @@ -1232,7 +1235,7 @@ namespace GameCult.Aetheria.State.Verse var equipmentIndices = weaponGroup >= 0 && weaponGroup < (entity.WeaponGroups ?? Array.Empty>()).Count ? entity.WeaponGroups[weaponGroup] ?? Array.Empty() : Array.Empty(); - return AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, AetheriaRuntimeBehaviorKinds.ConstantWeapon) + return AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, AetheriaRuntimeBehaviorKinds.ConstantWeapon) .Select(behavior => { var magazineSize = Math.Max(0, (int)Math.Round(ReadNumber(behavior.Payload, 13))); @@ -1264,7 +1267,7 @@ namespace GameCult.Aetheria.State.Verse var equipmentIndices = weaponGroup >= 0 && weaponGroup < (entity.WeaponGroups ?? Array.Empty>()).Count ? entity.WeaponGroups[weaponGroup] ?? Array.Empty() : Array.Empty(); - return AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, AetheriaRuntimeBehaviorKinds.DeployableWeapon) + return AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, AetheriaRuntimeBehaviorKinds.DeployableWeapon) .Where(behavior => equipmentIndices.Contains(behavior.EquipmentIndex)) .Select(behavior => new ResolvedDeployableWeapon( ResolveAuthoredWeapon(entity, behavior, settings), @@ -1384,8 +1387,37 @@ namespace GameCult.Aetheria.State.Verse AuxiliaryValue = damage.HullAppliedDamage, Reason = weapon.DamageType, PositionX = target.PositionX, PositionZ = target.PositionZ }); - if (aliveBefore && !IsAlive(target)) - CommitDestruction(run, zone, target, attacker.EntityIndex, shotId, weapon.ItemKey, frameId, settings); + PublishEquipmentDestroyedEvents(run, zone, target, damage, + attacker.EntityIndex, shotId, frameId); + if (aliveBefore && (damage.CockpitDestroyed || !IsAlive(target))) + CommitDestruction(run, zone, target, attacker.EntityIndex, shotId, weapon.ItemKey, + frameId, settings, damage.CockpitDestroyed ? "cockpit-destroyed" : "hull-destroyed"); + } + + private static void PublishEquipmentDestroyedEvents( + AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeZoneSnapshotCommit zone, + AetheriaRuntimeEntitySnapshotCommit target, + DamageResolution damage, + int sourceEntityIndex, + string subjectKey, + long frameId) + { + foreach (var equipmentIndex in damage.DestroyedEquipmentIndices) + { + var item = equipmentIndex >= 0 && equipmentIndex < (target.Equipment?.Count ?? 0) + ? target.Equipment[equipmentIndex]?.Item + : null; + AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit + { + EventId = $"{subjectKey}:equipment:{equipmentIndex}:destroyed", + Kind = "equipment.destroyed", FrameId = frameId, ZoneIndex = zone.ZoneIndex, + SourceEntityIndex = sourceEntityIndex, TargetEntityIndex = target.EntityIndex, + SubjectKey = subjectKey, ItemKey = item?.ItemKey ?? "", + ScalarValue = equipmentIndex, Reason = "durability-depleted", + PositionX = target.PositionX, PositionZ = target.PositionZ + }); + } } private static string NextShotId(AetheriaRuntimeZoneSnapshotCommit zone, @@ -1549,7 +1581,7 @@ namespace GameCult.Aetheria.State.Verse var requestedEquipment = requestedWeaponGroup >= 0 && requestedWeaponGroup < (entity.WeaponGroups ?? Array.Empty>()).Count ? entity.WeaponGroups[requestedWeaponGroup] ?? Array.Empty() : Array.Empty(); - return AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, AetheriaRuntimeBehaviorKinds.ChargedWeapon) + return AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, AetheriaRuntimeBehaviorKinds.ChargedWeapon) .Where(value => string.Equals(value.Payload.Kind, AetheriaRuntimeBehaviorKinds.ChargedWeapon, StringComparison.Ordinal)) .Select(value => new ResolvedChargedWeapon( ResolveAuthoredWeapon(entity, value, settings), value.Item, @@ -1566,7 +1598,7 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeCatalogSnapshot? catalog, AetheriaRuntimeDaemonSimulationSettings settings) { - var authored = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, AetheriaRuntimeBehaviorKinds.InstantWeapon) + var authored = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, AetheriaRuntimeBehaviorKinds.InstantWeapon) .Where(behavior => !string.Equals(behavior.Payload.Kind, AetheriaRuntimeBehaviorKinds.ChargedWeapon, StringComparison.Ordinal)) .Where(behavior => !string.Equals(behavior.Payload.Kind, AetheriaRuntimeBehaviorKinds.DeployableWeapon, StringComparison.Ordinal)) .Select(behavior => ResolveAuthoredWeapon(entity, behavior, settings)) @@ -1968,8 +2000,7 @@ namespace GameCult.Aetheria.State.Verse if (damage <= 0) return DamageResolution.None; - foreach (var shield in AetheriaRuntimeEquippedBehaviorQueries.Find(target, catalog, "Shield") - .Where(value => value.Item.Enabled)) + foreach (var shield in AetheriaRuntimeEquippedBehaviorQueries.FindOperational(target, catalog, "Shield")) { var efficiency = Math.Max(0.000001, shield.EvaluateStat(1)); var energyUsage = Math.Max(0, shield.EvaluateStat(2)); @@ -1998,6 +2029,8 @@ namespace GameCult.Aetheria.State.Verse var equipmentApplied = 0.0; var hullRequested = 0.0; var receipts = new List(cells.Count); + var destroyedEquipmentIndices = new HashSet(); + var cockpitDestroyed = false; foreach (var cell in cells) { var remaining = perCell; @@ -2012,10 +2045,20 @@ namespace GameCult.Aetheria.State.Verse if (equipment.Slot != null) { equipmentIndex = equipment.Index; + var durabilityBefore = equipment.Slot.Item.Durability; equipmentTaken = Math.Min(Math.Max(0, equipment.Slot.Item.Durability), remaining); equipment.Slot.Item.Durability = Math.Max(0, equipment.Slot.Item.Durability - equipmentTaken); equipmentApplied += equipmentTaken; remaining -= equipmentTaken; + if (durabilityBefore > 0.01 && equipment.Slot.Item.Durability <= 0.01) + { + destroyedEquipmentIndices.Add(equipmentIndex); + DeactivateDestroyedEquipment(target, equipmentIndex); + var catalogItem = catalog?.FindItem(equipment.Slot.Item.ItemKey ?? ""); + cockpitDestroyed |= (catalogItem?.BehaviorPayloads ?? Array.Empty()) + .Any(payload => payload != null && + AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(payload.Kind, "Cockpit")); + } } } var cellHull = remaining > 0 ? remaining : 0; @@ -2033,7 +2076,28 @@ namespace GameCult.Aetheria.State.Verse foreach (var receipt in receipts) receipt.HullAppliedDamage *= hullApplied / hullRequested; SetStat(target, Hull, hullBefore - hullApplied); - return new DamageResolution(0, armorApplied, equipmentApplied, hullApplied, 0, 0, receipts); + return new DamageResolution(0, armorApplied, equipmentApplied, hullApplied, 0, 0, receipts, + destroyedEquipmentIndices.OrderBy(value => value).ToArray(), cockpitDestroyed); + } + + private static void DeactivateDestroyedEquipment( + AetheriaRuntimeEntitySnapshotCommit entity, + int equipmentIndex) + { + foreach (var state in entity.WeaponStates ?? Array.Empty()) + { + if (!string.Equals(state.OwnerKind, AetheriaRuntimeBehaviorStateProjector.EquipmentOwnerKind, + StringComparison.Ordinal) || state.OwnerIndex != equipmentIndex) + continue; + state.Firing = false; + state.TriggerPending = false; + state.BurstRemaining = 0; + state.Charging = false; + state.Charged = false; + state.Charge = 0; + state.LockProgress = 0; + state.LockTargetEntityIndex = -1; + } } private static void EnsureArmorState(AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeCatalogSnapshot? catalog) @@ -2163,8 +2227,8 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeCatalogSnapshot? catalog) { - var shield = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "Shield") - .FirstOrDefault(value => value.Item.Enabled); + var shield = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, "Shield") + .FirstOrDefault(); if (shield == null) { SetStat(entity, Shield, 0); @@ -2181,12 +2245,14 @@ namespace GameCult.Aetheria.State.Verse private readonly struct DamageResolution { public static DamageResolution None { get; } = new DamageResolution(0, 0, 0, 0, 0, 0, - Array.Empty()); + Array.Empty(), Array.Empty(), false); public DamageResolution(double shieldAbsorbedDamage, double armorAppliedDamage, double equipmentAppliedDamage, double hullAppliedDamage, double shieldEnergyConsumed, double shieldHeatGenerated, - IReadOnlyList cells) + IReadOnlyList cells, + IReadOnlyList? destroyedEquipmentIndices = null, + bool cockpitDestroyed = false) { ShieldAbsorbedDamage = shieldAbsorbedDamage; ArmorAppliedDamage = armorAppliedDamage; @@ -2195,6 +2261,8 @@ namespace GameCult.Aetheria.State.Verse ShieldEnergyConsumed = shieldEnergyConsumed; ShieldHeatGenerated = shieldHeatGenerated; Cells = cells; + DestroyedEquipmentIndices = destroyedEquipmentIndices ?? Array.Empty(); + CockpitDestroyed = cockpitDestroyed; } public double ShieldAbsorbedDamage { get; } @@ -2204,6 +2272,8 @@ namespace GameCult.Aetheria.State.Verse public double ShieldEnergyConsumed { get; } public double ShieldHeatGenerated { get; } public IReadOnlyList Cells { get; } + public IReadOnlyList DestroyedEquipmentIndices { get; } + public bool CockpitDestroyed { get; } public double TotalAppliedDamage => ArmorAppliedDamage + EquipmentAppliedDamage + HullAppliedDamage; } @@ -2238,9 +2308,7 @@ namespace GameCult.Aetheria.State.Verse var equipmentStates = (entity.EquipmentStates ?? Array.Empty()) .Where(state => state != null) .ToDictionary(state => state.EquipmentIndex); - var sensitivitySquared = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "Sensor") - .Where(sensor => sensor.Item.Enabled && sensor.Item.Durability > 0 && - (!equipmentStates.TryGetValue(sensor.EquipmentIndex, out var state) || state.Online)) + var sensitivitySquared = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, "Sensor") .Select(sensor => Math.Max(0, sensor.EvaluateStat( 3, equipmentStates.TryGetValue(sensor.EquipmentIndex, out var state) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEnergySimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEnergySimulation.cs index 3393d4918..aa24e9530 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEnergySimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEnergySimulation.cs @@ -147,11 +147,7 @@ namespace GameCult.Aetheria.State.Verse private static IReadOnlyList Online( AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeCatalogSnapshot? catalog, string kind) => - AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, kind) - .Where(value => (entity.EquipmentStates ?? Array.Empty()) - .FirstOrDefault(state => state != null && state.EquipmentIndex == value.EquipmentIndex)?.Online ?? - (value.Item.Enabled && value.Item.Durability > 0.01)) - .ToArray(); + AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, kind); private static void AddCapacitorCharge(AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeCatalogSnapshot? catalog, AetheriaRuntimeEquippedBehavior capacitor, double delta) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs index e8cf8da16..2c2eb3cb0 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs @@ -90,5 +90,22 @@ namespace GameCult.Aetheria.State.Verse } return found; } + + public static IReadOnlyList FindOperational( + AetheriaRuntimeEntitySnapshotCommit? entity, + AetheriaRuntimeCatalogSnapshot? catalog, + string behaviorKind) + { + if (entity == null) + return Array.Empty(); + + var equipmentStates = (entity.EquipmentStates ?? Array.Empty()) + .Where(state => state != null) + .ToDictionary(state => state.EquipmentIndex); + return Find(entity, catalog, behaviorKind) + .Where(value => value.Item.Enabled && value.Item.Durability > 0.01 && + (!equipmentStates.TryGetValue(value.EquipmentIndex, out var state) || state.Online)) + .ToArray(); + } } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeFlightSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeFlightSimulation.cs index fd9d03128..26688e17f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeFlightSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeFlightSimulation.cs @@ -426,16 +426,8 @@ namespace GameCult.Aetheria.State.Verse private static IReadOnlyList Online( AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeCatalogSnapshot catalog, - string kind) - { - var states = (entity.EquipmentStates ?? Array.Empty()) - .Where(state => state != null) - .ToDictionary(state => state.EquipmentIndex); - return AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, kind) - .Where(value => value.Item.Enabled && value.Item.Durability > 0.01 && - (!states.TryGetValue(value.EquipmentIndex, out var state) || state.Online)) - .ToArray(); - } + string kind) => + AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, kind); private static double ThermalPerformance(AetheriaRuntimeEntitySnapshotCommit entity, int equipmentIndex) => (entity.EquipmentStates ?? Array.Empty()) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeMiningSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeMiningSimulation.cs index 48a42696e..87814868c 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeMiningSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeMiningSimulation.cs @@ -29,7 +29,7 @@ namespace GameCult.Aetheria.State.Verse if (!intent.Active || !TryEntityIndex(intent.ActorEntityKey, out var minerIndex)) continue; var miner = entities.FirstOrDefault(entity => entity.EntityIndex == minerIndex && entity.IsActive); - var tool = AetheriaRuntimeEquippedBehaviorQueries.Find(miner, catalog, "MiningTool") + var tool = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(miner, catalog, "MiningTool") .FirstOrDefault(candidate => candidate.EquipmentIndex == intent.EquipmentIndex && candidate.BehaviorIndex == intent.BehaviorIndex); var body = (zone.Bodies ?? Array.Empty()) .FirstOrDefault(candidate => candidate != null && string.Equals(candidate.BodyKey, intent.TargetBodyKey, StringComparison.Ordinal)); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSurveySimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSurveySimulation.cs index 70543a6ec..591e498a3 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSurveySimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSurveySimulation.cs @@ -16,7 +16,7 @@ namespace GameCult.Aetheria.State.Verse { if (!intent.Active || !int.TryParse((intent.ActorEntityKey ?? "").Split('.').LastOrDefault(), out var index)) continue; var entity = entities.FirstOrDefault(value => value.EntityIndex == index && value.IsActive); - var scanner = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "ResourceScanner") + var scanner = AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, "ResourceScanner") .FirstOrDefault(value => value.EquipmentIndex == intent.EquipmentIndex && value.BehaviorIndex == intent.BehaviorIndex); if (entity == null || scanner == null) continue; var body = (zone.Bodies ?? Array.Empty()).FirstOrDefault(value => value != null && string.Equals(value.BodyKey, intent.TargetBodyKey, StringComparison.Ordinal)); diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 733a70227..75ca69362 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -821,8 +821,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. impact position/direction; damage amount, orthogonal spread, 0.5-cell penetration, and typed damage type. - Outputs: one atomic `shield -> armor cell -> equipment -> scalar hull` - result, mutated canonical grids/equipment/hull state, and receipts recording - which layers were reached and how much each layer absorbed or received. + result, mutated canonical grids/equipment/hull state, receipts recording + which layers were reached, and one `equipment.destroyed` fact whenever an + installed item crosses the fossil durability threshold. - Derived state: aggregate armor and exact schematic armor/maximum-armor facts are Eve projections of canonical cell state. Scalar hull is the terminal remainder, not an armor surrogate. Damage type is typed/pass-through; no @@ -831,7 +832,10 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. Unity components, Eve lowerers, scalar-health helpers, and reconciliation loops cannot independently apply or repair armor, equipment, or hull damage. - Shared paths: direct and deployable impacts enter the same transaction after - their respective authoritative impact facts are resolved. + their respective authoritative impact facts are resolved. All behavior + consumers use the shared operational-equipment query, so disabled, + thermally-offline, and destroyed items cannot keep acting through a forgotten + subsystem-specific filter. - Cut line: scalar-hull-only and caller-specific damage paths are no longer owners. Hull/hardpoint topology initializes armor grids; only the daemon transaction mutates them thereafter. Penetration always advances by a @@ -839,10 +843,11 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. ### Daemon Destruction Transaction -- Owner: lethal daemon damage owns one destruction identity, active-world +- Owner: cause-specific daemon damage owns one destruction identity, active-world removal, reference cleanup, loot rolls, pickup state, and chronology. -- Inputs: canonical hull result, run seed, entity equipment/cargo, fossil loot - settings (`0.25` equipment probability, `25` launch speed, `30` second life). +- Inputs: canonical hull result or cockpit-destruction crossing, run seed, + entity equipment/cargo, and fossil loot settings (`0.25` equipment + probability, `25` launch speed, `30` second life). - Outputs: an inactive identity-stable tombstone, deterministic typed pickups, `entity.destroyed` and `pickup.dropped` events, and Eve world removal/effects. - Derived state: the retained entity row exists only for stable indexing and @@ -850,7 +855,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. - Forbidden writers: Unity destruction callbacks, Eve feedback renderers, and the reserved `DestroyEntity` command cannot erase entities or create loot. - Shared paths: direct shots and deployable splash invoke the same destruction - commit after the shared damage resolver crosses zero hull. + commit after the shared damage resolver crosses zero hull or destroys an + installed cockpit. Cockpit destruction preserves the remaining hull value and + publishes `equipment.destroyed` before `entity.destroyed(cockpit-destroyed)`. - Cut line: client-commanded removal and presentation-triggered loot are dead; EveUnity resolves `effect.feedback.entity.destroyed` only after the provider has published authoritative destruction chronology.