From 50f48bdeb523ed5f27a13071d700eeeb373224dd Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sat, 25 Mar 2023 19:33:47 +0500 Subject: [PATCH] Fixed #7 masturbation counted as sex with a partner Updated selection of place near bucket to masturbate --- Source/RJWSexperience/Patches/RJW_Patch.cs | 57 ++++++++++++++++--- .../SexHistory/SexHistoryComp.cs | 26 ++++----- .../RJWSexperience/SexHistory/UI/SexStatus.cs | 2 +- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Source/RJWSexperience/Patches/RJW_Patch.cs b/Source/RJWSexperience/Patches/RJW_Patch.cs index e0c3418..b3ccd7c 100644 --- a/Source/RJWSexperience/Patches/RJW_Patch.cs +++ b/Source/RJWSexperience/Patches/RJW_Patch.cs @@ -5,6 +5,7 @@ using RJWSexperience.Cum; using RJWSexperience.Logs; using RJWSexperience.SexHistory; using System; +using System.Collections.Generic; using UnityEngine; using Verse; @@ -44,7 +45,7 @@ namespace RJWSexperience LustUtility.UpdateLust(props, satisfaction, base_sat_per_fuck); CumUtility.FillCumBuckets(props); props.pawn.records?.Increment(VariousDefOf.OrgasmCount); - if (SexperienceMod.Settings.EnableSexHistory && props.partner != null) + if (SexperienceMod.Settings.EnableSexHistory && props.hasPartner()) props.pawn.TryGetComp()?.RecordSatisfaction(props.partner, props, satisfaction); } } @@ -80,7 +81,7 @@ namespace RJWSexperience { RJWUtility.UpdateSextypeRecords(props); - if (!SexperienceMod.Settings.EnableSexHistory || props.partner == null) + if (!SexperienceMod.Settings.EnableSexHistory || !props.hasPartner()) return; props.pawn.TryGetComp()?.RecordSex(props.partner, props); @@ -93,7 +94,7 @@ namespace RJWSexperience { public static void Postfix(JobDriver_SexBaseInitiator __instance) { - if (__instance.Partner != null) + if (__instance.Sexprops.hasPartner()) { __instance.pawn.PoptheCherry(__instance.Partner, __instance.Sexprops); __instance.Partner.PoptheCherry(__instance.pawn, __instance.Sexprops); @@ -110,10 +111,10 @@ namespace RJWSexperience /// /// /// - /// + /// Run original method public static bool Prefix(Pawn pawn, Pawn partner, ref IntVec3 __result) { - if (partner != null) + if (partner != null && partner != pawn) return true; // Not masturbation var log = LogManager.GetLogger("RJW_Patch_CasualSex_Helper_FindSexLocation"); @@ -129,13 +130,51 @@ namespace RJWSexperience if (bucket == null) { - log.Message("Bucket not found"); + log.Message("404 Bucket not found"); return true; } - __result = bucket.RandomAdjacentCell8Way(); - log.Message($"Bucket location: {__result}"); - return false; + Room bucketRoom = bucket.GetRoom(); + + List cellsAroundBucket = GenAdjFast.AdjacentCells8Way(bucket.Position); + IntVec3 doorNearBucket = IntVec3.Invalid; + + foreach (IntVec3 cell in cellsAroundBucket.InRandomOrder()) + { + if (!cell.Standable(bucket.Map)) + { + log.Message($"Discarded {cell}: not standable"); + continue; + } + + if (cell.GetRoom(bucket.Map) != bucketRoom) + { + if (cell.GetDoor(bucket.Map) != null) + { + doorNearBucket = cell; + } + else + { + log.Message($"Discarded {cell}: different room"); + } + + continue; + } + + __result = cell; + log.Message($"Masturbate at location: {__result}"); + return false; + } + + if (doorNearBucket != IntVec3.Invalid) + { + __result = doorNearBucket; + log.Message($"No proper place found, go jack off in the doorway: {__result}"); + return false; + } + + log.Message($"Failed to find situable location near the bucket at {bucket.Position}"); + return true; } } diff --git a/Source/RJWSexperience/SexHistory/SexHistoryComp.cs b/Source/RJWSexperience/SexHistory/SexHistoryComp.cs index 3598d3a..65f7928 100644 --- a/Source/RJWSexperience/SexHistory/SexHistoryComp.cs +++ b/Source/RJWSexperience/SexHistory/SexHistoryComp.cs @@ -44,6 +44,8 @@ namespace RJWSexperience.SexHistory public Gizmo Gizmo { get; private set; } + public Pawn ParentPawn => parent as Pawn; + public SexPartnerHistoryRecord GetFirstPartnerHistory => histories.TryGetValue(first); public SexPartnerHistoryRecord GetMostPartnerHistory @@ -245,17 +247,16 @@ namespace RJWSexperience.SexHistory public void RecordSex(Pawn partner, SexProps props) { - Pawn pawn = parent as Pawn; RecordFirst(partner, props); GetPartnerRecord(partner)?.RecordSex(props); recentPartner = partner.ThingID; recentSex = props.sexType; sextypeCount[(int)props.sexType]++; sextypeRecentTickAbs[(int)props.sexType] = GenTicks.TicksAbs; - if (partner.IsIncest(pawn)) incestuous++; + if (partner.IsIncest(ParentPawn)) incestuous++; if (partner.Dead) corpsefuck++; if (props.IsBestiality()) bestiality++; - else if (pawn.def != partner.def) interspecies++; + else if (ParentPawn.def != partner.def) interspecies++; dirty = true; } @@ -275,7 +276,7 @@ namespace RJWSexperience.SexHistory first = partner.ThingID; SexHistoryComp history = partner.TryGetComp(); firstSexTickAbs = GenTicks.TicksAbs; - history?.TakeSomeonesVirgin(parent as Pawn); + history?.TakeSomeonesVirgin(ParentPawn); } } @@ -288,12 +289,9 @@ namespace RJWSexperience.SexHistory return record; } - SexPartnerHistoryRecord newRecord = new SexPartnerHistoryRecord(partner, partner.IsIncest(parent as Pawn)); + SexPartnerHistoryRecord newRecord = new SexPartnerHistoryRecord(partner, partner.IsIncest(ParentPawn)); histories.Add(partnerId, newRecord); - if (parent is Pawn pawn) - { - pawn.records.Increment(VariousDefOf.SexPartnerCount); - } + ParentPawn.records.Increment(VariousDefOf.SexPartnerCount); return newRecord; } @@ -418,15 +416,15 @@ namespace RJWSexperience.SexHistory protected bool VirginCheck() { - if (histories.TryGetValue(first) != null) return false; + if (histories.TryGetValue(first) != null) + return false; - Pawn pawn = parent as Pawn; - return pawn?.IsVirgin() == true; + return ParentPawn.IsVirgin(); } public override IEnumerable CompGetGizmosExtra() { - if (SexperienceMod.Settings.HideGizmoWhenDrafted && (parent as Pawn)?.Drafted == true) + if (SexperienceMod.Settings.HideGizmoWhenDrafted && ParentPawn.Drafted) yield break; if (Find.Selector.NumSelected > 1) @@ -447,7 +445,7 @@ namespace RJWSexperience.SexHistory hotKey = VariousDefOf.OpenSexStatistics, action = delegate { - UI.SexStatusWindow.ToggleWindow(parent as Pawn, this); + UI.SexStatusWindow.ToggleWindow(ParentPawn, this); } }; } diff --git a/Source/RJWSexperience/SexHistory/UI/SexStatus.cs b/Source/RJWSexperience/SexHistory/UI/SexStatus.cs index f9dfe8c..880933b 100644 --- a/Source/RJWSexperience/SexHistory/UI/SexStatus.cs +++ b/Source/RJWSexperience/SexHistory/UI/SexStatus.cs @@ -223,7 +223,7 @@ namespace RJWSexperience.SexHistory.UI DrawBaseSexInfoLeft(leftRect.ContractedBy(4f)); //Center section - DrawBaseSexInfoCenter(centerRect.ContractedBy(4f), history.parent as Pawn); + DrawBaseSexInfoCenter(centerRect.ContractedBy(4f), history.ParentPawn); //Right section DrawBaseSexInfoRight(rightRect.ContractedBy(4f));