mirror of
https://github.com/amevarashi/RJW-Sexperience.git
synced 2024-08-14 23:54:08 +00:00
Fix NRE for races with no reproductive lifestages
This commit is contained in:
parent
5a68c6ec58
commit
607844bb0b
3 changed files with 49 additions and 14 deletions
|
@ -13,8 +13,8 @@ namespace RJWSexperience
|
|||
Trait virgin = p.story?.traits?.GetTrait(VariousDefOf.Virgin);
|
||||
if (virgin != null) p.story.traits.RemoveTrait(virgin);
|
||||
ResetRecord(p, true);
|
||||
ResetRecord(p, false);
|
||||
p.AddVirginTrait();
|
||||
if (ResetRecord(p, false))
|
||||
p.AddVirginTrait();
|
||||
MoteMaker.ThrowText(p.TrueCenter(), p.Map, "Records resetted!");
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,13 @@ namespace RJWSexperience
|
|||
MoteMaker.ThrowText(p.TrueCenter(), p.Map, "Lust: " + p.records.GetValue(VariousDefOf.Lust));
|
||||
}
|
||||
|
||||
private static void ResetRecord(Pawn pawn, bool allzero)
|
||||
private static bool ResetRecord(Pawn pawn, bool allzero)
|
||||
{
|
||||
if (!allzero)
|
||||
{
|
||||
if (SexperienceMod.Settings.History.EnableRecordRandomizer && pawn != null && xxx.is_human(pawn))
|
||||
if (SexperienceMod.Settings.History.EnableRecordRandomizer && xxx.is_human(pawn))
|
||||
{
|
||||
RecordRandomizer.Randomize(pawn);
|
||||
return RecordRandomizer.Randomize(pawn);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -102,6 +102,8 @@ namespace RJWSexperience
|
|||
pawn.records.SetTo(xxx.CountOfSexWithOthers, 0);
|
||||
pawn.records.SetTo(xxx.CountOfWhore, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,11 +10,16 @@ namespace RJWSexperience
|
|||
{
|
||||
public static void Postfix(PawnGenerationRequest request, ref Pawn __result)
|
||||
{
|
||||
if (SexperienceMod.Settings.History.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result))
|
||||
{
|
||||
RecordRandomizer.Randomize(__result);
|
||||
}
|
||||
__result.AddVirginTrait();
|
||||
if (__result == null)
|
||||
return;
|
||||
|
||||
bool doVirginTrait = true;
|
||||
|
||||
if (SexperienceMod.Settings.History.EnableRecordRandomizer && !request.Newborn && xxx.is_human(__result))
|
||||
doVirginTrait = RecordRandomizer.Randomize(__result);
|
||||
|
||||
if (doVirginTrait)
|
||||
__result.AddVirginTrait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,30 +3,52 @@ using System;
|
|||
using Verse;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
using RJWSexperience.Logs;
|
||||
|
||||
namespace RJWSexperience
|
||||
{
|
||||
public static class RecordRandomizer
|
||||
{
|
||||
private static readonly rjw.Modules.Shared.Logs.ILog log = LogManager.GetLogger<DebugLogProvider>("RecordRandomizer");
|
||||
|
||||
private static Settings.SettingsTabHistory Settings => SexperienceMod.Settings.History;
|
||||
|
||||
public static void Randomize(Pawn pawn)
|
||||
public static bool Randomize(Pawn pawn)
|
||||
{
|
||||
log.Message($"Randomize request for {pawn.NameShortColored}");
|
||||
|
||||
int avgsex = -500;
|
||||
bool isvirgin = Rand.Chance(Settings.VirginRatio);
|
||||
int totalsex = 0;
|
||||
int totalbirth = 0;
|
||||
int deviation = (int)Settings.MaxSexCountDeviation;
|
||||
|
||||
if (isvirgin)
|
||||
log.Message("Rand.Chance rolled virgin");
|
||||
|
||||
if (pawn.story != null)
|
||||
{
|
||||
float lust = RandomizeLust(pawn);
|
||||
|
||||
int sexableage = 0;
|
||||
int minsexage = 0;
|
||||
if (Settings.MinSexableFromLifestage)
|
||||
minsexage = (int)pawn.RaceProps.lifeStageAges.Find(x => x.def.reproductive).minAge;
|
||||
{
|
||||
LifeStageAge lifeStageAges = pawn.RaceProps.lifeStageAges.Find(x => x.def.reproductive);
|
||||
if (lifeStageAges == null)
|
||||
{
|
||||
log.Message($"No reproductive life stage! {pawn.NameShortColored}'s randomizstion cancelled");
|
||||
return false;
|
||||
}
|
||||
minsexage = (int)lifeStageAges.minAge;
|
||||
}
|
||||
else
|
||||
{
|
||||
minsexage = (int)(pawn.RaceProps.lifeExpectancy * Settings.MinSexablePercent);
|
||||
}
|
||||
|
||||
log.Message($"Min sex age is {minsexage}");
|
||||
|
||||
float lust = RandomizeLust(pawn);
|
||||
log.Message($"Lust set to {lust}");
|
||||
|
||||
if (pawn.ageTracker.AgeBiologicalYears > minsexage)
|
||||
{
|
||||
|
@ -34,6 +56,9 @@ namespace RJWSexperience
|
|||
avgsex = (int)(sexableage * Settings.SexPerYear * LustUtility.GetLustFactor(lust));
|
||||
}
|
||||
|
||||
log.Message($"Generating {sexableage} years of sex life");
|
||||
log.Message($"Average sex/year: {avgsex}");
|
||||
|
||||
if (pawn.relations != null && pawn.gender == Gender.Female)
|
||||
{
|
||||
totalbirth += pawn.relations.ChildrenCount;
|
||||
|
@ -83,7 +108,10 @@ namespace RJWSexperience
|
|||
}
|
||||
}
|
||||
pawn.records?.SetTo(xxx.CountOfSex, totalsex);
|
||||
log.Message($"Splitting {totalsex} sex acts between sex types");
|
||||
GenerateSextypeRecords(pawn, totalsex);
|
||||
log.Message($"{pawn.NameShortColored} randomized");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static float RandomizeLust(Pawn pawn)
|
||||
|
|
Loading…
Reference in a new issue