Refactor?

This commit is contained in:
amevarashi 2022-03-26 23:11:59 +05:00
parent 60b268695c
commit cea590edd4
7 changed files with 63 additions and 63 deletions

View File

@ -83,11 +83,11 @@ namespace RJWSexperience
if (props.sexType != xxx.rjwSextype.Masturbation || props.partner != null) 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 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) if (lustDelta == 0)
@ -96,6 +96,12 @@ namespace RJWSexperience
rjw.Modules.Shared.Logs.LogManager.GetLogger<RjwSexperienceMod>().Message($"{props.pawn.NameShortColored}'s lust changed by {lustDelta} (from {lust})"); rjw.Modules.Shared.Logs.LogManager.GetLogger<RjwSexperienceMod>().Message($"{props.pawn.NameShortColored}'s lust changed by {lustDelta} (from {lust})");
props.pawn.records.AddTo(VariousDefOf.Lust, lustDelta); 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")] [HarmonyPatch(typeof(SexUtility), "TransferNutrition")]

View File

@ -81,7 +81,7 @@
<Compile Include="RJWUtility.cs" /> <Compile Include="RJWUtility.cs" />
<Compile Include="SexHistory\HistoryUtility.cs" /> <Compile Include="SexHistory\HistoryUtility.cs" />
<Compile Include="SexHistory\SexPartnerHistory.cs" /> <Compile Include="SexHistory\SexPartnerHistory.cs" />
<Compile Include="SexHistory\SexHistory.cs" /> <Compile Include="SexHistory\SexPartnerHistoryRecord.cs" />
<Compile Include="PawnRelationWorkers.cs" /> <Compile Include="PawnRelationWorkers.cs" />
<Compile Include="Keyed.cs" /> <Compile Include="Keyed.cs" />
<Compile Include="Patches\Rimworld_Patch.cs" /> <Compile Include="Patches\Rimworld_Patch.cs" />

View File

