Added isBloodRelated filter attribute

This commit is contained in:
amevarashi 2022-11-21 22:40:44 +05:00
parent 765e6c0778
commit 7d6f0d043c
8 changed files with 92 additions and 142 deletions

View file

@ -1,30 +1,41 @@
using System.Collections.Generic;
using RJWSexperience.Ideology.Filters;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Verse;
namespace RJWSexperience.Ideology.Precepts
{
/// <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")]
public class DefExtension_ModifyPreference : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<Rule> rules;
/// <summary>
/// Apply SexAppraiser modifiers from rules with a satisfied filter
/// </summary>
public void Apply(Pawn pawn, Pawn partner, ref float preference)
{
foreach (Rule rule in rules)
foreach (Rule rule in rules.Where(rule => rule.Applies(pawn, partner)))
{
if (rule.Applies(pawn, partner))
preference *= rule.multiplier;
preference *= rule.multiplier;
}
}
/// <summary>
/// Type to associate SexAppraiser result modifier with a TwoPawnFilter
/// </summary>
public class Rule
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float multiplier = 1f;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public TwoPawnFilter filter;
/// <summary>
/// Check if the pair of pawns fits filter conditions
/// </summary>
public bool Applies(Pawn pawn, Pawn partner)
{
if (filter == null)