Refactor IdeoUtility

This commit is contained in:
amevarashi 2022-06-18 13:54:29 +05:00
parent 2fce94c913
commit 6c60df4df0

View file

@ -1,6 +1,5 @@
using RimWorld; using RimWorld;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Verse; using Verse;
namespace RJWSexperience.Ideology namespace RJWSexperience.Ideology
@ -10,39 +9,50 @@ namespace RJWSexperience.Ideology
public static bool IsSubmissive(this Pawn pawn) public static bool IsSubmissive(this Pawn pawn)
{ {
Ideo ideo = pawn.Ideo; Ideo ideo = pawn.Ideo;
if (ideo != null) if (ideo == null)
{ return false;
if (ideo.HasPrecept(VariousDefOf.Submissive_Female) && pawn.gender == Gender.Female) return true;
else if (ideo.HasPrecept(VariousDefOf.Submissive_Male) && pawn.gender == Gender.Male) return true; if (ideo.HasPrecept(VariousDefOf.Submissive_Female) && pawn.gender == Gender.Female)
} return true;
else if (ideo.HasPrecept(VariousDefOf.Submissive_Male) && pawn.gender == Gender.Male)
return true;
return false; return false;
} }
public static bool ContainAll(string str, string[] tags) public static bool ContainAll(string str, string[] tags)
{ {
if (tags.NullOrEmpty())
return true;
string lstr = str.ToLower(); string lstr = str.ToLower();
if (!tags.NullOrEmpty()) for (int i = 0; i < tags.Count(); i++) for (int i = 0; i < tags.Length; i++)
{ {
if (!lstr.Contains('[' + tags[i].ToLower() + ']')) return false; if (!lstr.Contains('[' + tags[i].ToLower() + ']'))
} return false;
}
return true; return true;
} }
public static bool IsIncest(Pawn pawn, Pawn partner) public static bool IsIncest(Pawn pawn, Pawn partner)
{ {
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(partner); IEnumerable<PawnRelationDef> relations = pawn.GetRelations(partner);
Ideo ideo = pawn.Ideo; if (relations.EnumerableNullOrEmpty())
bool wide = false; return false;
if (ideo != null) wide = ideo.HasPrecept(VariousDefOf.Incestuos_Disapproved_CloseOnly);
if (!relations.EnumerableNullOrEmpty()) foreach (PawnRelationDef relation in relations) bool wide = pawn.Ideo?.HasPrecept(VariousDefOf.Incestuos_Disapproved_CloseOnly) == true;
foreach (PawnRelationDef relation in relations)
{
if (wide)
{ {
if (wide) if (relation.incestOpinionOffset < 0)
{ return true;
if (relation.incestOpinionOffset < 0) return true;
}
else if (relation.familyByBloodRelation) return true;
} }
else if (relation.familyByBloodRelation)
{
return true;
}
}
return false; return false;
} }
} }