diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index bfe71ac2b..c99947c9d 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -17,6 +17,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks DeployableWeaponRunsThroughYmirAndDetonatesOnDaemon(); DeployableRangeExpiryDetonatesAfterYmirMovement(); CanonicalCatalogPublishesRecoveredMineLauncher(); + EnergyFundedShieldInterceptsDamageBeforeHull(); DaemonSimulationTreatsYmirHitAsPresentationOnly(); ProjectileContactCannotKill(); MissingPhysicsOwnerCannotAdvanceProjectiles(); @@ -375,6 +376,83 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "mine presentation must retain the fossil triggered pulse cadence"); } + private static void EnergyFundedShieldInterceptsDamageBeforeHull() + { + var source = Entity(0, -50, "player"); + var target = Entity(1, 0, "neutral"); + target.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit + { + Item = new AetheriaRuntimeLoadoutItemCommit + { ItemKey = "test-energy-shield", Quality = 1, Durability = 1, Enabled = true } + }]; + target.BehaviorStates = [new AetheriaRuntimeBehaviorStateCommit + { + OwnerKind = "fixture", OwnerIndex = 0, BehaviorIndex = 0, + BehaviorKind = "Capacitor", CapacitorCharge = 100, CapacitorCapacity = 100, + CapacitorEfficiency = 1 + }]; + var shield = new AetheriaRuntimeBehaviorPayload(0, "Shield", 0, + [ + new AetheriaRuntimeBehaviorField(1, PerformanceStat(2)), + new AetheriaRuntimeBehaviorField(2, PerformanceStat(3)) + ]); + var catalog = new AetheriaRuntimeCatalogSnapshot( + [CatalogItem("test-energy-shield", shield)], [], []); + var zone = new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [source, target] }; + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "energy-shield-smoke", CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", Zones = [zone] + }; + + void AddDetonatingPayload(string id, double damage) + { + zone.PhysicalPayloads = [new AetheriaRuntimePhysicalPayloadCommit + { + PayloadId = id, PayloadKind = "mine", WeaponItemKey = "test-blast", + SourceEntityIndex = source.EntityIndex, PositionX = target.PositionX, + LifetimeSeconds = 30, BlastRadius = 10, PayloadMagnitude = damage, + TriggeredAtSeconds = 0, DetonationDelaySeconds = 0, Stationary = true, Active = true + }]; + } + + AddDetonatingPayload("shielded-blast", 20); + AetheriaRuntimeDaemonSimulation.Step(run, new AetheriaRuntimeDaemonIntentState(), 0.1, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault, + new AetheriaYmirPhysicalPayloadPhysics(), new AetheriaYmirWorldPhysics(), catalog, 1, 0.1); + var capacitor = target.BehaviorStates.Single(value => value.BehaviorKind == "Capacitor"); + RequireNear(100, Stat(target, "hull"), 0.000001, + "funded shield must intercept damage before hull"); + RequireNear(40, capacitor.CapacitorCharge, 0.000001, + "shield must consume damage multiplied by authored energy usage"); + RequireNear(40.0 / 3.0, Stat(target, "shield"), 0.000001, + "legacy shield meter must be derived from remaining funded absorption, not own hit points"); + Require(run.GameEvents.Any(value => value.Kind == "shield.absorbed" && + Math.Abs(value.ScalarValue - 20) < 0.000001 && + Math.Abs(value.AuxiliaryValue - 10) < 0.000001), + "shield outcome must publish absorbed damage and authored heat contribution"); + 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"] == "shield.absorbed" && + node.Props["scalarValue"] == "20" && node.Props["auxiliaryValue"] == "10"), + "Eve feedback must expose exact shield absorption and heat facts"); + var shieldAsset = AetheriaRuntimeAssets.ProjectManifest(catalog).Assets.Single(value => + value.Ref.Metadata.TryGetValue("presentationRole", out var role) && role == "effect.impact.shield"); + RequireEqual("prefab.effect.impact.shield", shieldAsset.Ref.AssetKey, + "provider must advertise the authored shield visual by semantic impact role"); + + capacitor.CapacitorCharge = 0; + AddDetonatingPayload("unfunded-blast", 20); + AetheriaRuntimeDaemonSimulation.Step(run, new AetheriaRuntimeDaemonIntentState(), 0.1, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault, + new AetheriaYmirPhysicalPayloadPhysics(), new AetheriaYmirWorldPhysics(), catalog, 2, 0.2); + RequireNear(80, Stat(target, "hull"), 0.000001, + "unfunded shield must not manufacture absorption"); + } + private static void ChargedWeaponHoldRiskMalfunctionsDeterministically() { var source = Entity(0, 0, "player"); @@ -1102,8 +1180,9 @@ internal sealed class AetheriaDaemonYmirSmokeChecks Require(run.GameEvents.Count(value => value.Kind == "shot.committed" && value.ItemKey == "test-lock-cannon") >= 6, "two authored bursts must commit all six due rounds through the shot resolver"); Require(run.ShotReceipts.Count(value => value.WeaponItemKey == "test-lock-cannon") >= 6 && - run.ShotReceipts.All(value => value.Hit && value.AppliedDamage == value.NominalDamage), - "zero-spread authored rounds must commit immutable certain-hit receipts before presentation travel"); + run.ShotReceipts.All(value => value.Hit && value.HullAppliedDamage >= 0 && + value.HullAppliedDamage <= value.NominalDamage && value.ShieldAbsorbedDamage == 0), + "zero-spread authored rounds must commit exact certain-hit damage receipts before presentation travel"); Require(run.ShotReceipts.Select(value => value.ShotId).Distinct(StringComparer.Ordinal).Count() == run.ShotReceipts.Count, "every burst round must own a stable independent shot identity"); diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 2b78739b0..ce43f148b 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -16595,7 +16595,7 @@ static void RequireUnityDoesNotCallSharedSimulationTicks(string root) { "public static class AetheriaRuntimeDaemonSimulation", "AetheriaRuntimeDaemonSimulationSettings settings", - "StepCombat(run, zone, entities, intents, deltaSeconds, settings, physicalPayloadPhysics, catalog, frameId)", + "StepCombat(run, zone, entities, intents, deltaSeconds, settings, physicalPayloadPhysics, catalog,", "AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, AetheriaRuntimeBehaviorKinds.InstantWeapon)", "EnsureWeaponState(", "CommitWeaponRound(attacker, weapon)", @@ -16696,6 +16696,18 @@ static void RequireUnityDoesNotCallSharedSimulationTicks(string root) string.Join(", ", survivingPhysicalPayloadDamageSymbols)); } + var shotReceiptDocument = File.ReadAllText(snapshotDocumentsPath); + if (daemonSimulation.Contains("var shield = GetStat(target, Shield)", StringComparison.Ordinal) || + daemonSimulation.Contains("SetStat(target, Shield, shield -", StringComparison.Ordinal) || + !daemonSimulation.Contains("damage * energyUsage", StringComparison.Ordinal) || + !daemonSimulation.Contains("damage / efficiency", StringComparison.Ordinal) || + !shotReceiptDocument.Contains("ShieldAbsorbedDamage", StringComparison.Ordinal) || + !shotReceiptDocument.Contains("ShieldEnergyConsumed", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Shield authority must be the equipped energy-funded behavior transaction, not a scalar shield hitpoint pool."); + } + if (daemonSimulation.Contains("AetheriaRuntimeRtsSimulation", StringComparison.Ordinal) || daemonSimulation.Contains("daemon-rts", StringComparison.Ordinal) || daemonSimulation.Contains("rts-commander", StringComparison.Ordinal) || diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs index 1c046794f..70d315523 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs @@ -27,6 +27,7 @@ namespace GameCult.Aetheria.State.Verse Add(entries, MapPrefab("prefab.entity.station", "Station", "Prefabs/Stations/AsteroidOutpost", "station")); Add(entries, MapPrefab("prefab.entity.orbital", "Orbital", "Prefabs/Stations/Zenith", "orbital")); Add(entries, MapPrefab("prefab.effect.shot.bolt", "Bolt", "Prefabs/Lightning", "effect.shot.bolt")); + Add(entries, MapPrefab("prefab.effect.impact.shield", "Shield impact", "Prefabs/Shield", "effect.impact.shield")); Add(entries, MapProjectPrefab("prefab.entity.pickup", "Pickup", "Assets/Prefabs/RPG/Pickups/Tetrahedron.prefab")); Add(entries, MinePrefab()); foreach (var inventoryAsset in InventoryUiAssets()) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs index a7dc3fa38..ae7a06493 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs @@ -293,6 +293,7 @@ namespace GameCult.Aetheria.State.Verse ("targetEntityIndex", value.TargetEntityIndex.ToString(CultureInfo.InvariantCulture)), ("pickupIndex", value.PickupIndex.ToString(CultureInfo.InvariantCulture)), ("itemKey", value.ItemKey), ("scalarValue", FormatNumber(value.ScalarValue)), + ("auxiliaryValue", FormatNumber(value.AuxiliaryValue)), ("subjectKey", value.SubjectKey), ("reason", value.Reason), ("position", string.Join(",", new[] { FormatNumber(value.PositionX), FormatNumber(value.PositionZ) })), ("currentFrameId", frameId.ToString(CultureInfo.InvariantCulture)) @@ -328,6 +329,10 @@ namespace GameCult.Aetheria.State.Verse ("hit", value.Hit ? "true" : "false"), ("nominalDamage", FormatNumber(value.NominalDamage)), ("appliedDamage", FormatNumber(value.AppliedDamage)), + ("shieldAbsorbedDamage", FormatNumber(value.ShieldAbsorbedDamage)), + ("hullAppliedDamage", FormatNumber(value.HullAppliedDamage)), + ("shieldEnergyConsumed", FormatNumber(value.ShieldEnergyConsumed)), + ("shieldHeatGenerated", FormatNumber(value.ShieldHeatGenerated)), ("origin", string.Join(",", FormatNumber(value.OriginX), FormatNumber(value.OriginZ))), ("endpoint", string.Join(",", FormatNumber(value.EndpointX), FormatNumber(value.EndpointZ))), ("presentationDuration", FormatNumber(value.PresentationDurationSeconds)), diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index 828a32e20..79cf4059a 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -239,6 +239,8 @@ namespace GameCult.Aetheria.State.Verse double simulationTimeSeconds) { var byIndex = entities.ToDictionary(entity => entity.EntityIndex); + foreach (var entity in entities) + RefreshShieldProjection(entity, catalog); foreach (var attacker in entities) { var weaponGroup = ResolveFireGroup(run, zone, attacker, intents); @@ -327,7 +329,7 @@ namespace GameCult.Aetheria.State.Verse weapon.State.BurstRemaining--; weapon.State.BurstTimer -= weapon.State.BurstInterval; var shotId = NextShotId(zone, attacker, weapon); - CommitShotResolution(run, zone, attacker, target, weapon, shotId, frameId); + CommitShotResolution(run, zone, attacker, target, weapon, shotId, frameId, catalog); AppendShotCommittedEvent(run, zone, attacker, target, weapon, shotId, frameId); weapon.State.Firing = true; AetheriaRuntimeThermalSimulation.AddHeat(attacker, weapon.Heat); @@ -358,7 +360,7 @@ namespace GameCult.Aetheria.State.Verse } } } - ResolveDeployableDetonations(run, zone, entities, frameId, simulationTimeSeconds); + ResolveDeployableDetonations(run, zone, entities, frameId, simulationTimeSeconds, catalog); foreach (var entity in entities) { @@ -437,7 +439,8 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeZoneSnapshotCommit zone, IReadOnlyList entities, long frameId, - double simulationTimeSeconds) + double simulationTimeSeconds, + AetheriaRuntimeCatalogSnapshot? catalog) { var survivors = new List(); foreach (var payload in zone.PhysicalPayloads ?? Array.Empty()) @@ -455,7 +458,28 @@ namespace GameCult.Aetheria.State.Verse var dx = target.PositionX - payload.PositionX; var dz = target.PositionZ - payload.PositionZ; if (dx * dx + dz * dz > payload.BlastRadius * payload.BlastRadius) continue; - Damage(target, payload.PayloadMagnitude); + var damage = ResolveDamage(target, payload.PayloadMagnitude, catalog); + if (damage.ShieldAbsorbedDamage > 0) + AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit + { + EventId = $"physical-payload:{payload.PayloadId}:shield:{target.EntityIndex}", + Kind = "shield.absorbed", FrameId = frameId, ZoneIndex = zone.ZoneIndex, + SourceEntityIndex = payload.SourceEntityIndex, TargetEntityIndex = target.EntityIndex, + SubjectKey = payload.PayloadId, ItemKey = payload.WeaponItemKey, + ScalarValue = damage.ShieldAbsorbedDamage, + AuxiliaryValue = damage.ShieldHeatGenerated, + PositionX = payload.PositionX, PositionZ = payload.PositionZ + }); + if (damage.HullAppliedDamage > 0) + AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit + { + EventId = $"physical-payload:{payload.PayloadId}:damage:{target.EntityIndex}", + Kind = "entity.damaged", FrameId = frameId, ZoneIndex = zone.ZoneIndex, + SourceEntityIndex = payload.SourceEntityIndex, TargetEntityIndex = target.EntityIndex, + SubjectKey = payload.PayloadId, ItemKey = payload.WeaponItemKey, + ScalarValue = damage.HullAppliedDamage, + PositionX = payload.PositionX, PositionZ = payload.PositionZ + }); } 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 }); } @@ -584,7 +608,7 @@ namespace GameCult.Aetheria.State.Verse state.BurstRemaining--; state.BurstTimer -= state.BurstInterval; var shotId = NextShotId(zone, attacker, shot); - CommitShotResolution(run, zone, attacker, solutionTarget, shot, shotId, frameId); + CommitShotResolution(run, zone, attacker, solutionTarget, shot, shotId, frameId, catalog); AppendShotCommittedEvent(run, zone, attacker, solutionTarget, shot, shotId, frameId); state.Firing = true; AetheriaRuntimeThermalSimulation.AddHeat(attacker, shot.Heat); @@ -738,7 +762,7 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeThermalSimulation.AddHeat(attacker, weapon.Heat * deltaSeconds); var shot = weapon.ResolutionShot(deltaSeconds); var shotId = NextShotId(zone, attacker, shot); - CommitShotResolution(run, zone, attacker, selectedTarget!, shot, shotId, frameId); + CommitShotResolution(run, zone, attacker, selectedTarget!, shot, shotId, frameId, catalog); AppendShotCommittedEvent(run, zone, attacker, selectedTarget!, shot, shotId, frameId); } } @@ -1061,7 +1085,8 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeEntitySnapshotCommit target, ResolvedWeapon weapon, string shotId, - long frameId) + long frameId, + AetheriaRuntimeCatalogSnapshot? catalog) { if ((run.ShotReceipts ?? Array.Empty()) .Any(value => value != null && string.Equals(value.ShotId, shotId, StringComparison.Ordinal))) @@ -1098,10 +1123,8 @@ namespace GameCult.Aetheria.State.Verse var endpointX = target.PositionX + Math.Cos(angle) * impactRadius; var endpointZ = target.PositionZ + Math.Sin(angle) * impactRadius; var presentationKind = ResolveShotPresentationKind(weapon.State.BehaviorKind); - var appliedDamage = hit ? weapon.Damage : 0; - var shieldBefore = Math.Max(0, GetStat(target, Shield)); var aliveBefore = IsAlive(target); - if (hit) Damage(target, appliedDamage); + var damage = hit ? ResolveDamage(target, weapon.Damage, catalog) : DamageResolution.None; AetheriaRuntimeShotReceipts.Append(run, new AetheriaRuntimeShotReceiptCommit { @@ -1111,8 +1134,8 @@ namespace GameCult.Aetheria.State.Verse WeaponBehaviorIndex = weapon.State.BehaviorIndex, ContactInformation = information, LockQuality = lockQuality, RangeFactor = rangeFactor, MotionFactor = motionFactor, DispersionFactor = dispersionFactor, HitProbability = probability, HitRoll = roll, - Hit = hit, NominalDamage = weapon.Damage, AppliedDamage = appliedDamage, - Outcome = hit ? "hit" : "miss", + Hit = hit, NominalDamage = weapon.Damage, AppliedDamage = damage.HullAppliedDamage, + Outcome = !hit ? "miss" : damage.ShieldAbsorbedDamage > 0 ? "shielded" : "hit", OriginX = attacker.PositionX, OriginZ = attacker.PositionZ, EndpointX = endpointX, EndpointZ = endpointZ, PresentationDurationSeconds = presentationKind == "stream" @@ -1120,8 +1143,12 @@ namespace GameCult.Aetheria.State.Verse : distance / Math.Max(1, weapon.ProjectileSpeed), PresentationKind = presentationKind, ImpactAngleRoll = angleRoll, ImpactRadiusRoll = radiusRoll, - ImpactKind = !hit ? "none" : shieldBefore > 0 ? "shield" : "hull", - PresentationIntensity = Math.Max(0.1, weapon.Damage) + ImpactKind = !hit ? "none" : damage.ShieldAbsorbedDamage > 0 ? "shield" : "hull", + PresentationIntensity = Math.Max(0.1, weapon.Damage), + ShieldAbsorbedDamage = damage.ShieldAbsorbedDamage, + HullAppliedDamage = damage.HullAppliedDamage, + ShieldEnergyConsumed = damage.ShieldEnergyConsumed, + ShieldHeatGenerated = damage.ShieldHeatGenerated }); AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit { @@ -1131,13 +1158,22 @@ namespace GameCult.Aetheria.State.Verse ItemKey = weapon.ItemKey, ScalarValue = probability, PositionX = target.PositionX, PositionZ = target.PositionZ }); - if (hit) + if (damage.ShieldAbsorbedDamage > 0) + AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit + { + EventId = $"shot:{shotId}:shield", Kind = "shield.absorbed", FrameId = frameId, + ZoneIndex = zone.ZoneIndex, SourceEntityIndex = attacker.EntityIndex, + TargetEntityIndex = target.EntityIndex, SubjectKey = shotId, + ItemKey = weapon.ItemKey, ScalarValue = damage.ShieldAbsorbedDamage, + PositionX = endpointX, PositionZ = endpointZ + }); + if (damage.HullAppliedDamage > 0) AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit { EventId = $"shot:{shotId}:damage", Kind = "entity.damaged", FrameId = frameId, ZoneIndex = zone.ZoneIndex, SourceEntityIndex = attacker.EntityIndex, TargetEntityIndex = target.EntityIndex, SubjectKey = shotId, - ItemKey = weapon.ItemKey, ScalarValue = appliedDamage, + ItemKey = weapon.ItemKey, ScalarValue = damage.HullAppliedDamage, PositionX = target.PositionX, PositionZ = target.PositionZ }); if (aliveBefore && !IsAlive(target)) @@ -1591,18 +1627,75 @@ namespace GameCult.Aetheria.State.Verse } } - private static void Damage(AetheriaRuntimeEntitySnapshotCommit target, double damage) + private static DamageResolution ResolveDamage( + AetheriaRuntimeEntitySnapshotCommit target, + double damage, + AetheriaRuntimeCatalogSnapshot? catalog) { - var shield = GetStat(target, Shield); - var shieldDamage = Math.Min(shield, damage); - if (shieldDamage > 0) + damage = Math.Max(0, damage); + if (damage <= 0) + return DamageResolution.None; + + foreach (var shield in AetheriaRuntimeEquippedBehaviorQueries.Find(target, catalog, "Shield") + .Where(value => value.Item.Enabled)) { - SetStat(target, Shield, shield - shieldDamage); - damage -= shieldDamage; + var efficiency = Math.Max(0.000001, shield.EvaluateStat(1)); + var energyUsage = Math.Max(0, shield.EvaluateStat(2)); + var energyDemand = damage * energyUsage; + shield.State.ShieldEfficiency = efficiency; + shield.State.ShieldEnergyUsage = energyUsage; + if (!CanSupplyEnergy(target, energyDemand)) + continue; + + CommitEnergy(target, energyDemand); + var heat = damage / efficiency; + AetheriaRuntimeThermalSimulation.AddHeat(target, heat); + RefreshShieldProjection(target, catalog); + return new DamageResolution(damage, 0, energyDemand, heat); } - if (damage > 0) - SetStat(target, Hull, Math.Max(0, GetStat(target, Hull) - damage)); + var hullBefore = Math.Max(0, GetStat(target, Hull)); + var hullApplied = Math.Min(hullBefore, damage); + SetStat(target, Hull, hullBefore - hullApplied); + return new DamageResolution(0, hullApplied, 0, 0); + } + + private static void RefreshShieldProjection( + AetheriaRuntimeEntitySnapshotCommit entity, + AetheriaRuntimeCatalogSnapshot? catalog) + { + var shield = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "Shield") + .FirstOrDefault(value => value.Item.Enabled); + if (shield == null) + { + SetStat(entity, Shield, 0); + return; + } + + var energyUsage = Math.Max(0, shield.EvaluateStat(2)); + var availableEnergy = (entity.BehaviorStates ?? Array.Empty()) + .Where(value => value != null && value.BehaviorKind == "Capacitor") + .Sum(value => Math.Max(0, value.CapacitorCharge)); + SetStat(entity, Shield, energyUsage <= 0 ? 1 : availableEnergy / energyUsage); + } + + private readonly struct DamageResolution + { + public static DamageResolution None { get; } = new DamageResolution(0, 0, 0, 0); + + public DamageResolution(double shieldAbsorbedDamage, double hullAppliedDamage, + double shieldEnergyConsumed, double shieldHeatGenerated) + { + ShieldAbsorbedDamage = shieldAbsorbedDamage; + HullAppliedDamage = hullAppliedDamage; + ShieldEnergyConsumed = shieldEnergyConsumed; + ShieldHeatGenerated = shieldHeatGenerated; + } + + public double ShieldAbsorbedDamage { get; } + public double HullAppliedDamage { get; } + public double ShieldEnergyConsumed { get; } + public double ShieldHeatGenerated { get; } } private static bool IsAlive(AetheriaRuntimeEntitySnapshotCommit entity) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs index 2ab30ae02..50098f7a7 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs @@ -451,6 +451,7 @@ namespace GameCult.Aetheria.State.Verse [Key(10)] public double PositionX { get; set; } [Key(11)] public double PositionZ { get; set; } [Key(12)] public string Reason { get; set; } = ""; + [Key(13)] public double AuxiliaryValue { get; set; } } [MessagePackObject] @@ -485,6 +486,10 @@ namespace GameCult.Aetheria.State.Verse [Key(26)] public double ImpactRadiusRoll { get; set; } [Key(27)] public string ImpactKind { get; set; } = "none"; [Key(28)] public double PresentationIntensity { get; set; } = 1; + [Key(29)] public double ShieldAbsorbedDamage { get; set; } + [Key(30)] public double HullAppliedDamage { get; set; } + [Key(31)] public double ShieldEnergyConsumed { get; set; } + [Key(32)] public double ShieldHeatGenerated { get; set; } } [MessagePackObject] diff --git a/docs/deterministic-combat-resolution.md b/docs/deterministic-combat-resolution.md index 29b90dabe..f04d1d6eb 100644 --- a/docs/deterministic-combat-resolution.md +++ b/docs/deterministic-combat-resolution.md @@ -168,6 +168,14 @@ causes. They enter the same detonation transaction as proximity triggers and retain their reason in the event chronology. Ymir movement happens before the range check, matching the original simulation ordering. +Shield interception follows the original behavior contract rather than a +synthetic shield hitpoint pool. An enabled equipped Shield behavior may absorb +the full incoming damage only when canonical capacitors can fund +`damage * EnergyUsage`; absorption consumes that energy and adds +`damage / Efficiency` heat. Otherwise damage reaches the hull transaction. +Receipts publish absorbed damage, hull-applied damage, energy consumed, heat +generated, and the semantic `shield` or `hull` impact kind. + ## Eve Presentation Eve receives: diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 84207cba4..6ae863b3a 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -22,7 +22,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Collision | Unity physics and entity handlers | Ymir | collision/result facts | visual interpolation only | Ymir.Core world stepping wired for entity bodies, radial fields and contacts; missing-owner negative proof passes | publish authoritative collision events and prove Unity cannot write transforms back | | Targeting/contacts | sensors + `ActionGameManager` | daemon | contact/target semantics | target HUD and indicators | simplified owner wired/projected; daemon weapon lock now acquires and decays from facing, elapsed time, and observer-local contact confidence instead of granting an immediate perfect lock | target-switch reset, angular decay, visibility/nearest/explicit cases, and runtime lock feedback | | Projectile flight | weapon/projectile classes | Eve presentation for ordinary tracers; Ymir for persistent physical payloads | receipt trajectory/effect facts or persistent payload state | native projectile visual | ordinary instant, charged, and constant execution creates no projectile body; each weapon state owns a stable shot sequence and receipts carry origin, endpoint, nominal duration, and effect identity for Eve presentation; `SpawnProjectile` and its alternate writer are deleted; Ymir projectile contacts are feedback-only for explicitly persisted payload rows and cannot write damage; Ymir.Core remains embedded for world integration, radial fields, circle contacts, pickups, and genuinely persistent/interceptable payloads | split/rename the remaining physical-payload interface and remove ordinary projectile terminology from runtime contracts | -| Shield/hull damage | energy-funded shield, armor cells, equipment and hull | daemon | entity status + damage events | meters, impacts, damage VFX | bounded immutable shot receipts record stable identity, observer information, lock, range, motion, dispersion, probability, roll, outcome, and applied damage; daemon applies current scalar shield-then-hull damage at shot commitment; fake or later Ymir projectile contacts cannot emit damage/destruction | cognition/signature factors, named independent entropy dimensions, miss/impact distribution, typed armor/hull/equipment grids, penetration and damage types | +| Shield/hull damage | energy-funded shield, armor cells, equipment and hull | daemon | entity status + damage events | meters, impacts, damage VFX | equipped Shield behavior now owns the fossil all-or-nothing energy gate: funded hits consume `damage * EnergyUsage`, add `damage / Efficiency` heat, and publish shield absorption without hull loss; unfunded hits bypass the shield; shot receipts expose exact shield/hull/energy/heat quantities and `effect.impact.shield` resolves through the provider asset manifest; fake or later Ymir contacts cannot decide damage | typed armor/hull/equipment grids, penetration, spread, damage types, and generic shield-effect lifecycle 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 plus Ymir geometry/kinematics | action capability, weapon state, shot/damage receipts | effects/audio/HUD | instant and constant resource/timing lifecycles are daemon-owned; charged weapons accept one semantic request, spool without requiring a solution, hold at full charge, commit automatically when a solution appears, and perform deterministic once-per-second malfunction hazard checks after the authored safe hold interval with increasing persisted risk; generic Eve `weapon.state` exposes charge hold/risk and feedback exposes readiness, commit, refusal, and malfunction chronology | replace projectile-contact damage with `deterministic-combat-resolution.md`, then guided persistent payloads, visibility/wear, penetration, impact distribution, and Unity effect reconciliation | | 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 |