@ -16,11 +16,6 @@ namespace RJWSexperience
{ {
public static class RJWUtility 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) public static bool RemoveVirginTrait(Pawn pawn, Pawn partner, SexProps props)
{ {
int degree; int degree;

View File

@ -13,7 +13,7 @@ namespace RJWSexperience
public SexPartnerHistory() { } public SexPartnerHistory() { }
public const int ARRLEN = 20; public const int ARRLEN = 20;
protected Dictionary<string, SexHistory> histories = new Dictionary<string, SexHistory>(); protected Dictionary<string, SexPartnerHistoryRecord> histories = new Dictionary<string, SexPartnerHistoryRecord>();
protected string first = ""; protected string first = "";
protected bool dirty = true; protected bool dirty = true;
protected xxx.rjwSextype recentsex = xxx.rjwSextype.None; protected xxx.rjwSextype recentsex = xxx.rjwSextype.None;
@ -46,7 +46,7 @@ namespace RJWSexperience
protected int mostsextickabscache = 0; protected int mostsextickabscache = 0;
protected int bestsextickabscache = 0; protected int bestsextickabscache = 0;
public SexHistory GetFirstPartnerHistory public SexPartnerHistoryRecord GetFirstPartnerHistory
{ {
get get
{ {
@ -54,7 +54,7 @@ namespace RJWSexperience
return histories.TryGetValue(first); return histories.TryGetValue(first);
} }
} }
public SexHistory GetMostPartnerHistory public SexPartnerHistoryRecord GetMostPartnerHistory
{ {
get get
{ {
@ -78,8 +78,8 @@ namespace RJWSexperience
return mostsatsextypecache; return mostsatsextypecache;
} }
} }
public SexHistory GetRecentPartnersHistory => histories.TryGetValue(recentpartner); public SexPartnerHistoryRecord GetRecentPartnersHistory => histories.TryGetValue(recentpartner);
public SexHistory GetBestSexPartnerHistory public SexPartnerHistoryRecord GetBestSexPartnerHistory
{ {
get get
{ {
@ -96,11 +96,11 @@ namespace RJWSexperience
} }
} }
public int VirginsTaken => virginstaken; public int VirginsTaken => virginstaken;
public List<SexHistory> PartnerList public List<SexPartnerHistoryRecord> PartnerList
{ {
get get
{ {
List<SexHistory> res = null; List<SexPartnerHistoryRecord> res = null;
Update(); Update();
if (!histories.NullOrEmpty()) if (!histories.NullOrEmpty())
{ {
@ -113,7 +113,7 @@ namespace RJWSexperience
{ {
get get
{ {
if (histories == null) histories = new Dictionary<string, SexHistory>(); if (histories == null) histories = new Dictionary<string, SexPartnerHistoryRecord>();
return histories.Count; return histories.Count;
} }
} }
@ -272,7 +272,7 @@ namespace RJWSexperience
Scribe_Collections.Look(ref sextypesatsave, "sextypesatsave", LookMode.Value); Scribe_Collections.Look(ref sextypesatsave, "sextypesatsave", LookMode.Value);
Scribe_Collections.Look(ref sextyperecenttickabssave, "sextyperecenttickabssave", LookMode.Value); Scribe_Collections.Look(ref sextyperecenttickabssave, "sextyperecenttickabssave", LookMode.Value);
if (histories == null) histories = new Dictionary<string, SexHistory>(); if (histories == null) histories = new Dictionary<string, SexPartnerHistoryRecord>();
if (Scribe.mode == LoadSaveMode.LoadingVars) if (Scribe.mode == LoadSaveMode.LoadingVars)
{ {
@ -280,7 +280,7 @@ namespace RJWSexperience
sextypesat = sextypesatsave?.ToArray() ?? new float[ARRLEN]; sextypesat = sextypesatsave?.ToArray() ?? new float[ARRLEN];
sextyperecenttickabs = sextyperecenttickabssave?.ToArray() ?? new int[ARRLEN]; sextyperecenttickabs = sextyperecenttickabssave?.ToArray() ?? new int[ARRLEN];
foreach (KeyValuePair<string, SexHistory> element in histories) foreach (KeyValuePair<string, SexPartnerHistoryRecord> element in histories)
{ {
element.Value.parent = this; element.Value.parent = this;
element.Value.partnerID = element.Key; element.Value.partnerID = element.Key;
@ -292,10 +292,9 @@ namespace RJWSexperience
public void RecordHistory(Pawn partner, SexProps props) public void RecordHistory(Pawn partner, SexProps props)
{ {
Pawn pawn = parent as Pawn; Pawn pawn = parent as Pawn;
TryAddHistory(partner); SexPartnerHistoryRecord history = GetPartnerRecord(partner);
RecordFirst(partner, props); RecordFirst(partner, props);
recentpartner = partner.ThingID; recentpartner = partner.ThingID;
SexHistory history = histories[partner.ThingID];
history?.RecordSex(props); history?.RecordSex(props);
recentsex = props.sexType; recentsex = props.sexType;
sextypecount[(int)props.sexType]++; sextypecount[(int)props.sexType]++;
@ -309,51 +308,48 @@ namespace RJWSexperience
public void RecordSatisfactionHistory(Pawn partner, SexProps props, float satisfaction) public void RecordSatisfactionHistory(Pawn partner, SexProps props, float satisfaction)
{ {
TryAddHistory(partner); SexPartnerHistoryRecord history = GetPartnerRecord(partner);
RecordFirst(partner, props); RecordFirst(partner, props);
SexHistory history = histories[partner.ThingID];
history?.RecordSatisfaction(props, satisfaction); history?.RecordSatisfaction(props, satisfaction);
recentsat = satisfaction; recentsat = satisfaction;
sextypesat[(int)props.sexType] += satisfaction; sextypesat[(int)props.sexType] += satisfaction;
dirty = true; 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)); return record;
histories.Add(partner.ThingID, newhistory);
Pawn pawn = parent as Pawn;
if (pawn != null)
{
pawn.records.AddTo(VariousDefOf.SexPartnerCount, 1);
}
return true;
} }
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) public void RecordFirst(Pawn partner, SexProps props)
{ {
if (VirginCheck() && props.sexType == xxx.rjwSextype.Vaginal) if (VirginCheck() && props.sexType == xxx.rjwSextype.Vaginal)
{ {
TryAddHistory(partner); GetPartnerRecord(partner);
first = partner.ThingID; first = partner.ThingID;
SexPartnerHistory history = partner.GetPartnerHistory(); SexPartnerHistory history = partner.GetPartnerHistory();
firstsextickabs = GenTicks.TicksAbs; firstsextickabs = GenTicks.TicksAbs;
if (history != null) history?.TakeSomeonesVirgin(parent as Pawn);
{
history.TakeSomeonesVirgin(parent as Pawn);
}
} }
} }
public void TakeSomeonesVirgin(Pawn partner) public void TakeSomeonesVirgin(Pawn partner)
{ {
TryAddHistory(partner); SexPartnerHistoryRecord partnerRecord = GetPartnerRecord(partner);
SexHistory history = histories[partner.ThingID]; partnerRecord?.TookVirgin();
if (history != null) history.TookVirgin();
virginstaken++; virginstaken++;
} }
@ -382,9 +378,9 @@ namespace RJWSexperience
Dictionary<ThingDef, int> racetotalsat = new Dictionary<ThingDef, int>(); Dictionary<ThingDef, int> racetotalsat = new Dictionary<ThingDef, int>();
List<Pawn> allpartners = new List<Pawn>(); List<Pawn> allpartners = new List<Pawn>();
foreach (KeyValuePair<string, SexHistory> element in histories) foreach (KeyValuePair<string, SexPartnerHistoryRecord> element in histories)
{ {
SexHistory h = element.Value; SexPartnerHistoryRecord h = element.Value;
//find most sex partner //find most sex partner
if (max < h.TotalSexCount) if (max < h.TotalSexCount)

View File

@ -11,7 +11,7 @@ using RJWSexperience.ExtensionMethods;
namespace RJWSexperience namespace RJWSexperience
{ {
public class SexHistory : IExposable public class SexPartnerHistoryRecord : IExposable
{ {
public SexPartnerHistory parent; public SexPartnerHistory parent;
public string partnerID; 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.partner = pawn;
this.namecache = pawn.Label; this.namecache = pawn.Label;
@ -184,25 +184,25 @@ namespace RJWSexperience
partner = Find.WorldPawns.AllPawnsAliveOrDead.FirstOrDefault(x => x.ThingID.Equals(partnerID)); partner = Find.WorldPawns.AllPawnsAliveOrDead.FirstOrDefault(x => x.ThingID.Equals(partnerID));
} }
public class RecentOrderComparer : IComparer<SexHistory> public class RecentOrderComparer : IComparer<SexPartnerHistoryRecord>
{ {
public int Compare(SexHistory x, SexHistory y) public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{ {
return y.RecentSexTickAbs.CompareTo(x.RecentSexTickAbs); return y.RecentSexTickAbs.CompareTo(x.RecentSexTickAbs);
} }
} }
public class MostOrderComparer : IComparer<SexHistory> public class MostOrderComparer : IComparer<SexPartnerHistoryRecord>
{ {
public int Compare(SexHistory x, SexHistory y) public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{ {
return y.TotalSexCount.CompareTo(x.TotalSexCount); return y.TotalSexCount.CompareTo(x.TotalSexCount);
} }
} }
public class NameOrderComparer : IComparer<SexHistory> public class NameOrderComparer : IComparer<SexPartnerHistoryRecord>
{ {
public int Compare(SexHistory x, SexHistory y) public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
{ {
return x.Label.CompareTo(y.Label); return x.Label.CompareTo(y.Label);
} }

View File

@ -2,6 +2,7 @@
using System; using System;
using UnityEngine; using UnityEngine;
using Verse; using Verse;
using System.Diagnostics.CodeAnalysis;
namespace RJWSexperience namespace RJWSexperience
{ {
@ -10,7 +11,8 @@ namespace RJWSexperience
/// </summary> /// </summary>
public class StatPart_Lust : StatPart 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) public override string ExplanationPart(StatRequest req)
{ {
@ -48,7 +50,8 @@ namespace RJWSexperience
/// </summary> /// </summary>
public class StatPart_Slave : StatPart 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) public override string ExplanationPart(StatRequest req)
{ {

View File

@ -58,10 +58,10 @@ namespace RJWSexperience.UI
protected Pawn pawn; protected Pawn pawn;
protected SexHistory selectedPawn; protected SexPartnerHistoryRecord selectedPawn;
protected SexPartnerHistory history; protected SexPartnerHistory history;
protected CompRJW rjwcomp; protected CompRJW rjwcomp;
protected List<SexHistory> partnerList; protected List<SexPartnerHistoryRecord> partnerList;
protected PartnerOrderMode orderMode; protected PartnerOrderMode orderMode;
private static GUIStyleState fontstylestate = new GUIStyleState() { textColor = Color.white }; private static GUIStyleState fontstylestate = new GUIStyleState() { textColor = Color.white };
@ -184,13 +184,13 @@ namespace RJWSexperience.UI
partnerList = history?.PartnerList; partnerList = history?.PartnerList;
break; break;
case PartnerOrderMode.Recent: case PartnerOrderMode.Recent:
partnerList.Sort(new SexHistory.RecentOrderComparer()); partnerList.Sort(new SexPartnerHistoryRecord.RecentOrderComparer());
break; break;
case PartnerOrderMode.Most: case PartnerOrderMode.Most:
partnerList.Sort(new SexHistory.MostOrderComparer()); partnerList.Sort(new SexPartnerHistoryRecord.MostOrderComparer());
break; break;
case PartnerOrderMode.Name: case PartnerOrderMode.Name:
partnerList.Sort(new SexHistory.NameOrderComparer()); partnerList.Sort(new SexPartnerHistoryRecord.NameOrderComparer());
break; 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); Widgets.DrawMenuSection(rect);
string str = tooltip; 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 labelRect = new Rect(rect.x, rect.y, rect.width, FONTHEIGHT);
Rect infoRect = new Rect(rect.x, rect.y + FONTHEIGHT, rect.width, rect.height - FONTHEIGHT); Rect infoRect = new Rect(rect.x, rect.y + FONTHEIGHT, rect.width, rect.height - FONTHEIGHT);
@ -579,7 +579,7 @@ namespace RJWSexperience.UI
listmain.End(); listmain.End();
} }
protected void DrawPartnerList(Rect rect, List<SexHistory> partnerList) protected void DrawPartnerList(Rect rect, List<SexPartnerHistoryRecord> partnerList)
{ {
Rect pawnRect = new Rect(rect.x, rect.y, LISTPAWNSIZE, LISTPAWNSIZE); Rect pawnRect = new Rect(rect.x, rect.y, LISTPAWNSIZE, LISTPAWNSIZE);
for (int i = 0; i < partnerList.Count; i++) 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) if (history != null)
{ {