CombatState: drop the StatsKnown gate; a stale optimum is re-derived at the next agent Update
Agents update before the entities, so a weapon that came online this tick has evaluated by the next Update; the Weapon.StatsKnown flag and the gate on it were dead machinery and are removed. The add handler no longer marks stale itself (a new item's Online subscription does). The refit test fits and removes a dominating gun. Not yet verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7e92c7da93
commit
1e9a89e401
3 changed files with 43 additions and 28 deletions
|
|
@ -24,13 +24,14 @@ public class CombatState : BaseState
|
|||
public CombatState(Agent agent) : base(agent)
|
||||
{
|
||||
foreach (var item in _agent.Ship.Equipment) Watch(item);
|
||||
_agent.Ship.Equipment.ObserveAdd().Subscribe(add => { Watch(add.Value); _optimumStale = true; });
|
||||
_agent.Ship.Equipment.ObserveAdd().Subscribe(add => Watch(add.Value));
|
||||
_agent.Ship.Equipment.ObserveRemove().Subscribe(_ => _optimumStale = true);
|
||||
}
|
||||
|
||||
// The optimum is a function of the loadout's evaluated stats, so it is re-derived whenever a weapon comes or goes
|
||||
// or changes online state, and only once every weapon that can run has evaluated its stats (a weapon evaluates on
|
||||
// its first active tick, after it comes online): a ship the zone just spawned samples over live stats, not zeros.
|
||||
// The optimum is a function of the loadout's evaluated stats, so it is re-derived at the next Update (agents update
|
||||
// before the entities, so by then the weapons that came online this tick have evaluated) whenever a weapon is
|
||||
// added, removed or changes online state. Sampling on the event itself would read the stats before they exist: a
|
||||
// ship the zone just spawned would keep an optimum of 0.
|
||||
private void Watch(EquippedItem item)
|
||||
{
|
||||
if (item.Behaviors.OfType<Weapon>().Any()) item.Online.Subscribe(_ => _optimumStale = true);
|
||||
|
|
@ -38,7 +39,7 @@ public class CombatState : BaseState
|
|||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
if (_optimumStale && _agent.Ship.Weapons.All(w => w.StatsKnown || !w.Item.Active.Value))
|
||||
if (_optimumStale)
|
||||
{
|
||||
SampleDps();
|
||||
_optimumStale = false;
|
||||
|
|
|
|||
|
|
@ -173,13 +173,9 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
Tracking = Evaluate(_data.Tracking);
|
||||
}
|
||||
|
||||
// False until the first active tick has evaluated the stats above: before it they all read zero.
|
||||
public bool StatsKnown { get; private set; }
|
||||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
UpdateStats();
|
||||
StatsKnown = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue