Implement PreceptComp_UnwillingToDo for sextype precepts

This commit is contained in:
amevarashi 2022-06-23 21:47:05 +05:00
parent b5e1dcc38b
commit df9c39e0a7
6 changed files with 154 additions and 107 deletions

View file

@ -0,0 +1,13 @@
using rjw;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology
{
public class HistoryEventDefExtension_AssociatedSextypes : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<xxx.rjwSextype> sextypes = new List<xxx.rjwSextype>();
}
}

View file

@ -1,9 +1,12 @@
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience.Ideology
{
[StaticConstructorOnStartup]
public static class IdeoUtility
{
public static bool IsSubmissive(this Pawn pawn)
@ -73,5 +76,38 @@ namespace RJWSexperience.Ideology
}
return finalMultiplier;
}
public static HistoryEventDef GetSextypeEventDef(xxx.rjwSextype sextype)
{
if (historyEventBySextype.TryGetValue(sextype, out HistoryEventDef historyEventDef))
return historyEventDef;
return null;
}
public static HistoryEventDef GetSextypeEventDef(string sextype)
{
if (!Enum.TryParse(sextype, out xxx.rjwSextype rjwSextype))
return null;
return GetSextypeEventDef(rjwSextype);
}
private static readonly Dictionary<xxx.rjwSextype, HistoryEventDef> historyEventBySextype = BuildHistoryEventBySextype();
private static Dictionary<xxx.rjwSextype, HistoryEventDef> BuildHistoryEventBySextype()
{
Dictionary<xxx.rjwSextype, HistoryEventDef> dictionary = new Dictionary<xxx.rjwSextype, HistoryEventDef>();
foreach (HistoryEventDef historyEventDef in DefDatabase<HistoryEventDef>.AllDefsListForReading)
{
HistoryEventDefExtension_AssociatedSextypes associatedSextypes = historyEventDef.GetModExtension<HistoryEventDefExtension_AssociatedSextypes>();
if (associatedSextypes == null)
continue;
foreach (xxx.rjwSextype sextype in associatedSextypes.sextypes)
{
if (!dictionary.TryAdd(sextype, historyEventDef))
Log.Error($"[Sexperience.Ideology] Error in HistoryEventDef {historyEventDef.defName}: {sextype} sextype is already associated with {dictionary[sextype].defName} HistoryEventDef");
}
}
return dictionary;
}
}
}

View file

@ -157,7 +157,7 @@ namespace RJWSexperience.Ideology.Patches
}
else
{
HistoryEventDef sexevent = GetSexHistoryDef(sextype);
HistoryEventDef sexevent = IdeoUtility.GetSextypeEventDef(sextype);
if (sexevent != null)
{
Find.HistoryEventsManager.RecordEvent(sexevent.TaggedEvent(human, tag + HETag.Gender(human), partner));
@ -177,44 +177,6 @@ namespace RJWSexperience.Ideology.Patches
else suppression.CurLevel += 0.05f;
}
}
/// <summary>
/// only for non-violate human sex
/// </summary>
/// <param name="sextype"></param>
/// <returns></returns>
public static HistoryEventDef GetSexHistoryDef(xxx.rjwSextype sextype)
{
switch (sextype)
{
case xxx.rjwSextype.None:
case xxx.rjwSextype.MechImplant:
default:
return null;
case xxx.rjwSextype.Vaginal:
return VariousDefOf.VaginalSex;
case xxx.rjwSextype.Anal:
case xxx.rjwSextype.Rimming:
return VariousDefOf.AnalSex;
case xxx.rjwSextype.Oral:
case xxx.rjwSextype.Fellatio:
case xxx.rjwSextype.Cunnilingus:
return VariousDefOf.OralSex;
case xxx.rjwSextype.Masturbation:
case xxx.rjwSextype.Boobjob:
case xxx.rjwSextype.Handjob:
case xxx.rjwSextype.Footjob:
case xxx.rjwSextype.Fingering:
case xxx.rjwSextype.MutualMasturbation:
return VariousDefOf.MiscSex;
case xxx.rjwSextype.DoublePenetration:
case xxx.rjwSextype.Scissoring:
case xxx.rjwSextype.Fisting:
case xxx.rjwSextype.Sixtynine:
return VariousDefOf.PromiscuousSex;
}
}
}
/// <summary>
@ -236,14 +198,12 @@ namespace RJWSexperience.Ideology.Patches
public static float PreceptSextype(Ideo ideo, float sexdrive, float score, InteractionWithExtension interaction)
{
for (int i = 0; i < ideo.PreceptsListForReading.Count; i++)
{
if (ideo.PreceptsListForReading[i].def.GetModExtension<DefExtension_PreferSextype>()?.HasSextype(interaction.Extension.rjwSextype) == true)
HistoryEventDef sexEventDef = IdeoUtility.GetSextypeEventDef(interaction.Extension.rjwSextype);
if (sexEventDef != null && ideo.MemberWillingToDo(new HistoryEvent(sexEventDef)))
{
float mult = 8.0f * Math.Max(0.3f, 1 / Math.Max(0.01f, sexdrive));
return score * mult;
}
}
return score;
}
}

