59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
using rjwquirks.Modules.Shared.PawnSelectors;
|
|
using System.Collections.Generic;
|
|
using Verse;
|
|
|
|
namespace rjwquirks.Modules.Quirks
|
|
{
|
|
/// <summary>
|
|
/// Class to check if quirk can be assigned to a pawn
|
|
/// </summary>
|
|
public class OwnerRequirement
|
|
{
|
|
/// <summary>
|
|
/// Requirement conditions
|
|
/// </summary>
|
|
public IPawnSelector pawnSelector;
|
|
|
|
/// <summary>
|
|
/// Translation key for a displayed reason why quirk can't be assigned to a pawn
|
|
/// </summary>
|
|
[NoTranslate]
|
|
public string rejectionReason;
|
|
|
|
/// <summary>
|
|
/// Check if pawn satisfies requirement conditions
|
|
/// </summary>
|
|
public AcceptanceReport CheckBeforeAdd(Pawn pawn)
|
|
{
|
|
if (pawnSelector?.PawnSatisfies(pawn) == true)
|
|
{
|
|
return AcceptanceReport.WasAccepted;
|
|
}
|
|
else
|
|
{
|
|
return new AcceptanceReport(rejectionReason.Translate());
|
|
}
|
|
}
|
|
|
|
public IEnumerable<string> ConfigErrors()
|
|
{
|
|
if (pawnSelector == null)
|
|
{
|
|
yield return "<pawnSelector> is empty";
|
|
}
|
|
else
|
|
{
|
|
foreach (string error in pawnSelector.ConfigErrors())
|
|
{
|
|
yield return error;
|
|
}
|
|
}
|
|
|
|
if (rejectionReason.NullOrEmpty())
|
|
{
|
|
yield return "<rejectionReason> is empty";
|
|
}
|
|
}
|
|
}
|
|
}
|