diff --git a/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs b/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs index 3d82535..bb372fb 100644 --- a/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs +++ b/RJWSexperience/RJWSexperience/Patches/RJW_Patch.cs @@ -83,11 +83,11 @@ namespace RJWSexperience if (props.sexType != xxx.rjwSextype.Masturbation || props.partner != null) { - lustDelta = Mathf.Clamp((satisfaction - base_sat_per_fuck) * RJWUtility.LustIncrementFactor((float)lust), -0.5f, 0.5f); // If the sex is satisfactory, lust grows up. Declines at the opposite. + lustDelta = Mathf.Clamp((satisfaction - base_sat_per_fuck) * LustIncrementFactor((float)lust), -0.5f, 0.5f); // If the sex is satisfactory, lust grows up. Declines at the opposite. } else { - lustDelta = Mathf.Clamp(satisfaction * satisfaction * RJWUtility.LustIncrementFactor((float)lust), 0, 0.5f); // Masturbation always increases lust. + lustDelta = Mathf.Clamp(satisfaction * satisfaction * LustIncrementFactor((float)lust), 0, 0.5f); // Masturbation always increases lust. } if (lustDelta == 0) @@ -96,6 +96,12 @@ namespace RJWSexperience rjw.Modules.Shared.Logs.LogManager.GetLogger().Message($"{props.pawn.NameShortColored}'s lust changed by {lustDelta} (from {lust})"); props.pawn.records.AddTo(VariousDefOf.Lust, lustDelta); } + + private static float LustIncrementFactor(float lust) + { + return Mathf.Exp(-Mathf.Pow(lust / Configurations.LustLimit, 2)); + } + } [HarmonyPatch(typeof(SexUtility), "TransferNutrition")] diff --git a/RJWSexperience/RJWSexperience/RJWSexperience.csproj b/RJWSexperience/RJWSexperience/RJWSexperience.csproj index 6796d6c..4879c20 100644 --- a/RJWSexperience/RJWSexperience/RJWSexperience.csproj +++ b/RJWSexperience/RJWSexperience/RJWSexperience.csproj @@ -81,7 +81,7 @@ - + diff --git a/RJWSexperience/RJWSexperience/RJWUtility.cs b/RJWSexperience/RJWSexperience/RJWUtility.cs index b1df5c3..450ed8a 100644 --- a/RJWSexperience/RJWSexperience/RJWUtility.cs +++ b/RJWSexperience/RJWSexperience/RJWUtility.cs @@ -16,11 +16,6 @@ namespace RJWSexperience { public static class RJWUtility { - public static float LustIncrementFactor(float lust) - { - return Mathf.Exp(-Mathf.Pow(lust / Configurations.LustLimit, 2)); - } - public static bool RemoveVirginTrait(Pawn pawn, Pawn partner, SexProps props) { int degree; diff --git a/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs index 1f50eaf..1e6389d 100644 --- a/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs +++ b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistory.cs @@ -13,7 +13,7 @@ namespace RJWSexperience public SexPartnerHistory() { } public const int ARRLEN = 20; - protected Dictionary histories = new Dictionary(); + protected Dictionary histories = new Dictionary(); protected string first = ""; protected bool dirty = true; protected xxx.rjwSextype recentsex = xxx.rjwSextype.None; @@ -46,7 +46,7 @@ namespace RJWSexperience protected int mostsextickabscache = 0; protected int bestsextickabscache = 0; - public SexHistory GetFirstPartnerHistory + public SexPartnerHistoryRecord GetFirstPartnerHistory { get { @@ -54,7 +54,7 @@ namespace RJWSexperience return histories.TryGetValue(first); } } - public SexHistory GetMostPartnerHistory + public SexPartnerHistoryRecord GetMostPartnerHistory { get { @@ -78,8 +78,8 @@ namespace RJWSexperience return mostsatsextypecache; } } - public SexHistory GetRecentPartnersHistory => histories.TryGetValue(recentpartner); - public SexHistory GetBestSexPartnerHistory + public SexPartnerHistoryRecord GetRecentPartnersHistory => histories.TryGetValue(recentpartner); + public SexPartnerHistoryRecord GetBestSexPartnerHistory { get { @@ -96,11 +96,11 @@ namespace RJWSexperience } } public int VirginsTaken => virginstaken; - public List PartnerList + public List PartnerList { get { - List res = null; + List res = null; Update(); if (!histories.NullOrEmpty()) { @@ -113,7 +113,7 @@ namespace RJWSexperience { get { - if (histories == null) histories = new Dictionary(); + if (histories == null) histories = new Dictionary(); return histories.Count; } } @@ -272,7 +272,7 @@ namespace RJWSexperience Scribe_Collections.Look(ref sextypesatsave, "sextypesatsave", LookMode.Value); Scribe_Collections.Look(ref sextyperecenttickabssave, "sextyperecenttickabssave", LookMode.Value); - if (histories == null) histories = new Dictionary(); + if (histories == null) histories = new Dictionary(); if (Scribe.mode == LoadSaveMode.LoadingVars) { @@ -280,7 +280,7 @@ namespace RJWSexperience sextypesat = sextypesatsave?.ToArray() ?? new float[ARRLEN]; sextyperecenttickabs = sextyperecenttickabssave?.ToArray() ?? new int[ARRLEN]; - foreach (KeyValuePair element in histories) + foreach (KeyValuePair element in histories) { element.Value.parent = this; element.Value.partnerID = element.Key; @@ -292,10 +292,9 @@ namespace RJWSexperience public void RecordHistory(Pawn partner, SexProps props) { Pawn pawn = parent as Pawn; - TryAddHistory(partner); + SexPartnerHistoryRecord history = GetPartnerRecord(partner); RecordFirst(partner, props); recentpartner = partner.ThingID; - SexHistory history = histories[partner.ThingID]; history?.RecordSex(props); recentsex = props.sexType; sextypecount[(int)props.sexType]++; @@ -309,51 +308,48 @@ namespace RJWSexperience public void RecordSatisfactionHistory(Pawn partner, SexProps props, float satisfaction) { - TryAddHistory(partner); + SexPartnerHistoryRecord history = GetPartnerRecord(partner); RecordFirst(partner, props); - SexHistory history = histories[partner.ThingID]; history?.RecordSatisfaction(props, satisfaction); recentsat = satisfaction; sextypesat[(int)props.sexType] += satisfaction; dirty = true; } - protected bool TryAddHistory(Pawn partner) + protected SexPartnerHistoryRecord GetPartnerRecord(Pawn partner) { - if (!histories.ContainsKey(partner.ThingID)) + string partnerId = partner.ThingID; + + if (histories.TryGetValue(partnerId, out SexPartnerHistoryRecord record)) { - SexHistory newhistory = new SexHistory(partner, partner.IsIncest(parent as Pawn)); - histories.Add(partner.ThingID, newhistory); - Pawn pawn = parent as Pawn; - if (pawn != null) - { - pawn.records.AddTo(VariousDefOf.SexPartnerCount, 1); - } - return true; + return record; } - return false; + + SexPartnerHistoryRecord newRecord = new SexPartnerHistoryRecord(partner, partner.IsIncest(parent as Pawn)); + histories.Add(partnerId, newRecord); + if (parent is Pawn pawn) + { + pawn.records.Increment(VariousDefOf.SexPartnerCount); + } + return newRecord; } public void RecordFirst(Pawn partner, SexProps props) { if (VirginCheck() && props.sexType == xxx.rjwSextype.Vaginal) { - TryAddHistory(partner); + GetPartnerRecord(partner); first = partner.ThingID; SexPartnerHistory history = partner.GetPartnerHistory(); firstsextickabs = GenTicks.TicksAbs; - if (history != null) - { - history.TakeSomeonesVirgin(parent as Pawn); - } + history?.TakeSomeonesVirgin(parent as Pawn); } } public void TakeSomeonesVirgin(Pawn partner) { - TryAddHistory(partner); - SexHistory history = histories[partner.ThingID]; - if (history != null) history.TookVirgin(); + SexPartnerHistoryRecord partnerRecord = GetPartnerRecord(partner); + partnerRecord?.TookVirgin(); virginstaken++; } @@ -382,9 +378,9 @@ namespace RJWSexperience Dictionary racetotalsat = new Dictionary(); List allpartners = new List(); - foreach (KeyValuePair element in histories) + foreach (KeyValuePair element in histories) { - SexHistory h = element.Value; + SexPartnerHistoryRecord h = element.Value; //find most sex partner if (max < h.TotalSexCount) diff --git a/RJWSexperience/RJWSexperience/SexHistory/SexHistory.cs b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistoryRecord.cs similarity index 90% rename from RJWSexperience/RJWSexperience/SexHistory/SexHistory.cs rename to RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistoryRecord.cs index 2738e72..5686da7 100644 --- a/RJWSexperience/RJWSexperience/SexHistory/SexHistory.cs +++ b/RJWSexperience/RJWSexperience/SexHistory/SexPartnerHistoryRecord.cs @@ -11,7 +11,7 @@ using RJWSexperience.ExtensionMethods; namespace RJWSexperience { - public class SexHistory : IExposable + public class SexPartnerHistoryRecord : IExposable { public SexPartnerHistory parent; public string partnerID; @@ -115,9 +115,9 @@ namespace RJWSexperience } } - public SexHistory() { } + public SexPartnerHistoryRecord() { } - public SexHistory(Pawn pawn, bool incest = false) + public SexPartnerHistoryRecord(Pawn pawn, bool incest = false) { this.partner = pawn; this.namecache = pawn.Label; @@ -184,25 +184,25 @@ namespace RJWSexperience partner = Find.WorldPawns.AllPawnsAliveOrDead.FirstOrDefault(x => x.ThingID.Equals(partnerID)); } - public class RecentOrderComparer : IComparer + public class RecentOrderComparer : IComparer { - public int Compare(SexHistory x, SexHistory y) + public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y) { return y.RecentSexTickAbs.CompareTo(x.RecentSexTickAbs); } } - public class MostOrderComparer : IComparer + public class MostOrderComparer : IComparer { - public int Compare(SexHistory x, SexHistory y) + public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y) { return y.TotalSexCount.CompareTo(x.TotalSexCount); } } - public class NameOrderComparer : IComparer + public class NameOrderComparer : IComparer { - public int Compare(SexHistory x, SexHistory y) + public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y) { return x.Label.CompareTo(y.Label); } diff --git a/RJWSexperience/RJWSexperience/StatParts.cs b/RJWSexperience/RJWSexperience/StatParts.cs index b387fa2..8cb35a6 100644 --- a/RJWSexperience/RJWSexperience/StatParts.cs +++ b/RJWSexperience/RJWSexperience/StatParts.cs @@ -2,6 +2,7 @@ using System; using UnityEngine; using Verse; +using System.Diagnostics.CodeAnalysis; namespace RJWSexperience { @@ -10,7 +11,8 @@ namespace RJWSexperience /// public class StatPart_Lust : StatPart { - public float factor; // Value is loaded from XML + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] + public float factor; public override string ExplanationPart(StatRequest req) { @@ -48,7 +50,8 @@ namespace RJWSexperience /// public class StatPart_Slave : StatPart { - public float factor; // Value is loaded from XML + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] + public float factor; public override string ExplanationPart(StatRequest req) { diff --git a/RJWSexperience/RJWSexperience/UI/SexStatus.cs b/RJWSexperience/RJWSexperience/UI/SexStatus.cs index e03e323..383245b 100644 --- a/RJWSexperience/RJWSexperience/UI/SexStatus.cs +++ b/RJWSexperience/RJWSexperience/UI/SexStatus.cs @@ -58,10 +58,10 @@ namespace RJWSexperience.UI protected Pawn pawn; - protected SexHistory selectedPawn; + protected SexPartnerHistoryRecord selectedPawn; protected SexPartnerHistory history; protected CompRJW rjwcomp; - protected List partnerList; + protected List partnerList; protected PartnerOrderMode orderMode; private static GUIStyleState fontstylestate = new GUIStyleState() { textColor = Color.white }; @@ -184,13 +184,13 @@ namespace RJWSexperience.UI partnerList = history?.PartnerList; break; case PartnerOrderMode.Recent: - partnerList.Sort(new SexHistory.RecentOrderComparer()); + partnerList.Sort(new SexPartnerHistoryRecord.RecentOrderComparer()); break; case PartnerOrderMode.Most: - partnerList.Sort(new SexHistory.MostOrderComparer()); + partnerList.Sort(new SexPartnerHistoryRecord.MostOrderComparer()); break; case PartnerOrderMode.Name: - partnerList.Sort(new SexHistory.NameOrderComparer()); + partnerList.Sort(new SexPartnerHistoryRecord.NameOrderComparer()); break; } } @@ -222,7 +222,7 @@ namespace RJWSexperience.UI } - protected void DrawInfoWithPortrait(Rect rect, SexHistory history, string tooltip = "") + protected void DrawInfoWithPortrait(Rect rect, SexPartnerHistoryRecord history, string tooltip = "") { Widgets.DrawMenuSection(rect); string str = tooltip; @@ -271,7 +271,7 @@ namespace RJWSexperience.UI } } - protected void DrawSexInfoCard(Rect rect, SexHistory history, string label, string tooltip, string rightlabel = "") + protected void DrawSexInfoCard(Rect rect, SexPartnerHistoryRecord history, string label, string tooltip, string rightlabel = "") { Rect labelRect = new Rect(rect.x, rect.y, rect.width, FONTHEIGHT); Rect infoRect = new Rect(rect.x, rect.y + FONTHEIGHT, rect.width, rect.height - FONTHEIGHT); @@ -579,7 +579,7 @@ namespace RJWSexperience.UI listmain.End(); } - protected void DrawPartnerList(Rect rect, List partnerList) + protected void DrawPartnerList(Rect rect, List partnerList) { Rect pawnRect = new Rect(rect.x, rect.y, LISTPAWNSIZE, LISTPAWNSIZE); for (int i = 0; i < partnerList.Count; i++) @@ -603,7 +603,7 @@ namespace RJWSexperience.UI } } - protected void DrawPawn(Rect rect, SexHistory history) + protected void DrawPawn(Rect rect, SexPartnerHistoryRecord history) { if (history != null) {