View file

@ -1,21 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology.Precepts
{
public class DefExtension_PreferSextype : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<string> sextypes = new List<string>();
private HashSet<string> sextypesHashSet;
public bool HasSextype(string sextype)
{
if (sextypesHashSet == null)
sextypesHashSet = new HashSet<string>(sextypes);
return sextypesHashSet.Contains(sextype);
}
}
}

View file

@ -43,6 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Ideology\HistoryEventDefExtension_AssociatedSextypes.cs" />
<Compile Include="Ideology\GoodwillSituationWorker_MemeCompatibility.cs" />
<Compile Include="Harmony.cs" />
<Compile Include="Ideology\HETag.cs" />
@ -56,7 +57,6 @@
<Compile Include="Ideology\Precepts\DefExtension_ModifyNecroMtb.cs" />
<Compile Include="Ideology\Precepts\DefExtension_ModifyBestialityMtb.cs" />
<Compile Include="Ideology\Precepts\DefExtension_ModifyPreference.cs" />
<Compile Include="Ideology\Precepts\DefExtension_PreferSextype.cs" />
<Compile Include="Ideology\Precepts\DefExtension_MultipleMemesRequired.cs" />
<Compile Include="Ideology\Precepts\PreceptComp_KnowsMemoryThoughtTagged.cs" />
<Compile Include="Ideology\Rituals\JobGiver_GangbangConsensual.cs" />

View file

