Refactor StatParts

This commit is contained in:
amevarashi 2022-05-20 21:25:56 +05:00
parent 257d86a416
commit b4231341ff
7 changed files with 87 additions and 41 deletions

View file

@ -3,9 +3,6 @@
<RS_Mod_Title>RJW Sexperience</RS_Mod_Title>
<!-- Sex status screen -->
<LustStatFactor>Lust: x{0}%</LustStatFactor>
<SlaveStatFactor>Slave: x{0}%</SlaveStatFactor>
<SlaveStatFactorDefault>Not Slave: x100%</SlaveStatFactorDefault>
<MemeStatFactor>Meme: x{0}%</MemeStatFactor>
<RSVictimCondition>slave, prisoner, submissive gender only</RSVictimCondition>
<RSBreederCondition>improper animal: cannot breed or forbidden by precepts</RSBreederCondition>
@ -14,7 +11,6 @@
<RSShouldCanFuck>capable of sex is required</RSShouldCanFuck>
<RSTotalGatheredCum>Total gathered cum: </RSTotalGatheredCum>
<RS_LostVirgin>{1} took {0}'s virginity.</RS_LostVirgin>
<RS_FloatMenu_CleanSelf>Gather cums on body</RS_FloatMenu_CleanSelf>
<RS_Best_Sextype>Best sextype</RS_Best_Sextype>
<RS_Recent_Sextype>Recent sextype</RS_Recent_Sextype>
<RS_Sex_Partners>Sex partners</RS_Sex_Partners>
@ -33,7 +29,6 @@
<RS_Best_Sex_Partner>Best Sex Partner</RS_Best_Sex_Partner>
<RS_Best_Sex_Partner_ToolTip>The partner who had most satisfying sex.</RS_Best_Sex_Partner_ToolTip>
<RS_VirginsTaken>Taken virgins</RS_VirginsTaken>
<RS_VirginsTaken_ToolTip>The number of partners who i taken first.</RS_VirginsTaken_ToolTip>
<RS_TotalSexHad>Total sex had</RS_TotalSexHad>
<RS_TotalSexHad_ToolTip>Total number of sex.</RS_TotalSexHad_ToolTip>
<RS_Raped>Raped: </RS_Raped>
@ -49,7 +44,6 @@
<RS_Interspecies>Interspecies</RS_Interspecies>
<RS_Normal>Normal</RS_Normal>
<RS_Necrophile>Necrophile</RS_Necrophile>
<RS_GatherCum>Gather cum</RS_GatherCum>
<RS_SexSkill>Sex skill</RS_SexSkill>
<RS_CumAddiction>Cum addiction</RS_CumAddiction>
<RS_CumAddiction_Tooltip>Addicted to cum.</RS_CumAddiction_Tooltip>

View file

@ -25,9 +25,7 @@
<Operation Class="PatchOperationAdd">
<xpath>Defs/StatDef[defName="SexFrequency"]/parts</xpath>
<value>
<li Class="RJWSexperience.StatPart_Lust">
<factor>1.0</factor>
</li>
<li Class="RJWSexperience.StatPart_Lust" />
</value>
</Operation>

View file

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

View file

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Verse;
namespace RJWSexperience
{
public static class LustUtility
{
/// <summary>
/// ~0.023.
/// No need to calculate this every call
/// </summary>
private static readonly float magicNum1 = Mathf.Log(10f) / 100;
/// <summary>
/// Transforms lust value into a stat multiplier
/// </summary>
/// <param name="lust"></param>
/// <returns>Positive value</returns>
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<SimpleCurveDrawInfo> curves = new List<SimpleCurveDrawInfo>();
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);
}
}
}

View file

@ -59,6 +59,7 @@
<Compile Include="Cum\JobDriver_CleanSelfWithBucket.cs" />
<Compile Include="Logs\DebugLogProvider.cs" />
<Compile Include="Logs\LogManager.cs" />
<Compile Include="LustUtility.cs" />
<Compile Include="Patches\DefInjection.cs" />
<Compile Include="Patches\GetGizmos.cs" />
<Compile Include="Recipe_HymenSurgery.cs" />

View file

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

View file

@ -1,6 +1,4 @@
using RimWorld;
using System;
using UnityEngine;
using Verse;
using System.Diagnostics.CodeAnalysis;
@ -11,14 +9,11 @@ namespace RJWSexperience
/// </summary>
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));
}
/// <summary>
@ -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)