Consumable host: one initialiser for gear and running effects; tests pin overlap, lifetime, per-design cooldown, refit

Entity.Activate re-initialises the running consumable effects through the same
InitializeBehaviors that initialises gear and ActivateConsumable, so a consumable
active across deactivate/refit/activate retargets to the new items.
ConsumableTests gains the stackable overlap/multiply, shared-entry detach,
expiry-boundary, per-design cooldown and refit facts. StatResolverTests' expiry
test builds its consumable through ItemManager.CreateInstance.
Not yet built or run; verification follows in a later commit message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-09 23:24:54 +02:00
commit 29c5f7aba1
3 changed files with 109 additions and 11 deletions

View file

@ -203,12 +203,10 @@ public abstract class Entity
return presencePermitted;
}), initialValue: true);
foreach (var item in Equipment)
foreach (var behavior in item.Behaviors)
{
if(behavior is IInitializableBehavior initializableBehavior)
initializableBehavior.Initialize();
}
// One initialiser for everything that computes targets here: gear and the effects still running, so a
// consumable active across a refit retargets to the new items exactly as gear does.
InitializeBehaviors(Equipment.SelectMany(item => item.Behaviors));
InitializeBehaviors(_activeConsumables.SelectMany(effect => effect.Behaviors));
foreach(var entity in Zone.Entities)
{
EntityInfoGathered[entity] = 0;
@ -863,10 +861,15 @@ public abstract class Entity
var effect = new ConsumableItemEffect(item, this);
// The same hook Activate runs over Equipment: a behaviour that computes its targets there (StatModifier)
// would otherwise reach its second tick uninitialised.
foreach (var behavior in effect.Behaviors)
InitializeBehaviors(effect.Behaviors);
_activeConsumables.Add(effect);
}
private static void InitializeBehaviors(IEnumerable<Behavior> behaviors)
{
foreach (var behavior in behaviors.ToList())
if (behavior is IInitializableBehavior initializable)
initializable.Initialize();
_activeConsumables.Add(effect);
}
public ConsumableItemEffect FindActiveConsumable(ConsumableItemData data)