From 05e9c5d2731a7f846e969778333fd9f9c36cdc6f Mon Sep 17 00:00:00 2001 From: Leonhard Applis Date: Wed, 10 Aug 2022 21:08:21 +0200 Subject: [PATCH] Added a draft for proselyzing by sex --- .../PreceptDefs/Precepts_SexProselytizing.xml | 32 ++++++++++++++++ Source/IdeologyAddon/Ideology/IdeoUtility.cs | 20 ++++++++++ .../Ideology/Patches/RJW_Patch_Ideo.cs | 37 +++++++++++++++++++ Source/IdeologyAddon/Ideology/VariousDefOf.cs | 5 +++ 4 files changed, 94 insertions(+) create mode 100644 1.3/Defs/PreceptDefs/Precepts_SexProselytizing.xml diff --git a/1.3/Defs/PreceptDefs/Precepts_SexProselytizing.xml b/1.3/Defs/PreceptDefs/Precepts_SexProselytizing.xml new file mode 100644 index 0000000..8afe4c1 --- /dev/null +++ b/1.3/Defs/PreceptDefs/Precepts_SexProselytizing.xml @@ -0,0 +1,32 @@ + + + + + + Sex_Proselytizing + + UI/Issues/Submissive + + + + Proselyzing_By_Orgasm + Sex_Proselytizing + + Orgasms converts both partners towards this ideology. + Low + 50 + 400 + + + \ No newline at end of file diff --git a/Source/IdeologyAddon/Ideology/IdeoUtility.cs b/Source/IdeologyAddon/Ideology/IdeoUtility.cs index 9414558..2f558de 100644 --- a/Source/IdeologyAddon/Ideology/IdeoUtility.cs +++ b/Source/IdeologyAddon/Ideology/IdeoUtility.cs @@ -34,6 +34,26 @@ namespace RJWSexperience.Ideology } return finalMultiplier; } + internal static void ConvertPawnBySex(Pawn pawn, Pawn partner, float severity = 0.01f) + { + // Important Note: This is called on "orgasm" - hence when a pawn has the orgasm he is the "pawn" here. + // If Bob fucks Alice, Alice has the orgasm and Alice is the Pawn while Bob is the Partner. + // Hence, the Conversion happens from Partner -> Pawn and not the other way round! + + // Short Circuit: Either pawn is null, exit early and do nothing + if (pawn == null || partner == null) return; + bool sameIdeo = pawn.Ideo == partner.Ideo; + // Option A: Partner has same Ideo as Pawn, increase certainty + if (sameIdeo) + { + pawn.ideo.OffsetCertainty(severity); + } + // Option B: Partner as different Ideo, try to convert + else + { + pawn.ideo.IdeoConversionAttempt(severity, partner.Ideo); + } + } public static float getGenitalSize(Pawn p) { diff --git a/Source/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs b/Source/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs index b7c48d6..ddb13db 100644 --- a/Source/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs +++ b/Source/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs @@ -210,5 +210,42 @@ namespace RJWSexperience.Ideology.Patches ideo = mother?.Ideo; return mother?.Faction ?? baby.Faction; } + + [HarmonyPatch(typeof(JobDriver_Sex), "Roll_Orgasm_Duration_Reset")] + public static class RJW_Patch_Orgasm_IdeoConversion + { + public static void Postfix(JobDriver_Sex __instance) + { + // ShortCuts: Exit Early if Pawn or Partner are null (can happen with Animals or Masturbation) + // TODO: From my Tests, this does still invoke on masturbation + if (__instance.pawn == null || __instance.Partner == null) + return; + // Orgasm is called "all the time" - it exits early when the sex is still going. + // Hence, we hijack the "Roll_Orgasm_Duration_Reset" which is fired after the real orgasm happened + // But we have to check for one edge case, namely the function is also done when sex is initialized (which we catch by checking for orgasm > 0 + if (__instance.orgasms <= 0) return; + + if (__instance.Partner.Ideo.HasPrecept(VariousDefOf.Proselyzing_By_Orgasm)) + { + // Pawn is the one having the orgasm + // Partner is "giving" the orgasm, hence the pawn will be converted towards the partners ideology + IdeoUtility.ConvertPawnBySex(__instance.pawn, __instance.Partner, 0.03f); + } + } + } + + // TODO: This does not work as intended! + // Something is wrong with this, it's not called correctly.I expect this to be the wrong Harmony Patch Point + [HarmonyPatch(typeof(SexUtility), "Aftersex", new Type[] { typeof(SexProps) })] + public static class RJW_Patch_Aftersex_IdeoConversion + { + // This is not exactly where I should put it (Maybe after The JobDriver_Sex Finishes??) + public static void Postfix(SexProps props) + { + IdeoUtility.ConvertPawnBySex(props.pawn, props.partner, props.orgasms * 0.03f); + } + + } + } } diff --git a/Source/IdeologyAddon/Ideology/VariousDefOf.cs b/Source/IdeologyAddon/Ideology/VariousDefOf.cs index 8d1f5a4..4cce63e 100644 --- a/Source/IdeologyAddon/Ideology/VariousDefOf.cs +++ b/Source/IdeologyAddon/Ideology/VariousDefOf.cs @@ -21,5 +21,10 @@ namespace RJWSexperience.Ideology [MayRequireIdeology] public static readonly PreceptDef BabyFaction_AlwaysColony; [MayRequireIdeology] public static readonly PreceptDef Submissive_Male; [MayRequireIdeology] public static readonly PreceptDef Submissive_Female; + [MayRequireIdeology] public static readonly PreceptDef Proselyzing_By_Orgasm; + [MayRequireIdeology] public static readonly PreceptDef Proselyzing_By_Sex; + [MayRequireIdeology] public static readonly PreceptDef GenitalSize_Approved; + [MayRequireIdeology] public static readonly PreceptDef GenitalSize_Disapproved; + [MayRequireIdeology] public static readonly PreceptDef GenitalSize_NoRules; } }