Persist weapon runtime state in checkpoints

This commit is contained in:
Meta Vens 2026-06-14 14:19:21 +01:00
commit f98f650ab5
10 changed files with 287 additions and 8 deletions

View file

@ -788,10 +788,75 @@ public class ActionGameManager : MonoBehaviour
.ToArray() ?? Array.Empty<IReadOnlyList<int>>(),
StatGrids = ProjectEntityStatGrids(entity),
ActiveConsumables = ProjectActiveConsumables(entity),
BehaviorProgress = ProjectBehaviorProgress(entity)
BehaviorProgress = ProjectBehaviorProgress(entity),
WeaponStates = ProjectWeaponStates(entity)
};
}
private static AetheriaRuntimeWeaponStateCommit[] ProjectWeaponStates(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));
var activeConsumables = entity.ActiveConsumables;
for (var ownerIndex = 0; ownerIndex < activeConsumables.Count; ownerIndex++)
states.AddRange(ProjectWeaponStates("active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors));
return states.ToArray();
}
private static IEnumerable<AetheriaRuntimeWeaponStateCommit> ProjectWeaponStates(
string ownerKind,
int ownerIndex,
IReadOnlyList<Behavior> behaviors)
{
if (behaviors == null)
yield break;
for (var behaviorIndex = 0; behaviorIndex < behaviors.Count; behaviorIndex++)
{
if (!(behaviors[behaviorIndex] is Weapon weapon))
continue;
var state = new AetheriaRuntimeWeaponStateCommit
{
OwnerKind = ownerKind,
OwnerIndex = ownerIndex,
BehaviorIndex = behaviorIndex,
BehaviorKind = weapon.Data?.Kind ?? "",
Firing = weapon.Firing,
Ammo = weapon.Ammo
};
if (weapon is InstantWeapon instant)
{
state.BurstRemaining = instant.BurstRemaining;
state.BurstTimer = instant.BurstTimer;
state.BurstInterval = instant.BurstInterval;
state.CooldownProgress = instant.CooldownProgress;
state.CoolingDown = instant.CoolingDown;
}
if (weapon is ChargedWeapon charged)
{
state.Charging = charged.Charging;
state.Charged = charged.Charged;
state.Charge = charged.Charge;
}
if (weapon is ConstantWeapon constant)
{
state.Reloading = constant.Reloading;
state.ReloadProgress = constant.ReloadProgress;
state.AmmoIntervalProgress = constant.AmmoIntervalProgress;
}
yield return state;
}
}
private static AetheriaRuntimeBehaviorProgressCommit[] ProjectBehaviorProgress(Entity entity)
{
var progress = new List<AetheriaRuntimeBehaviorProgressCommit>();

View file

@ -95,6 +95,8 @@ public class ChargedWeapon : InstantWeapon
{
get => _charge;
}
public bool Charging => _charging;
public bool Charged => _charged;
public ChargedWeapon(ChargedWeaponData data, EquippedItem item) : base(data, item)
{

View file

@ -35,6 +35,9 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
{
get => _ammo;
}
public float AmmoIntervalProgress => _ammoInterval;
public float ReloadProgress => _reload;
public bool Reloading => _reloading;
public float Progress
{
@ -147,4 +150,4 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
OnStopFiring?.Invoke();
}
}
}
}

View file

@ -59,6 +59,11 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
{
get => _ammo;
}
public int BurstRemaining => _burstRemaining;
public float BurstTimer => _burstTimer;
public float BurstInterval => _burstInterval;
public float CooldownProgress => _cooldown;
public bool CoolingDown => _coolingDown;
public virtual float Progress => saturate(_cooldown);
public event Action OnReloadBegin;
@ -197,4 +202,4 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
Trigger();
base.Activate();
}
}
}