rjw-sexperience-ideology/Source/IdeologyAddon/Precepts/DefExtension_ModifyPreferen...

49 lines
1.2 KiB
C#
Raw Normal View History

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