RJW-Sexperience/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_ModifyPreference.cs

40 lines
1.1 KiB
C#
Raw Normal View History

using RimWorld;
using rjw;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
2022-06-19 13:26:35 +00:00
namespace RJWSexperience.Ideology.Precepts
{
2022-06-19 13:26:35 +00:00
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;
public void Apply(Pawn pawn, Pawn partner, ref float preference)
{
foreach (Rule rule in rules)
{
if (rule.Applies(pawn, partner))
preference *= rule.multiplier;
}
}
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")]
2022-07-03 06:42:07 +00:00
public PartnerFilter filter;
public bool Applies(Pawn pawn, Pawn partner)
{
if (filter == null)
return true;
2022-07-03 06:42:07 +00:00
return filter.Applies(pawn, partner);
}
}
}
}