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);
|
Trait virgin = p.story?.traits?.GetTrait(VariousDefOf.Virgin);
|
||||||
if (virgin != null) p.story.traits.RemoveTrait(virgin);
|
if (virgin != null) p.story.traits.RemoveTrait(virgin);
|
||||||
ResetRecord(p, true);
|
ResetRecord(p, true);
|
||||||
ResetRecord(p, false);
|
if (ResetRecord(p, false))
|
||||||
p.AddVirginTrait();
|
p.AddVirginTrait();
|
||||||
MoteMaker.ThrowText(p.TrueCenter(), p.Map, "Records resetted!");
|
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));
|
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 (!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
|
else
|
||||||
|
|
@ -102,6 +102,8 @@ namespace RJWSexperience
|
||||||
pawn.records.SetTo(xxx.CountOfSexWithOthers, 0);
|
pawn.records.SetTo(xxx.CountOfSexWithOthers, 0);
|
||||||
pawn.records.SetTo(xxx.CountOfWhore, 0);
|
pawn.records.SetTo(xxx.CountOfWhore, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,16 @@ namespace RJWSexperience
|
||||||
{
|
{
|
||||||
public static void Postfix(PawnGenerationRequest request, ref Pawn __result)
|
public static void Postfix(PawnGenerationRequest request, ref Pawn __result)
|
||||||
{
|
{
|
||||||
if (SexperienceMod.Settings.History.EnableRecordRandomizer && __result != null && !request.Newborn && xxx.is_human(__result))
|
if (__result == null)
|
||||||
{
|
return;
|
||||||
RecordRandomizer.Randomize(__result);
|
|
||||||
}
|
bool doVirginTrait = true;
|
||||||
__result.AddVirginTrait();
|
|
||||||
|
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 Verse;
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using RJWSexperience.Logs;
|
||||||
|
|
||||||
namespace RJWSexperience
|
namespace RJWSexperience
|
||||||
{
|
{
|
||||||
public static class RecordRandomizer
|
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;
|
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;
|
int avgsex = -500;
|
||||||
bool isvirgin = Rand.Chance(Settings.VirginRatio);
|
bool isvirgin = Rand.Chance(Settings.VirginRatio);
|
||||||
int totalsex = 0;
|
int totalsex = 0;
|
||||||
int totalbirth = 0;
|
int totalbirth = 0;
|
||||||
int deviation = (int)Settings.MaxSexCountDeviation;
|
int deviation = (int)Settings.MaxSexCountDeviation;
|
||||||
|
|
||||||
|
if (isvirgin)
|
||||||
|
log.Message("Rand.Chance rolled virgin");
|
||||||
|
|
||||||
if (pawn.story != null)
|
if (pawn.story != null)
|
||||||
{
|
{
|
||||||
float lust = RandomizeLust(pawn);
|
|
||||||
|
|
||||||
int sexableage = 0;
|
int sexableage = 0;
|
||||||
int minsexage = 0;
|
int minsexage = 0;
|
||||||
if (Settings.MinSexableFromLifestage)
|
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
|
else
|
||||||
|
{
|
||||||
minsexage = (int)(pawn.RaceProps.lifeExpectancy * Settings.MinSexablePercent);
|
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)
|
if (pawn.ageTracker.AgeBiologicalYears > minsexage)
|
||||||
{
|
{
|
||||||
|
|
@ -34,6 +56,9 @@ namespace RJWSexperience
|
||||||
avgsex = (int)(sexableage * Settings.SexPerYear * LustUtility.GetLustFactor(lust));
|
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)
|
if (pawn.relations != null && pawn.gender == Gender.Female)
|
||||||
{
|
{
|
||||||
totalbirth += pawn.relations.ChildrenCount;
|
totalbirth += pawn.relations.ChildrenCount;
|
||||||
|
|
@ -83,7 +108,10 @@ namespace RJWSexperience
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pawn.records?.SetTo(xxx.CountOfSex, totalsex);
|
pawn.records?.SetTo(xxx.CountOfSex, totalsex);
|
||||||
|
log.Message($"Splitting {totalsex} sex acts between sex types");
|
||||||
GenerateSextypeRecords(pawn, totalsex);
|
GenerateSextypeRecords(pawn, totalsex);
|
||||||
|
log.Message($"{pawn.NameShortColored} randomized");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float RandomizeLust(Pawn pawn)
|
public static float RandomizeLust(Pawn pawn)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue