using RJWSexperience.Ideology.Filters;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Verse;
namespace RJWSexperience.Ideology.Precepts
{
///
/// Def extension to enable changing SexAppraiser results based on filters
///
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
public class DefExtension_ModifyPreference : DefModExtension
{
public List rules;
///
/// Apply SexAppraiser modifiers from rules with a satisfied filter
///
public void Apply(Pawn pawn, Pawn partner, ref float preference)
{
foreach (Rule rule in rules.Where(rule => rule.Applies(pawn, partner)))
{
preference *= rule.multiplier;
}
}
///
/// Type to associate SexAppraiser result modifier with a TwoPawnFilter
///
public class Rule
{
public float multiplier = 1f;
public TwoPawnFilter filter;
///
/// Check if the pair of pawns fits filter conditions
///
public bool Applies(Pawn pawn, Pawn partner)
{
if (filter == null)
return true;
return filter.Applies(pawn, partner);
}
}
}
}