Refactor SexPartnerHistoryRecord

This commit is contained in:
amevarashi 2022-05-11 20:37:14 +05:00
parent e8211a1f3b
commit 803105d64b
3 changed files with 65 additions and 114 deletions

View File

@ -17,18 +17,6 @@ namespace RJWSexperience.ExtensionMethods
} }
} }
public static Pawn GetInteractionRecipient(this SexProps props)
{
if (props.isReceiver)
{
return props.pawn;
}
else
{
return props.partner;
}
}
public static bool IsBestiality(this SexProps props) public static bool IsBestiality(this SexProps props)
{ {
if (props.partner != null) if (props.partner != null)

View File

@ -1,8 +1,6 @@
using RimWorld; using rjw;
using rjw;
using RJWSexperience.ExtensionMethods; using RJWSexperience.ExtensionMethods;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Verse; using Verse;
namespace RJWSexperience namespace RJWSexperience
@ -12,53 +10,31 @@ namespace RJWSexperience
public string PartnerID { get; set; } public string PartnerID { get; set; }
protected Pawn partner = null; protected Pawn partner = null;
protected string namecache; protected string labelCache;
protected int totalsexhad = 0; protected int totalSexCount = 0;
protected int raped = 0; protected int raped = 0;
protected int rapedme = 0; protected int rapedMe = 0;
protected int orgasms = 0; protected int orgasms = 0;
protected xxx.rjwSextype bestsextype = xxx.rjwSextype.None; protected xxx.rjwSextype bestSextype = xxx.rjwSextype.None;
protected float bestsatisfaction = 0; protected float bestSatisfaction = 0;
protected bool itookvirgin = false; protected bool iTookVirgin = false;
protected bool incest = false; protected bool incest = false;
protected int recentsextickabs = 0; protected int recentSexTickAbs = 0;
protected int bestsextickabs = 0; protected int bestSexTickAbs = 0;
protected bool cannotLoadPawnData = false; protected bool cannotLoadPawnData = false;
protected ThingDef race; protected ThingDef raceCache;
public string Label public xxx.rjwSextype BestSextype => bestSextype;
{ public float BestSatisfaction => bestSatisfaction;
get public int TotalSexCount => totalSexCount;
{ public int OrgasmCount => orgasms;
if (partner != null) public bool IamFirst => iTookVirgin;
{ public bool Incest => incest;
namecache = partner.Label; public int Raped => raped;
return namecache; public int RapedMe => rapedMe;
} public int RecentSexTickAbs => recentSexTickAbs;
else return namecache; public int BestSexTickAbs => bestSexTickAbs;
} public int BestSexElapsedTicks => GenTicks.TicksAbs - bestSexTickAbs;
}
public xxx.rjwSextype BestSextype
{
get
{
return bestsextype;
}
}
public float BestSatisfaction
{
get
{
return bestsatisfaction;
}
}
public int TotalSexCount
{
get
{
return totalsexhad;
}
}
public Pawn Partner public Pawn Partner
{ {
get get
@ -71,30 +47,13 @@ namespace RJWSexperience
return partner; return partner;
} }
} }
public string RapeInfo public string Label
{ {
get get
{ {
string res = ""; if (Partner != null)
if (raped > 0) res += Keyed.RS_Raped + raped + " "; labelCache = Partner.Label;
if (rapedme > 0) res += Keyed.RS_RapedMe + rapedme + " "; return labelCache;
return res;
}
}
public int OrgasmCount => orgasms;
public bool IamFirst => itookvirgin;
public bool Incest => incest;
public int Raped => raped;
public int RapedMe => rapedme;
public int RecentSexTickAbs => recentsextickabs;
public int BestSexTickAbs => bestsextickabs;
public int BestSexElapsedTicks => GenTicks.TicksAbs - bestsextickabs;
public string BestSexDays
{
get
{
if (bestsextickabs != 0) return Keyed.RS_HadBestSexDaysAgo(GenDate.ToStringTicksToDays(BestSexElapsedTicks) + " " + Keyed.RS_Ago);
return "";
} }
} }
public ThingDef Race public ThingDef Race
@ -102,11 +61,8 @@ namespace RJWSexperience
get get
{ {
if (Partner != null) if (Partner != null)
{ raceCache = Partner.def;
race = Partner.def; return raceCache;
return race;
}
else return race;
} }
} }
@ -115,70 +71,69 @@ namespace RJWSexperience
public SexPartnerHistoryRecord(Pawn pawn, bool incest = false) public SexPartnerHistoryRecord(Pawn pawn, bool incest = false)
{ {
this.partner = pawn; this.partner = pawn;
this.namecache = pawn.Label; this.labelCache = pawn.Label;
this.incest = incest; this.incest = incest;
this.race = pawn.def; this.raceCache = pawn.def;
} }
public void ExposeData() public void ExposeData()
{ {
Scribe_Values.Look(ref namecache, "namecache"); Scribe_Values.Look(ref labelCache, "namecache");
Scribe_Values.Look(ref totalsexhad, "totalsexhad", 0); Scribe_Values.Look(ref totalSexCount, "totalsexhad", 0);
Scribe_Values.Look(ref raped, "raped", 0); Scribe_Values.Look(ref raped, "raped", 0);
Scribe_Values.Look(ref rapedme, "rapedme", 0); Scribe_Values.Look(ref rapedMe, "rapedme", 0);
Scribe_Values.Look(ref orgasms, "orgasms", 0); Scribe_Values.Look(ref orgasms, "orgasms", 0);
Scribe_Values.Look(ref bestsextype, "bestsextype", xxx.rjwSextype.None); Scribe_Values.Look(ref bestSextype, "bestsextype", xxx.rjwSextype.None);
Scribe_Values.Look(ref bestsatisfaction, "bestsatisfaction", 0f); Scribe_Values.Look(ref bestSatisfaction, "bestsatisfaction", 0f);
Scribe_Values.Look(ref itookvirgin, "itookvirgin", false); Scribe_Values.Look(ref iTookVirgin, "itookvirgin", false);
Scribe_Values.Look(ref incest, "incest", false); Scribe_Values.Look(ref incest, "incest", false);
Scribe_Values.Look(ref recentsextickabs, "recentsextickabs", 0); Scribe_Values.Look(ref recentSexTickAbs, "recentsextickabs", 0);
Scribe_Values.Look(ref bestsextickabs, "bestsextickabs", 0); Scribe_Values.Look(ref bestSexTickAbs, "bestsextickabs", 0);
Scribe_Defs.Look(ref race, "race"); Scribe_Defs.Look(ref raceCache, "race");
} }
public void RecordSex(SexProps props) public void RecordSex(SexProps props)
{ {
totalsexhad++; totalSexCount++;
if (props.isRape) if (props.isRape)
{ {
if (partner == props.GetInteractionInitiator()) if (partner == props.GetInteractionInitiator())
{ rapedMe++;
rapedme++; else
}
else if (partner == props.GetInteractionRecipient())
{
raped++; raped++;
}
} }
recentsextickabs = GenTicks.TicksAbs; recentSexTickAbs = GenTicks.TicksAbs;
} }
public void RecordSatisfaction(SexProps props, float satisfaction) public void RecordSatisfaction(SexProps props, float satisfaction)
{ {
if (satisfaction > bestsatisfaction) orgasms++;
if (satisfaction > bestSatisfaction)
{ {
orgasms++; bestSextype = props.sexType;
bestsextype = props.sexType; bestSatisfaction = satisfaction;
bestsatisfaction = satisfaction; bestSexTickAbs = GenTicks.TicksAbs;
bestsextickabs = GenTicks.TicksAbs;
} }
} }
public void TookVirgin() public void TookVirgin()
{ {
itookvirgin = true; iTookVirgin = true;
} }
protected void LoadPartnerPawn(string partnerID) protected void LoadPartnerPawn(string partnerID)
{ {
foreach (Map map in Find.Maps) foreach (Map map in Find.Maps)
{ {
partner = map.mapPawns.AllPawns.FirstOrDefault(x => x.ThingID.Equals(partnerID)); partner = map.mapPawns.AllPawns.Find(x => x.ThingID.Equals(partnerID));
if (partner != null) return; if (partner != null) return;
} }
partner = Find.WorldPawns.AllPawnsAliveOrDead.FirstOrDefault(x => x.ThingID.Equals(partnerID)); partner = Find.WorldPawns.AllPawnsAliveOrDead.Find(x => x.ThingID.Equals(partnerID));
} }
#region OrderComparers
public class RecentOrderComparer : IComparer<SexPartnerHistoryRecord> public class RecentOrderComparer : IComparer<SexPartnerHistoryRecord>
{ {
public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y) public int Compare(SexPartnerHistoryRecord x, SexPartnerHistoryRecord y)
@ -202,6 +157,7 @@ namespace RJWSexperience
return x.Label.CompareTo(y.Label); return x.Label.CompareTo(y.Label);
} }
} }
}
#endregion OrderComparers
}
} }

