rjw-sexperience-ideology/Source/IdeologyAddon/RomanceChanceFactorHelpers.cs

108 lines
3.2 KiB
C#
Raw Normal View History

using RimWorld;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace RJWSexperience.Ideology
{
public static class RomanceChanceFactorHelpers
{
/// <summary>
/// Default value for parent relation
/// </summary>
private const float parentRomanceChanceFactor = 0.03f;
/// <summary>
/// Get ideology adjusted romanceChanceFactor
/// </summary>
public static float GetRomanceChanceFactor(Pawn pawn, Pawn partner)
{
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(partner).Where(def => def.familyByBloodRelation);
PreceptDef incestuousPrecept = pawn.Ideo?.PreceptsListForReading.Select(precept => precept.def).FirstOrFallback(def => def.issue == VariousDefOf.Incestuos);
float romanceChanceFactor = 1f;
if (!relations.Any())
{
if (incestuousPrecept == RsiPreceptDefOf.Incestuos_IncestOnly)
{
return parentRomanceChanceFactor;
}
else
{
return romanceChanceFactor;
}
}
foreach (PawnRelationDef relationDef in relations)
{
romanceChanceFactor *= GetRomanceChanceFactor(relationDef, incestuousPrecept);
}
return romanceChanceFactor;
}
/// <summary>
/// Get ideology adjusted romanceChanceFactor for the relation
/// </summary>
public static float GetRomanceChanceFactor(PawnRelationDef relationDef, PreceptDef incestuousPrecept)
{
if (incestuousPrecept == null || incestuousPrecept == RsiPreceptDefOf.Incestuos_Disapproved) // Default game setup
{
return relationDef.romanceChanceFactor;
}
if (incestuousPrecept == RsiPreceptDefOf.Incestuos_Free)
{
return 1f;
}
else if (incestuousPrecept == RsiPreceptDefOf.Incestuos_Disapproved_CloseOnly)
{
if (relationDef.familyByBloodRelation && relationDef.importance > PawnRelationDefOf.Cousin.importance)
{
return relationDef.romanceChanceFactor;
}
else
{
return 1f;
}
}
else if (incestuousPrecept == RsiPreceptDefOf.Incestuos_Forbidden)
{
if (relationDef.familyByBloodRelation)
{
return parentRomanceChanceFactor;
}
}
else if (incestuousPrecept == RsiPreceptDefOf.Incestuos_IncestOnly)
{
if (!relationDef.familyByBloodRelation)
{
return parentRomanceChanceFactor;
}
else
{
return 1f;
}
}
return relationDef.romanceChanceFactor;
}
[DebugAction("RJW Sexperience Ideology", "Show romanceChanceFactors", false, true, actionType = DebugActionType.Action, allowedGameStates = AllowedGameStates.Entry)]
public static void DisplayDebugTable()
{
IEnumerable<PreceptDef> incestuousPrecepts = DefDatabase<PreceptDef>
.AllDefsListForReading
.Where(def => def.issue == VariousDefOf.Incestuos);
IEnumerable<TableDataGetter<PawnRelationDef>> preceptGetters = incestuousPrecepts
.Select(precept => new TableDataGetter<PawnRelationDef>(precept.defName,(PawnRelationDef rel) => GetRomanceChanceFactor(rel, precept)));
var relName = new TableDataGetter<PawnRelationDef>("Relation Def", (PawnRelationDef rel) => rel.defName);
TableDataGetter<PawnRelationDef>[] getters = (new List<TableDataGetter<PawnRelationDef>>() { relName }).Concat(preceptGetters).ToArray();
DebugTables.MakeTablesDialog(DefDatabase<PawnRelationDef>.AllDefsListForReading, getters);
}
}
}