2022-06-19 12:40:38 +00:00
|
|
|
|
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 12:40:38 +00:00
|
|
|
|
{
|
2022-06-19 13:26:35 +00:00
|
|
|
|
public class DefExtension_ModifyPreference : DefModExtension
|
2022-06-19 12:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
[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;
|
2022-06-19 12:40:38 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PartnerFilter
|
|
|
|
|
{
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public bool? isAnimal;
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public bool? isVeneratedAnimal;
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public bool? isSlave;
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public bool? isAlien;
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public List<PawnRelationDef> hasOneOfRelations;
|
|
|
|
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
|
|
|
|
public List<PawnRelationDef> hasNoneOfRelations;
|
|
|
|
|
|
|
|
|
|
public bool Applies(Pawn pawn, Pawn partner)
|
|
|
|
|
{
|
|
|
|
|
if (isAnimal != null && isAnimal != partner.IsAnimal())
|
2022-06-19 12:40:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2022-07-03 06:42:07 +00:00
|
|
|
|
if (isVeneratedAnimal != null && isVeneratedAnimal != pawn.Ideo.IsVeneratedAnimal(partner))
|
2022-06-19 12:40:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2022-07-03 06:42:07 +00:00
|
|
|
|
if (isSlave != null && isSlave != partner.IsSlave)
|
2022-06-21 04:00:17 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2022-07-03 06:42:07 +00:00
|
|
|
|
//if (isAlien != null && isAlien != partner)
|
2022-06-21 04:00:17 +00:00
|
|
|
|
// return false;
|
|
|
|
|
|
2022-07-03 06:42:07 +00:00
|
|
|
|
if (!hasOneOfRelations.NullOrEmpty())
|
2022-06-19 12:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (pawn.relations == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
2022-07-03 06:42:07 +00:00
|
|
|
|
foreach (PawnRelationDef relationDef in hasOneOfRelations)
|
2022-06-19 12:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (pawn.relations?.DirectRelationExists(relationDef, partner) == true)
|
|
|
|
|
{
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 06:42:07 +00:00
|
|
|
|
if (!hasNoneOfRelations.NullOrEmpty() && pawn.relations != null)
|
2022-06-19 12:40:38 +00:00
|
|
|
|
{
|
2022-07-03 06:42:07 +00:00
|
|
|
|
foreach (PawnRelationDef relationDef in hasNoneOfRelations)
|
2022-06-19 12:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (pawn.relations.DirectRelationExists(relationDef, partner))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|