View File

@ -239,15 +239,22 @@ namespace RJWSexperience.UI
SoundDefOf.ClickReject.PlayOneShotOnCamera(); SoundDefOf.ClickReject.PlayOneShotOnCamera();
} }
} }
string rapeInfo = "";
if (history.Raped > 0) rapeInfo += Keyed.RS_Raped + history.Raped + " ";
if (history.RapedMe > 0) rapeInfo += Keyed.RS_RapedMe + history.RapedMe;
GUI.Label(nameRect, partner?.Name?.ToStringFull ?? history.Label.CapitalizeFirst(), fontstyleleft); GUI.Label(nameRect, partner?.Name?.ToStringFull ?? history.Label.CapitalizeFirst(), fontstyleleft);
GUI.Label(sexinfoRect, Keyed.RS_Sex_Count + history.TotalSexCount + " " + history.RapeInfo, fontstyleleft); GUI.Label(sexinfoRect, Keyed.RS_Sex_Count + history.TotalSexCount + " " + rapeInfo, fontstyleleft);
GUI.Label(sexinfoRect2, Keyed.RS_Orgasms + history.OrgasmCount, fontstyleleft); GUI.Label(sexinfoRect2, Keyed.RS_Orgasms + history.OrgasmCount, fontstyleleft);
GUI.Label(sexinfoRect2, pawn.GetRelationsString(partner) + " ", fontstyleright); GUI.Label(sexinfoRect2, pawn.GetRelationsString(partner) + " ", fontstyleright);
float p = history.BestSatisfaction / BASESAT; float p = history.BestSatisfaction / BASESAT;
FillableBarLabeled(bestsexRect, String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)history.BestSextype]), p / 2, HistoryUtility.SextypeColor[(int)history.BestSextype], Texture2D.blackTexture, null, String.Format("{0:P2}", p)); FillableBarLabeled(bestsexRect, String.Format(Keyed.RS_Best_Sextype + ": {0}", Keyed.Sextype[(int)history.BestSextype]), p / 2, HistoryUtility.SextypeColor[(int)history.BestSextype], Texture2D.blackTexture, null, String.Format("{0:P2}", p));
if (history.IamFirst) str += "\n" + Keyed.RS_LostVirgin(history.Label, pawn.LabelShort); if (history.IamFirst)
str += "\n" + history.BestSexDays; str += "\n" + Keyed.RS_LostVirgin(history.Label, pawn.LabelShort);
if (history.BestSexTickAbs != 0)
str += "\n" + Keyed.RS_HadBestSexDaysAgo(history.BestSexElapsedTicks.ToStringTicksToDays() + " " + Keyed.RS_Ago);
TooltipHandler.TipRegion(rect, str); TooltipHandler.TipRegion(rect, str);
} }