using RimWorld;
using RJWSexperience.Ideology.Precepts;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace RJWSexperience.Ideology
{
public static class RomanceChanceFactorHelpers
{
///
/// Default value for parent relation
///
private const float parentRomanceChanceFactor = 0.03f;
///
/// Get ideology adjusted romanceChanceFactor
///
public static float GetRomanceChanceFactor(Pawn pawn, Pawn partner)
{
float romanceChanceFactor = 1f;
if (!pawn.relations.FamilyByBlood.Contains(partner))
{
if (pawn.Ideo?.HasPrecept(RsiDefOf.Precept.Incestuos_IncestOnly) == true)
{
return parentRomanceChanceFactor;
}
else
{
return romanceChanceFactor;
}
}
PreceptDef incestuousPrecept = pawn.Ideo?.PreceptsListForReading.Select(precept => precept.def).FirstOrFallback(def => def.issue == RsiDefOf.Issue.Incestuos);
IEnumerable relations = pawn.GetRelations(partner).Where(def => def.familyByBloodRelation);
foreach (PawnRelationDef relationDef in relations)
{
romanceChanceFactor *= GetRomanceChanceFactor(relationDef, incestuousPrecept);
}
return romanceChanceFactor;
}
///
/// Get ideology adjusted romanceChanceFactor for the relation
///
public static float GetRomanceChanceFactor(PawnRelationDef relationDef, PreceptDef incestuousPrecept)
{
if (incestuousPrecept == null)
{
return relationDef.romanceChanceFactor;
}
var incestDefExt = incestuousPrecept.GetModExtension();
if (incestDefExt == null)
{
return relationDef.romanceChanceFactor;
}
BloodRelationDegree relationDegree = RelationHelpers.GetBloodRelationDegree(relationDef);
if (incestDefExt.TryGetRomanceChanceFactor(relationDegree, out var romanceChanceOverride))
{
return romanceChanceOverride;
}
return relationDef.romanceChanceFactor;
}
[DebugAction("RJW Sexperience Ideology", "Show romanceChanceFactors", false, true, actionType = DebugActionType.Action, allowedGameStates = AllowedGameStates.Entry)]
public static void DisplayDebugTable()
{
IEnumerable incestuousPrecepts = DefDatabase
.AllDefsListForReading
.Where(def => def.issue == RsiDefOf.Issue.Incestuos);
IEnumerable> preceptGetters = incestuousPrecepts
.Select(precept => new TableDataGetter(precept.defName,(PawnRelationDef rel) => GetRomanceChanceFactor(rel, precept)));
var relName = new TableDataGetter("Relation Def", (PawnRelationDef rel) => rel.defName);
TableDataGetter[] getters = (new List>() { relName }).Concat(preceptGetters).ToArray();
DebugTables.MakeTablesDialog(DefDatabase.AllDefsListForReading, getters);
}
}
}