Use typed behavior projections in stat modifiers
This commit is contained in:
parent
c68dc15c3e
commit
6a92564f94
3 changed files with 19 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue