From 724bcbe86b674fbef7068433e7afd1cb370cee15 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sun, 3 Jul 2022 11:59:54 +0500 Subject: [PATCH] Move PartnerFilter to a separate class --- .../IdeologyAddon/Ideology/PartnerFilter.cs | 68 +++++++++++++++++++ .../Precepts/DefExtension_ModifyPreference.cs | 60 ---------------- 2 files changed, 68 insertions(+), 60 deletions(-) create mode 100644 RJWSexperience/IdeologyAddon/Ideology/PartnerFilter.cs diff --git a/RJWSexperience/IdeologyAddon/Ideology/PartnerFilter.cs b/RJWSexperience/IdeologyAddon/Ideology/PartnerFilter.cs new file mode 100644 index 0000000..c02b7af --- /dev/null +++ b/RJWSexperience/IdeologyAddon/Ideology/PartnerFilter.cs @@ -0,0 +1,68 @@ +using RimWorld; +using rjw; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Verse; + +namespace RJWSexperience.Ideology +{ + 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 hasOneOfRelations; + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] + public List hasNoneOfRelations; + + public bool Applies(Pawn pawn, Pawn partner) + { + if (isAnimal != null && isAnimal != partner.IsAnimal()) + return false; + + if (isVeneratedAnimal != null && isVeneratedAnimal != pawn.Ideo.IsVeneratedAnimal(partner)) + return false; + + if (isSlave != null && isSlave != partner.IsSlave) + return false; + + //if (isAlien != null && isAlien != partner) + // return false; + + if (!hasOneOfRelations.NullOrEmpty()) + { + if (pawn.relations == null) + return false; + + bool found = false; + foreach (PawnRelationDef relationDef in hasOneOfRelations) + { + if (pawn.relations?.DirectRelationExists(relationDef, partner) == true) + { + found = true; + break; + } + } + if (!found) + return false; + } + + if (!hasNoneOfRelations.NullOrEmpty() && pawn.relations != null) + { + foreach (PawnRelationDef relationDef in hasNoneOfRelations) + { + if (pawn.relations.DirectRelationExists(relationDef, partner)) + return false; + } + } + + return true; + } + } +} diff --git a/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_ModifyPreference.cs b/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_ModifyPreference.cs index b0a8cbc..86608e1 100644 --- a/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_ModifyPreference.cs +++ b/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_ModifyPreference.cs @@ -35,65 +35,5 @@ namespace RJWSexperience.Ideology.Precepts 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 hasOneOfRelations; - [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] - public List hasNoneOfRelations; - - public bool Applies(Pawn pawn, Pawn partner) - { - if (isAnimal != null && isAnimal != partner.IsAnimal()) - return false; - - if (isVeneratedAnimal != null && isVeneratedAnimal != pawn.Ideo.IsVeneratedAnimal(partner)) - return false; - - if (isSlave != null && isSlave != partner.IsSlave) - return false; - - //if (isAlien != null && isAlien != partner) - // return false; - - if (!hasOneOfRelations.NullOrEmpty()) - { - if (pawn.relations == null) - return false; - - bool found = false; - foreach (PawnRelationDef relationDef in hasOneOfRelations) - { - if (pawn.relations?.DirectRelationExists(relationDef, partner) == true) - { - found = true; - break; - } - } - if (!found) - return false; - } - - if (!hasNoneOfRelations.NullOrEmpty() && pawn.relations != null) - { - foreach (PawnRelationDef relationDef in hasNoneOfRelations) - { - if (pawn.relations.DirectRelationExists(relationDef, partner)) - return false; - } - } - - return true; - } - } } }