Use typed behavior projections in stat modifiers

This commit is contained in:
Meta Vens 2026-06-14 06:02:26 +01:00
commit 6a92564f94
3 changed files with 19 additions and 5 deletions

View file

@ -67,15 +67,15 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwa
if (typeof(EquippableItemData).IsAssignableFrom(targetType))
_stats = Entity.Equipment
.Select(hp => hp.EquippableItem)
.Where(gear => _data.RequireBehavior == null || ItemManager.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
.Where(HasRequiredBehavior)
.Where(gear => ItemManager.GetData(gear).GetType() == targetType)
.Select(gear => statField.GetValue(ItemManager.GetData(gear)) as PerformanceStat)
.ToArray();
else
_stats = Entity.Equipment
.Select(hp => hp.EquippableItem)
.Where(gear => _data.RequireBehavior == null || ItemManager.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
.SelectMany(gear => ItemManager.GetData(gear).Behaviors)
.Where(HasRequiredBehavior)
.SelectMany(gear => ItemManager.GetRuntimeBehaviorProjections(gear))
.Where(behaviorData => behaviorData.GetType() == targetType)
.Select(behaviorData => statField.GetValue(behaviorData) as PerformanceStat)
.ToArray();
@ -83,6 +83,13 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwa
}
}
private bool HasRequiredBehavior(EquippableItem gear)
{
return _data.RequireBehavior == null ||
ItemManager.GetRuntimeBehaviorProjections(gear)
.Any(behavior => behavior.GetType() == _data.RequireBehavior);
}
private void ApplyModifier()
{
_applied = true;
@ -135,4 +142,4 @@ public class StatReference
[Inspectable, LegacyPayloadKey(2)]
public string Stat;
}
}