Persist lock weapon state in typed snapshots

This commit is contained in:
Meta Vens 2026-06-14 15:47:15 +01:00
commit 6a6a19d08f
11 changed files with 89 additions and 14 deletions

Binary file not shown.

View file

@ -238,6 +238,19 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s
EquipmentIndices = [0]
}
],
WeaponStates =
[
new AetheriaWeaponStateSnapshot
{
OwnerKind = "equipment",
OwnerIndex = 0,
BehaviorIndex = 1,
BehaviorKind = "LockWeapon",
Ammo = 1,
LockProgress = 0.65,
LockTargetEntityKey = entityKey.ToString()
}
],
StatGrids =
[
new AetheriaEntityStatGrid
@ -495,6 +508,10 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether
entitySnapshot.DockingBayAssignments.Length != 1 ||
entitySnapshot.DockingBayAssignments[0] != -1 ||
entitySnapshot.WeaponGroups.Length != 1 ||
entitySnapshot.WeaponStates.Length != 1 ||
entitySnapshot.WeaponStates[0].BehaviorKind != "LockWeapon" ||
entitySnapshot.WeaponStates[0].LockProgress != 0.65 ||
entitySnapshot.WeaponStates[0].LockTargetEntityKey != entityKey.ToString() ||
entitySnapshot.StatGrids.Length != 1 ||
entitySnapshot.StatGrids[0].Values.Length != 4)
{

View file

@ -425,6 +425,16 @@ try
Reloading = true,
ReloadProgress = 0.4,
AmmoIntervalProgress = 0.6
},
new AetheriaRuntimeWeaponStateCommit
{
OwnerKind = "equipment",
OwnerIndex = 2,
BehaviorIndex = 1,
BehaviorKind = "LockWeapon",
Ammo = 1,
LockProgress = 0.65,
LockTargetEntityIndex = 0
}
},
BehaviorStates = new[]
@ -574,7 +584,7 @@ try
entity.BehaviorProgress[0].Progress == 0.5 &&
entity.BehaviorProgress[1].OwnerKind == "active_consumable" &&
entity.BehaviorProgress[1].Progress == 0.75 &&
entity.WeaponStates.Length == 3 &&
entity.WeaponStates.Length == 4 &&
entity.WeaponStates[0].BehaviorKind == "InstantWeapon" &&
entity.WeaponStates[0].Firing &&
entity.WeaponStates[0].Ammo == 2 &&
@ -588,6 +598,9 @@ try
entity.WeaponStates[2].BehaviorKind == "ConstantWeapon" &&
entity.WeaponStates[2].Reloading &&
entity.WeaponStates[2].AmmoIntervalProgress == 0.6 &&
entity.WeaponStates[3].BehaviorKind == "LockWeapon" &&
entity.WeaponStates[3].LockProgress == 0.65 &&
entity.WeaponStates[3].LockTargetEntityKey == "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1" &&
entity.BehaviorStates.Length == 4 &&
entity.BehaviorStates[0].BehaviorKind == "Sensor" &&
entity.BehaviorStates[0].Pinging &&
@ -651,8 +664,10 @@ try
packageEntities[0].DockingBayAssignments[0] != -1 ||
packageEntities[0].ActiveConsumables[0].ItemKey != "aetheria.item_definition:legacy:smoke:consumable" ||
packageEntities[0].BehaviorProgress.Count != 2 ||
packageEntities[0].WeaponStates.Count != 3 ||
packageEntities[0].WeaponStates.Count != 4 ||
packageEntities[0].WeaponStates[2].AmmoIntervalProgress != 0.6 ||
packageEntities[0].WeaponStates[3].LockProgress != 0.65 ||
packageEntities[0].WeaponStates[3].LockTargetEntityKey != "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1" ||
packageEntities[0].BehaviorStates.Count != 4 ||
packageEntities[0].BehaviorStates[3].CapacitorCharge != 7.5 ||
packageEntities[0].StatGrids.Count != 2 ||

View file

