Bind history events to sex interactions

This commit is contained in:
amevarashi 2022-07-02 20:35:06 +05:00
parent 340d35476a
commit a5d2c4fbd8
9 changed files with 215 additions and 115 deletions

View File

@ -1,13 +0,0 @@
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

@ -76,38 +76,5 @@ 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

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

View File

@ -5,6 +5,7 @@ using rjw.Modules.Interactions.Internals.Implementation;
using rjw.Modules.Interactions.Objects;
using RJWSexperience.Ideology.Precepts;
using System;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience.Ideology.Patches
@ -92,20 +93,27 @@ namespace RJWSexperience.Ideology.Patches
Pawn pawn = props.pawn;
Pawn partner = props.partner;
if (partner != null)
if (props.hasPartner())
{
if (xxx.is_human(pawn))
AfterSexHuman(pawn, partner, props.isRape, props.sexType);
AfterSexHuman(pawn, partner, props.isRape);
else if (xxx.is_human(partner))
AfterSexHuman(partner, pawn, false, props.sexType, true);
AfterSexHuman(partner, pawn, false, true);
}
InteractionDefExtension_HistoryEvents interactionEvents = props.dictionaryKey.GetModExtension<InteractionDefExtension_HistoryEvents>();
if (interactionEvents != null)
{
foreach (HistoryEventDef eventDef in interactionEvents.pawnEvents)
Find.HistoryEventsManager.RecordEvent(eventDef.CreateEvent(pawn));
foreach (HistoryEventDef eventDef in interactionEvents.partnerEvents)
Find.HistoryEventsManager.RecordEvent(eventDef.CreateEvent(partner));
}
}
public static void AfterSexHuman(Pawn human, Pawn partner, bool rape, xxx.rjwSextype sextype, bool isHumanReceiving = false)
public static void AfterSexHuman(Pawn human, Pawn partner, bool rape, bool isHumanReceiving = false)
{
if (partner.Dead)
Find.HistoryEventsManager.RecordEvent(VariousDefOf.SexWithCorpse.CreateEvent(human));
if (IdeoUtility.IsIncest(human, partner))
{
Find.HistoryEventsManager.RecordEvent(VariousDefOf.RJWSI_IncestuosSex.CreateEvent(human));
@ -162,15 +170,6 @@ namespace RJWSexperience.Ideology.Patches
Find.HistoryEventsManager.RecordEvent(VariousDefOf.WasRaped.CreateTaggedEvent(partner, HETag.BeenRaped + HETag.Gender(partner), human));
}
}
else
{
HistoryEventDef sexEventDef = IdeoUtility.GetSextypeEventDef(sextype);
if (sexEventDef != null)
{
Find.HistoryEventsManager.RecordEvent(sexEventDef.CreateEvent(human));
Find.HistoryEventsManager.RecordEvent(sexEventDef.CreateEvent(partner));
}
}
}
}
@ -194,22 +193,28 @@ namespace RJWSexperience.Ideology.Patches
{
public static void Postfix(InteractionWithExtension interaction, InteractionPawn dominant, InteractionPawn submissive, ref InteractionScore __result)
{
InteractionDefExtension_HistoryEvents interactionEvents = interaction.Interaction.GetModExtension<InteractionDefExtension_HistoryEvents>();
if (interactionEvents == null)
return;
Ideo ideo = dominant.Pawn.Ideo;
if (ideo != null)
__result.Dominant = PreceptSextype(ideo, dominant.Pawn.GetStatValue(xxx.sex_drive_stat), __result.Dominant, interaction);
__result.Dominant = PreceptSextype(ideo, dominant.Pawn.GetStatValue(xxx.sex_drive_stat), __result.Dominant, interactionEvents.pawnEvents);
ideo = submissive.Pawn.Ideo;
if (ideo != null)
__result.Submissive = PreceptSextype(ideo, submissive.Pawn.GetStatValue(xxx.sex_drive_stat), __result.Submissive, interaction);
__result.Submissive = PreceptSextype(ideo, submissive.Pawn.GetStatValue(xxx.sex_drive_stat), __result.Submissive, interactionEvents.partnerEvents);
}
public static float PreceptSextype(Ideo ideo, float sexdrive, float score, InteractionWithExtension interaction)
public static float PreceptSextype(Ideo ideo, float sexdrive, float score, List<HistoryEventDef> historyEventDefs)
{
HistoryEventDef sexEventDef = IdeoUtility.GetSextypeEventDef(interaction.Extension.rjwSextype);
if (sexEventDef != null && ideo.MemberWillingToDo(new HistoryEvent(sexEventDef)))
foreach(HistoryEventDef eventDef in historyEventDefs)
{
float mult = 8.0f * Math.Max(0.3f, 1 / Math.Max(0.01f, sexdrive));
return score * mult;
if (ideo.MemberWillingToDo(new HistoryEvent(eventDef)))
{
float mult = 8.0f * Math.Max(0.3f, 1 / Math.Max(0.01f, sexdrive));
return score * mult;
}
}
return score;
}

View File

@ -43,7 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Ideology\HistoryEventDefExtension_AssociatedSextypes.cs" />
<Compile Include="Ideology\InteractionDefExtension_HistoryEvents.cs" />
<Compile Include="Ideology\GoodwillSituationWorker_MemeCompatibility.cs" />
<Compile Include="Harmony.cs" />
<Compile Include="Ideology\HETag.cs" />

View File

@ -11,71 +11,26 @@
<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>
<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>
<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 -->

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Patch>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Necro_Anal" or defName="Necro_DoublePenetration" or defName="Necro_DoublePenetrationM" or defName="Necro_Vaginal"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>SexWithCorpse</li>
</pawnEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Necro_Reverse_Anal" or defName="Necro_Reverse_DoublePenetration" or defName="Necro_Reverse_DoublePenetrationM" or defName="Necro_Reverse_Vaginal"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>SexWithCorpse</li>
</pawnEvents>
</li>
</value>
</Operation>
</Patch>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<Patch>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Vaginal"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>VaginalSex</li>
</pawnEvents>
<partnerEvents>
<li>VaginalSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Anal" or defName="Sex_Rimming"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>AnalSex</li>
</pawnEvents>
<partnerEvents>
<li>AnalSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Beakjob" or defName="Sex_Cunnilingus" or defName="Sex_Fellatio" or defName="Sex_Makeout" or defName="Sex_Sixtynine"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>OralSex</li>
</pawnEvents>
<partnerEvents>
<li>OralSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Breastjob" or defName="Sex_Fingering" or defName="Sex_Footjob" or defName="Sex_Handjob" or defName="Sex_MutualHandholding" or defName="Sex_MutualMasturbation" or defName="Sex_MutualTailholding"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>MiscSex</li>
</pawnEvents>
<partnerEvents>
<li>MiscSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_DoublePenetration" or defName="Sex_DoublePenetrationM" or defName="Sex_Fisting" or defName="Sex_Scissoring"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>PromiscuousSex</li>
</pawnEvents>
<partnerEvents>
<li>PromiscuousSex</li>
</partnerEvents>
</li>
</value>
</Operation>
</Patch>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<Patch>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Reverse_Vaginal"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>VaginalSex</li>
</pawnEvents>
<partnerEvents>
<li>VaginalSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Reverse_Anal" or defName="Sex_Reverse_Rimming"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>AnalSex</li>
</pawnEvents>
<partnerEvents>
<li>AnalSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Reverse_Beakjob" or defName="Sex_Reverse_Cunnilingus" or defName="Sex_Reverse_Fellatio"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>OralSex</li>
</pawnEvents>
<partnerEvents>
<li>OralSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Reverse_Breastjob" or defName="Sex_Reverse_Fingering" or defName="Sex_Reverse_Footjob" or defName="Sex_Reverse_Handjob"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>MiscSex</li>
</pawnEvents>
<partnerEvents>
<li>MiscSex</li>
</partnerEvents>
</li>
</value>
</Operation>
<Operation Class="PatchOperationAddModExtension">
<xpath>/Defs/InteractionDef[defName="Sex_Reverse_DoublePenetration" or defName="Sex_Reverse_DoublePenetrationM" or defName="Sex_Reverse_Fisting"]</xpath>
<value>
<li Class="RJWSexperience.Ideology.InteractionDefExtension_HistoryEvents">
<pawnEvents>
<li>PromiscuousSex</li>
</pawnEvents>
<partnerEvents>
<li>PromiscuousSex</li>
</partnerEvents>
</li>
</value>
</Operation>
</Patch>