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)
{
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<RjwSexperienceMod>().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")]

View file

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

View file

@ -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;

View file

@ -13,7 +13,7 @@ namespace RJWSexperience
public SexPartnerHistory() { }
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 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<SexHistory> PartnerList
public List<SexPartnerHistoryRecord> PartnerList
{
get
{
List<SexHistory> res = null;
List<SexPartnerHistoryRecord> res = null;
Update();
if (!histories.NullOrEmpty())
{
@ -113,7 +113,7 @@ namespace RJWSexperience
{
get
{
if (histories == null) histories = new Dictionary<string, SexHistory>();
if (histories == null) histories = new Dictionary<string, SexPartnerHistoryRecord>();
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<string, SexHistory>();
if (histories == null) histories = new Dictionary<string, SexPartnerHistoryRecord>();
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<string, SexHistory> element in histories)
foreach (KeyValuePair<string, SexPartnerHistoryRecord> 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<ThingDef, int> racetotalsat = new Dictionary<ThingDef, int>();
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
if (max < h.TotalSexCount)

View file

@ -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<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);
}
}
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);
}
}
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);
}

View file

@ -2,6 +2,7 @@
using System;
using UnityEngine;
using Verse;
using System.Diagnostics.CodeAnalysis;
namespace RJWSexperience
{
@ -10,7 +11,8 @@ namespace RJWSexperience
/// </summary>
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
/// </summary>
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)
{

View file

@ -58,10 +58,10 @@ namespace RJWSexperience.UI
protected Pawn pawn;
protected SexHistory selectedPawn;
protected SexPartnerHistoryRecord selectedPawn;
protected SexPartnerHistory history;
protected CompRJW rjwcomp;
protected List<SexHistory> partnerList;
protected List<SexPartnerHistoryRecord> 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<SexHistory> partnerList)
protected void DrawPartnerList(Rect rect, List<SexPartnerHistoryRecord> 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)
{