@ -454,7 +454,7 @@ public static class AetheriaRuntimeCommitLogApplier
StatGrids = ToEntityStatGrids(entity.StatGrids),
ActiveConsumables = ToActiveConsumables(entity.ActiveConsumables),
BehaviorProgress = ToBehaviorProgress(entity.BehaviorProgress),
WeaponStates = ToWeaponStates(entity.WeaponStates),
WeaponStates = ToWeaponStates(entity.WeaponStates, runId, zoneIndex),
BehaviorStates = ToBehaviorStates(entity.BehaviorStates),
CargoContents = ToCargoBays(entity.CargoContents),
DockingBayContents = ToCargoBays(entity.DockingBayContents),
@ -492,7 +492,9 @@ public static class AetheriaRuntimeCommitLogApplier
}
private static AetheriaWeaponStateSnapshot[] ToWeaponStates(
IReadOnlyList<AetheriaRuntimeWeaponStateCommit>? states)
IReadOnlyList<AetheriaRuntimeWeaponStateCommit>? states,
string runId,
int zoneIndex)
{
return (states ?? Array.Empty<AetheriaRuntimeWeaponStateCommit>())
.Select(state => new AetheriaWeaponStateSnapshot
@ -513,7 +515,11 @@ public static class AetheriaRuntimeCommitLogApplier
Charge = state.Charge,
Reloading = state.Reloading,
ReloadProgress = state.ReloadProgress,
AmmoIntervalProgress = state.AmmoIntervalProgress
AmmoIntervalProgress = state.AmmoIntervalProgress,
LockProgress = state.LockProgress,
LockTargetEntityKey = state.LockTargetEntityIndex >= 0
? EntityKey(runId, zoneIndex, state.LockTargetEntityIndex).ToString()
: ""
})
.ToArray();
}

View file

@ -636,6 +636,12 @@ public sealed class AetheriaWeaponStateSnapshot
[Key(16)]
public double AmmoIntervalProgress { get; set; }
[Key(17)]
public double LockProgress { get; set; }
[Key(18)]
public string LockTargetEntityKey { get; set; } = "";
}
[MessagePackObject]

View file