@ -11,29 +11,74 @@
<HistoryEventDef>
<defName>VaginalSex</defName>
<label>vaginal sex</label>
<modExtensions>
<li Class="RJWSexperience.Ideology.HistoryEventDefExtension_AssociatedSextypes">
<sextypes>
<li>Vaginal</li>
</sextypes>
</li>
</modExtensions>
</HistoryEventDef>
<HistoryEventDef>
<defName>AnalSex</defName>
<label>anal sex</label>
<modExtensions>
<li Class="RJWSexperience.Ideology.HistoryEventDefExtension_AssociatedSextypes">
<sextypes>
<li>Anal</li>
<li>Rimming</li>
</sextypes>
</li>
</modExtensions>
</HistoryEventDef>
<HistoryEventDef>
<defName>OralSex</defName>
<label>oral sex</label>
</HistoryEventDef>
<HistoryEventDef>
<defName>MiscSex</defName>
<label>sex</label>
<modExtensions>
<li Class="RJWSexperience.Ideology.HistoryEventDefExtension_AssociatedSextypes">
<sextypes>
<li>Cunnilingus</li>
<li>Fellatio</li>
</sextypes>
</li>
</modExtensions>
</HistoryEventDef>
<HistoryEventDef>
<defName>PromiscuousSex</defName>
<label>promiscuous sex</label>
<modExtensions>
<li Class="RJWSexperience.Ideology.HistoryEventDefExtension_AssociatedSextypes">
<sextypes>
<li>DoublePenetration</li>
<li>Scissoring</li>
<li>Sixtynine</li>
<li>Fisting</li>
</sextypes>
</li>
</modExtensions>
</HistoryEventDef>
<!-- Precepts -->
<HistoryEventDef>
<defName>MiscSex</defName>
<label>sex</label>
<modExtensions>
<li Class="RJWSexperience.Ideology.HistoryEventDefExtension_AssociatedSextypes">
<sextypes>
<li>Masturbation</li>
<li>Boobjob</li>
<li>Handjob</li>
<li>Footjob</li>
<li>Fingering</li>
<li>MutualMasturbation</li>
</sextypes>
</li>
</modExtensions>
</HistoryEventDef>
<!-- Precepts -->
<PreceptDef>
<defName>Sex_Free</defName>
<issue>Sextype</issue>
@ -55,6 +100,9 @@
<displayOrderInImpact>1000</displayOrderInImpact>
<defaultSelectionWeight>100</defaultSelectionWeight>
<comps>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>AnalSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>AnalSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -63,6 +111,9 @@
<eventDef>AnalSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>OralSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>OralSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -71,6 +122,9 @@
<eventDef>OralSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>MiscSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>MiscSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -79,6 +133,9 @@
<eventDef>MiscSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>PromiscuousSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>PromiscuousSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -88,13 +145,6 @@
<thought>Sex_Know_Promiscuous</thought>
</li>
</comps>
<modExtensions>
<li Class="RJWSexperience.Ideology.Precepts.DefExtension_PreferSextype">
<sextypes>
<li>Vaginal</li>
</sextypes>
</li>
</modExtensions>
</PreceptDef>
<PreceptDef>
@ -107,6 +157,9 @@
<displayOrderInImpact>1000</displayOrderInImpact>
<defaultSelectionWeight>10</defaultSelectionWeight>
<comps>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>VaginalSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>VaginalSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -115,6 +168,9 @@
<eventDef>VaginalSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>OralSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>OralSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -123,6 +179,9 @@
<eventDef>OralSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>MiscSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>MiscSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -131,6 +190,9 @@
<eventDef>MiscSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>PromiscuousSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>PromiscuousSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -140,14 +202,6 @@
<thought>Sex_Know_Promiscuous</thought>
</li>
</comps>
<modExtensions>
<li Class="RJWSexperience.Ideology.Precepts.DefExtension_PreferSextype">
<sextypes>
<li>Anal</li>
<li>Rimming</li>
</sextypes>
</li>
</modExtensions>
</PreceptDef>
<PreceptDef>
@ -160,6 +214,9 @@
<displayOrderInImpact>1000</displayOrderInImpact>
<defaultSelectionWeight>5</defaultSelectionWeight>
<comps>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>VaginalSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>VaginalSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -168,6 +225,9 @@
<eventDef>VaginalSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>AnalSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>AnalSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -176,6 +236,9 @@
<eventDef>AnalSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>MiscSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>MiscSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -184,6 +247,9 @@
<eventDef>MiscSex</eventDef>
<thought>Sex_Know_Promiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>PromiscuousSex</eventDef>
</li>
<li Class="RJWSexperience.Ideology.Precepts.PreceptComp_SelfTookThoughtTagged">
<eventDef>PromiscuousSex</eventDef>
<thought>Sex_Promiscuous</thought>
@ -193,15 +259,6 @@
<thought>Sex_Know_Promiscuous</thought>
</li>
</comps>
<modExtensions>
<li Class="RJWSexperience.Ideology.Precepts.DefExtension_PreferSextype">
<sextypes>
<li>Cunnilingus</li>
<li>Fellatio</li>
<li>Beakjob</li>
</sextypes>
</li>
</modExtensions>
</PreceptDef>
<PreceptDef>
@ -217,6 +274,9 @@
<SexAbility>1.25</SexAbility>
</statFactors>
<comps>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>VaginalSex</eventDef>
</li>
<li Class="PreceptComp_SelfTookMemoryThought">
<eventDef>VaginalSex</eventDef>
<thought>Sex_NonPromiscuous</thought>
@ -225,6 +285,9 @@
<eventDef>VaginalSex</eventDef>
<thought>Sex_Know_NonPromiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>AnalSex</eventDef>
</li>
<li Class="PreceptComp_SelfTookMemoryThought">
<eventDef>AnalSex</eventDef>
<thought>Sex_NonPromiscuous</thought>
@ -233,6 +296,9 @@
<eventDef>AnalSex</eventDef>
<thought>Sex_Know_NonPromiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>OralSex</eventDef>
</li>
<li Class="PreceptComp_SelfTookMemoryThought">
<eventDef>OralSex</eventDef>
<thought>Sex_NonPromiscuous</thought>
@ -241,6 +307,9 @@
<eventDef>OralSex</eventDef>
<thought>Sex_Know_NonPromiscuous</thought>
</li>
<li Class="PreceptComp_UnwillingToDo">
<eventDef>MiscSex</eventDef>
</li>
<li Class="PreceptComp_SelfTookMemoryThought">
<eventDef>MiscSex</eventDef>
<thought>Sex_NonPromiscuous</thought>
@ -254,16 +323,6 @@
<thought>Sex_Know_Promiscuous_Approval</thought>
</li>
</comps>
<modExtensions>
<li Class="RJWSexperience.Ideology.Precepts.DefExtension_PreferSextype">
<sextypes>
<li>DoublePenetration</li>
<li>Scissoring</li>
<li>Sixtynine</li>
<li>Fisting</li>
</sextypes>
</li>
</modExtensions>
</PreceptDef>