48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using RimWorld;
|
|
using System.Collections.Generic;
|
|
using Verse;
|
|
|
|
namespace rjwquirks.Modules.Shared.PartnerSelectors
|
|
{
|
|
public class HasOneOfRelations : PartnerSelector
|
|
{
|
|
public List<PawnRelationDef> relations;
|
|
|
|
private HashSet<PawnRelationDef> relationsHashSet;
|
|
|
|
public override bool PartnerSatisfies(Pawn pawn, Pawn partner)
|
|
{
|
|
if (relationsHashSet == null)
|
|
{
|
|
relationsHashSet = new HashSet<PawnRelationDef>(relations);
|
|
}
|
|
|
|
IEnumerable<PawnRelationDef> pawnRelations = pawn.GetRelations(partner);
|
|
|
|
if (pawnRelations.EnumerableNullOrEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!relationsHashSet.Overlaps(pawnRelations))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override IEnumerable<string> ConfigErrors()
|
|
{
|
|
foreach (string error in base.ConfigErrors())
|
|
{
|
|
yield return error;
|
|
}
|
|
|
|
if (relations.NullOrEmpty())
|
|
{
|
|
yield return "<relations> is empty";
|
|
}
|
|
}
|
|
}
|
|
} |