From b4231341fffc3079685ffffe65ff2320a8ff92c3 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Fri, 20 May 2022 21:25:56 +0500 Subject: [PATCH] Refactor StatParts --- Languages/English/Keyed/RJW_Sexperience.xml | 6 -- Patches/RJW_StatDefs.xml | 4 +- RJWSexperience/RJWSexperience/Keyed.cs | 10 +-- RJWSexperience/RJWSexperience/LustUtility.cs | 75 +++++++++++++++++++ .../RJWSexperience/RJWSexperience.csproj | 1 + .../SexHistory/RecordRandomizer.cs | 4 +- RJWSexperience/RJWSexperience/StatParts.cs | 28 ++----- 7 files changed, 87 insertions(+), 41 deletions(-) create mode 100644 RJWSexperience/RJWSexperience/LustUtility.cs diff --git a/Languages/English/Keyed/RJW_Sexperience.xml b/Languages/English/Keyed/RJW_Sexperience.xml index fb7b50b..8b08c9d 100644 --- a/Languages/English/Keyed/RJW_Sexperience.xml +++ b/Languages/English/Keyed/RJW_Sexperience.xml @@ -3,9 +3,6 @@ RJW Sexperience - Lust: x{0}% - Slave: x{0}% - Not Slave: x100% Meme: x{0}% slave, prisoner, submissive gender only improper animal: cannot breed or forbidden by precepts @@ -14,7 +11,6 @@ capable of sex is required Total gathered cum: {1} took {0}'s virginity. - Gather cums on body Best sextype Recent sextype Sex partners @@ -33,7 +29,6 @@ Best Sex Partner The partner who had most satisfying sex. Taken virgins - The number of partners who i taken first. Total sex had Total number of sex. Raped: @@ -49,7 +44,6 @@ Interspecies Normal Necrophile - Gather cum Sex skill Cum addiction Addicted to cum. diff --git a/Patches/RJW_StatDefs.xml b/Patches/RJW_StatDefs.xml index 300594e..848165a 100644 --- a/Patches/RJW_StatDefs.xml +++ b/Patches/RJW_StatDefs.xml @@ -25,9 +25,7 @@ Defs/StatDef[defName="SexFrequency"]/parts -
  • - 1.0 -
  • +
  • diff --git a/RJWSexperience/RJWSexperience/Keyed.cs b/RJWSexperience/RJWSexperience/Keyed.cs index ef57960..76f7ba9 100644 --- a/RJWSexperience/RJWSexperience/Keyed.cs +++ b/RJWSexperience/RJWSexperience/Keyed.cs @@ -1,4 +1,5 @@ -using rjw; +using RimWorld; +using rjw; using RJWSexperience.UI; using UnityEngine; using Verse; @@ -7,17 +8,13 @@ namespace RJWSexperience { public static class Keyed { - public static string LustStatFactor(string value) => "LustStatFactor".Translate(value); - public static string SlaveStatFactor(string value) => "SlaveStatFactor".Translate(value); public static string RS_LostVirgin(string pawn, string partner) => "RS_LostVirgin".Translate(pawn.Colorize(Color.yellow), partner.Colorize(Color.yellow)); public static string RS_Sex_Info(string sextype, string sexcount) => "RS_Sex_Info".Translate(sextype, sexcount); public static string RS_SAT_AVG(string avgsat) => "RS_SAT_AVG".Translate(avgsat); public static string RS_HadBestSexDaysAgo(string days) => "RS_HadBestSexDaysAgo".Translate(days); public static readonly string Mod_Title = "RS_Mod_Title".Translate(); - public static readonly string SlaveStatFactorDefault = "SlaveStatFactorDefault".Translate(); public static readonly string RSTotalGatheredCum = "RSTotalGatheredCum".Translate(); - public static readonly string RS_FloatMenu_CleanSelf = "RS_FloatMenu_CleanSelf".Translate(); public static readonly string RS_Best_Sextype = "RS_Best_Sextype".Translate(); public static readonly string RS_Recent_Sextype = "RS_Recent_Sextype".Translate(); public static readonly string RS_Sex_Partners = "RS_Sex_Partners".Translate(); @@ -35,7 +32,6 @@ namespace RJWSexperience public static readonly string RS_First_Sex_Partner_ToolTip = "RS_First_Sex_Partner_ToolTip".Translate(); public static readonly string RS_Most_Sex_Partner_ToolTip = "RS_Most_Sex_Partner_ToolTip".Translate(); public static readonly string RS_Best_Sex_Partner_ToolTip = "RS_Best_Sex_Partner_ToolTip".Translate(); - public static readonly string RS_VirginsTaken_ToolTip = "RS_VirginsTaken_ToolTip".Translate(); public static readonly string RS_Raped = "RS_Raped".Translate(); public static readonly string RS_RapedMe = "RS_RapedMe".Translate(); public static readonly string RS_Sex_History = "RS_Sex_History".Translate(); @@ -53,7 +49,6 @@ namespace RJWSexperience public static readonly string RS_Bestiality = "RS_Bestiality".Translate(); public static readonly string RS_Interspecies = "RS_Interspecies".Translate(); public static readonly string RS_Necrophile = "RS_Necrophile".Translate(); - public static readonly string RS_GatherCum = "RS_GatherCum".Translate(); public static readonly string RS_SexSkill = "RS_SexSkill".Translate(); public static readonly string RS_CumAddiction = "RS_CumAddiction".Translate(); public static readonly string RS_CumAddiction_Tooltip = "RS_CumAddiction_Tooltip".Translate(); @@ -62,6 +57,7 @@ namespace RJWSexperience public static readonly string RS_NumofTimes = "RS_NumofTimes".Translate(); public static readonly string RS_Ago = "RS_Ago".Translate(); public static readonly string RS_LastSex = "RS_LastSex".Translate(); + [MayRequireRoyalty] public static readonly string Slave = "Slave".Translate(); public static readonly string TabLabelMain = "TabLabelMain".Translate(); public static readonly string TabLabelHistory = "TabLabelHistory".Translate(); diff --git a/RJWSexperience/RJWSexperience/LustUtility.cs b/RJWSexperience/RJWSexperience/LustUtility.cs new file mode 100644 index 0000000..7c3cd3f --- /dev/null +++ b/RJWSexperience/RJWSexperience/LustUtility.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Verse; + +namespace RJWSexperience +{ + public static class LustUtility + { + /// + /// ~0.023. + /// No need to calculate this every call + /// + private static readonly float magicNum1 = Mathf.Log(10f) / 100; + + /// + /// Transforms lust value into a stat multiplier + /// + /// + /// Positive value + public static float GetLustFactor(float lust) + { + float effectiveLust = lust * SexperienceMod.Settings.LustEffectPower; + if (effectiveLust < 0) + { + effectiveLust = Mathf.Exp((effectiveLust + 200f) * magicNum1) - 100f; + } + else + { + effectiveLust = Mathf.Sqrt((effectiveLust + 25f) * 100f) - 50f; + } + + return 1 + (effectiveLust / 100f); + } + + public static void DrawGraph(Rect graphRect) + { + List curves = new List(); + FloatRange lustRange = new FloatRange(-300f, 300f); + + SimpleCurveDrawInfo simpleCurveDrawInfo = new SimpleCurveDrawInfo + { + color = Color.yellow, + label = "Sex freq mult", + valueFormat = "x{0}", + curve = new SimpleCurve() + }; + for (float lust = lustRange.min; lust <= lustRange.max; lust++) + { + simpleCurveDrawInfo.curve.Add(new CurvePoint(lust, GetLustFactor(lust)), false); + } + + curves.Add(simpleCurveDrawInfo); + + SimpleCurveDrawerStyle curveDrawerStyle = new SimpleCurveDrawerStyle + { + UseFixedSection = true, + FixedSection = lustRange, + UseFixedScale = true, + FixedScale = new Vector2(0f, GetLustFactor(lustRange.max)), + DrawPoints = false, + DrawBackgroundLines = true, + DrawCurveMousePoint = true, + DrawMeasures = true, + MeasureLabelsXCount = 8, + MeasureLabelsYCount = 3, + XIntegersOnly = true, + YIntegersOnly = false, + LabelX = Keyed.Lust + }; + SimpleCurveDrawer.DrawCurves(graphRect, curves, curveDrawerStyle); + } + } +} diff --git a/RJWSexperience/RJWSexperience/RJWSexperience.csproj b/RJWSexperience/RJWSexperience/RJWSexperience.csproj index a0b8917..dc5df92 100644 --- a/RJWSexperience/RJWSexperience/RJWSexperience.csproj +++ b/RJWSexperience/RJWSexperience/RJWSexperience.csproj @@ -59,6 +59,7 @@ + diff --git a/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs b/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs index ee8aa01..8c16176 100644 --- a/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs +++ b/RJWSexperience/RJWSexperience/SexHistory/RecordRandomizer.cs @@ -19,7 +19,7 @@ namespace RJWSexperience int deviation = (int)Settings.MaxSexCountDeviation; if (pawn.story != null) { - _ = RandomizeLust(pawn); + float lust = RandomizeLust(pawn); int sexableage = 0; int minsexage = 0; @@ -31,7 +31,7 @@ namespace RJWSexperience if (pawn.ageTracker.AgeBiologicalYears > minsexage) { sexableage = pawn.ageTracker.AgeBiologicalYears - minsexage; - avgsex = (int)(sexableage * Settings.SexPerYear * StatPart_Lust.GetLustFactor(pawn)); + avgsex = (int)(sexableage * Settings.SexPerYear * LustUtility.GetLustFactor(lust)); } if (pawn.relations != null && pawn.gender == Gender.Female) diff --git a/RJWSexperience/RJWSexperience/StatParts.cs b/RJWSexperience/RJWSexperience/StatParts.cs index 969861f..eafdc43 100644 --- a/RJWSexperience/RJWSexperience/StatParts.cs +++ b/RJWSexperience/RJWSexperience/StatParts.cs @@ -1,6 +1,4 @@ using RimWorld; -using System; -using UnityEngine; using Verse; using System.Diagnostics.CodeAnalysis; @@ -11,14 +9,11 @@ namespace RJWSexperience /// public class StatPart_Lust : StatPart { - [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) { if (req.HasThing && (req.Thing is Pawn pawn)) { - return Keyed.LustStatFactor(String.Format("{0:0.##}", GetLustFactor(pawn) * factor * 100)); + return $"{Keyed.Lust.CapitalizeFirst()}: x{GetLustFactor(pawn).ToStringPercent()}"; } return null; } @@ -26,23 +21,10 @@ namespace RJWSexperience public override void TransformValue(StatRequest req, ref float val) { if (req.HasThing && (req.Thing is Pawn pawn)) - val *= GetLustFactor(pawn) * factor; + val *= GetLustFactor(pawn); } - public static float GetLustFactor(Pawn pawn) - { - float lust = pawn.records.GetValue(VariousDefOf.Lust) * SexperienceMod.Settings.LustEffectPower; - if (lust < 0) - { - lust = Mathf.Exp((lust + 200f * Mathf.Log(10f)) / 100f) - 100f; - } - else - { - lust = Mathf.Sqrt(100f * (lust + 25f)) - 50f; - } - - return 1 + lust / 100f; - } + protected float GetLustFactor(Pawn pawn) => LustUtility.GetLustFactor(pawn.records.GetValue(VariousDefOf.Lust)); } /// @@ -57,9 +39,9 @@ namespace RJWSexperience { if (req.HasThing && ((req.Thing as Pawn)?.IsSlave == true)) { - return Keyed.SlaveStatFactor(String.Format("{0:0.##}", factor * 100)); + return $"{Keyed.Slave.CapitalizeFirst()}: x{factor.ToStringPercent()}"; } - return Keyed.SlaveStatFactorDefault; + return null; } public override void TransformValue(StatRequest req, ref float val)