@ -795,7 +795,7 @@ public class ActionGameManager : MonoBehaviour
StatGrids = ProjectEntityStatGrids(entity),
ActiveConsumables = ProjectActiveConsumables(entity),
BehaviorProgress = ProjectBehaviorProgress(entity),
WeaponStates = ProjectWeaponStates(entity),
WeaponStates = ProjectWeaponStates(zone, entity),
BehaviorStates = ProjectBehaviorStates(entity)
};
}
@ -896,21 +896,22 @@ public class ActionGameManager : MonoBehaviour
}
}
private static AetheriaRuntimeWeaponStateCommit[] ProjectWeaponStates(Entity entity)
private static AetheriaRuntimeWeaponStateCommit[] ProjectWeaponStates(Zone zone, Entity entity)
{
var states = new List<AetheriaRuntimeWeaponStateCommit>();
for (var ownerIndex = 0; ownerIndex < entity.Equipment.Count; ownerIndex++)
states.AddRange(ProjectWeaponStates("equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors));
states.AddRange(ProjectWeaponStates(zone, "equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors));
var activeConsumables = entity.ActiveConsumables;
for (var ownerIndex = 0; ownerIndex < activeConsumables.Count; ownerIndex++)
states.AddRange(ProjectWeaponStates("active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors));
states.AddRange(ProjectWeaponStates(zone, "active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors));
return states.ToArray();
}
private static IEnumerable<AetheriaRuntimeWeaponStateCommit> ProjectWeaponStates(
Zone zone,
string ownerKind,
int ownerIndex,
IReadOnlyList<Behavior> behaviors)
@ -956,6 +957,12 @@ public class ActionGameManager : MonoBehaviour
state.AmmoIntervalProgress = constant.AmmoIntervalProgress;
}
if (weapon is LockWeapon lockWeapon)
{
state.LockProgress = lockWeapon.LockProgress;
state.LockTargetEntityIndex = lockWeapon.LockTarget == null ? -1 : zone.Entities.IndexOf(lockWeapon.LockTarget);
}
yield return state;
}
}

View file

@ -58,6 +58,10 @@ public class LockWeapon : InstantWeapon
get => saturate(_lock);
}
public float LockProgress => saturate(_lock);
public Entity LockTarget => _target;
public LockWeapon(LockWeaponData data, EquippedItem item) : base(data, item)
{
_data = data;

View file

@ -1019,7 +1019,9 @@ namespace GameCult.Aetheria.State.Unity
double charge,
bool reloading,
double reloadProgress,
double ammoIntervalProgress)
double ammoIntervalProgress,
double lockProgress,
string lockTargetEntityKey)
{
OwnerKind = ownerKind;
OwnerIndex = ownerIndex;
@ -1038,6 +1040,8 @@ namespace GameCult.Aetheria.State.Unity
Reloading = reloading;
ReloadProgress = reloadProgress;
AmmoIntervalProgress = ammoIntervalProgress;
LockProgress = lockProgress;
LockTargetEntityKey = lockTargetEntityKey;
}
public string OwnerKind { get; }
@ -1057,6 +1061,8 @@ namespace GameCult.Aetheria.State.Unity
public bool Reloading { get; }
public double ReloadProgress { get; }
public double AmmoIntervalProgress { get; }
public double LockProgress { get; }
public string LockTargetEntityKey { get; }
}
public sealed class AetheriaRuntimeBehaviorStateSnapshot

View file

@ -821,7 +821,9 @@ namespace GameCult.Aetheria.State.Unity
var reloading = ReadFieldBool(ref reader, weaponFields, 14);
var reloadProgress = ReadFieldDouble(ref reader, weaponFields, 15);
var ammoIntervalProgress = ReadFieldDouble(ref reader, weaponFields, 16);
SkipRemaining(ref reader, weaponFields, 17);
var lockProgress = ReadFieldDouble(ref reader, weaponFields, 17);
var lockTargetEntityKey = ReadFieldString(ref reader, weaponFields, 18);
SkipRemaining(ref reader, weaponFields, 19);
weaponStates[weapon] = new AetheriaRuntimeWeaponStateSnapshot(
ownerKind,
ownerIndex,
@ -839,7 +841,9 @@ namespace GameCult.Aetheria.State.Unity
charge,
reloading,
reloadProgress,
ammoIntervalProgress);
ammoIntervalProgress,
lockProgress,
lockTargetEntityKey);
}
return weaponStates;

View file

@ -685,6 +685,12 @@ namespace GameCult.Aetheria.State.Unity
[Key(16)]
public double AmmoIntervalProgress { get; set; }
[Key(17)]
public double LockProgress { get; set; }
[Key(18)]
public int LockTargetEntityIndex { get; set; } = -1;
}
[MessagePackObject]

View file

@ -164,8 +164,9 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
`IProgressBehavior` now publish typed progress rows keyed by owner kind,
owner index, behavior index, behavior kind, and progress value.
Weapon behaviors now also publish typed runtime rows for firing state, ammo,
burst timing, cooldown progress, charged-weapon charging/charge state, and
constant-weapon reload/ammo-interval state.
burst timing, cooldown progress, charged-weapon charging/charge state,
constant-weapon reload/ammo-interval state, and lock-weapon lock progress
plus target entity reference.
Sensor, radiator, reactor, and capacitor behaviors publish typed state rows
for ping state, radiator temperature/throughput, reactor draw/load, and
capacitor charge/capacity/efficiency.
@ -794,6 +795,9 @@ First Aetheria surfaces to publish:
- Done: extend run checkpoint commits and smoke coverage to carry typed
weapon behavior state rows for instant, charged, and constant weapon
runtime internals.
- Done: extend weapon behavior state rows for lock-weapon progress and
target entity references, so lock acquisition state no longer evaporates
at the commit boundary.
- Done: extend run checkpoint commits and smoke coverage to carry typed
behavior state rows for sensor ping state plus radiator, reactor, and
capacitor runtime internals.