From df9c39e0a759f50a8c855436ed280b90d0239a8a Mon Sep 17 00:00:00 2001 From: amevarashi Date: Thu, 23 Jun 2022 21:47:05 +0500 Subject: [PATCH] Implement PreceptComp_UnwillingToDo for sextype precepts --- ...oryEventDefExtension_AssociatedSextypes.cs | 13 ++ .../IdeologyAddon/Ideology/IdeoUtility.cs | 36 +++++ .../Ideology/Patches/RJW_Patch_Ideo.cs | 50 +------ .../Precepts/DefExtension_PreferSextype.cs | 21 --- .../IdeologyAddon/IdeologyAddon.csproj | 2 +- .../Defs/PreceptDefs/Precepts_Sex.xml | 139 +++++++++++++----- 6 files changed, 154 insertions(+), 107 deletions(-) create mode 100644 RJWSexperience/IdeologyAddon/Ideology/HistoryEventDefExtension_AssociatedSextypes.cs delete mode 100644 RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_PreferSextype.cs diff --git a/RJWSexperience/IdeologyAddon/Ideology/HistoryEventDefExtension_AssociatedSextypes.cs b/RJWSexperience/IdeologyAddon/Ideology/HistoryEventDefExtension_AssociatedSextypes.cs new file mode 100644 index 0000000..afdcae0 --- /dev/null +++ b/RJWSexperience/IdeologyAddon/Ideology/HistoryEventDefExtension_AssociatedSextypes.cs @@ -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 sextypes = new List(); + } +} diff --git a/RJWSexperience/IdeologyAddon/Ideology/IdeoUtility.cs b/RJWSexperience/IdeologyAddon/Ideology/IdeoUtility.cs index 333ecd1..e67fa3d 100644 --- a/RJWSexperience/IdeologyAddon/Ideology/IdeoUtility.cs +++ b/RJWSexperience/IdeologyAddon/Ideology/IdeoUtility.cs @@ -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 historyEventBySextype = BuildHistoryEventBySextype(); + + private static Dictionary BuildHistoryEventBySextype() + { + Dictionary dictionary = new Dictionary(); + foreach (HistoryEventDef historyEventDef in DefDatabase.AllDefsListForReading) + { + HistoryEventDefExtension_AssociatedSextypes associatedSextypes = historyEventDef.GetModExtension(); + 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; + } } } diff --git a/RJWSexperience/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs b/RJWSexperience/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs index 92bc1dd..05ec682 100644 --- a/RJWSexperience/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs +++ b/RJWSexperience/IdeologyAddon/Ideology/Patches/RJW_Patch_Ideo.cs @@ -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; } } - - /// - /// only for non-violate human sex - /// - /// - /// - 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; - } - } } /// @@ -236,13 +198,11 @@ 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++) + HistoryEventDef sexEventDef = IdeoUtility.GetSextypeEventDef(interaction.Extension.rjwSextype); + if (sexEventDef != null && ideo.MemberWillingToDo(new HistoryEvent(sexEventDef))) { - if (ideo.PreceptsListForReading[i].def.GetModExtension()?.HasSextype(interaction.Extension.rjwSextype) == true) - { - float mult = 8.0f * Math.Max(0.3f, 1 / Math.Max(0.01f, sexdrive)); - return score * mult; - } + float mult = 8.0f * Math.Max(0.3f, 1 / Math.Max(0.01f, sexdrive)); + return score * mult; } return score; } diff --git a/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_PreferSextype.cs b/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_PreferSextype.cs deleted file mode 100644 index c67ee02..0000000 --- a/RJWSexperience/IdeologyAddon/Ideology/Precepts/DefExtension_PreferSextype.cs +++ /dev/null @@ -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 sextypes = new List(); - private HashSet sextypesHashSet; - - public bool HasSextype(string sextype) - { - if (sextypesHashSet == null) - sextypesHashSet = new HashSet(sextypes); - - return sextypesHashSet.Contains(sextype); - } - } -} diff --git a/RJWSexperience/IdeologyAddon/IdeologyAddon.csproj b/RJWSexperience/IdeologyAddon/IdeologyAddon.csproj index 74379c4..5dca738 100644 --- a/RJWSexperience/IdeologyAddon/IdeologyAddon.csproj +++ b/RJWSexperience/IdeologyAddon/IdeologyAddon.csproj @@ -43,6 +43,7 @@ + @@ -56,7 +57,6 @@ - diff --git a/RJWSexperience_Ideology/Defs/PreceptDefs/Precepts_Sex.xml b/RJWSexperience_Ideology/Defs/PreceptDefs/Precepts_Sex.xml index c49bb61..1e5fee4 100644 --- a/RJWSexperience_Ideology/Defs/PreceptDefs/Precepts_Sex.xml +++ b/RJWSexperience_Ideology/Defs/PreceptDefs/Precepts_Sex.xml @@ -11,29 +11,74 @@ VaginalSex + +
  • + +
  • Vaginal
  • + + +
    AnalSex + +
  • + +
  • Anal
  • +
  • Rimming
  • + + +
    OralSex - - - - MiscSex - + +
  • + +
  • Cunnilingus
  • +
  • Fellatio
  • + + +
    PromiscuousSex + +
  • + +
  • DoublePenetration
  • +
  • Scissoring
  • +
  • Sixtynine
  • +
  • Fisting
  • + + +
    - + + MiscSex + + +
  • + +
  • Masturbation
  • +
  • Boobjob
  • +
  • Handjob
  • +
  • Footjob
  • +
  • Fingering
  • +
  • MutualMasturbation
  • + + +
    +
    + + Sex_Free Sextype @@ -55,6 +100,9 @@ 1000 100 +
  • + AnalSex +
  • AnalSex Sex_Promiscuous @@ -63,6 +111,9 @@ AnalSex Sex_Know_Promiscuous
  • +
  • + OralSex +
  • OralSex Sex_Promiscuous @@ -71,6 +122,9 @@ OralSex Sex_Know_Promiscuous
  • +
  • + MiscSex +
  • MiscSex Sex_Promiscuous @@ -79,6 +133,9 @@ MiscSex Sex_Know_Promiscuous
  • +
  • + PromiscuousSex +
  • PromiscuousSex Sex_Promiscuous @@ -88,13 +145,6 @@ Sex_Know_Promiscuous
  • - -
  • - -
  • Vaginal
  • - - -
    @@ -107,6 +157,9 @@ 1000 10 +
  • + VaginalSex +
  • VaginalSex Sex_Promiscuous @@ -115,6 +168,9 @@ VaginalSex Sex_Know_Promiscuous
  • +
  • + OralSex +
  • OralSex Sex_Promiscuous @@ -123,6 +179,9 @@ OralSex Sex_Know_Promiscuous
  • +
  • + MiscSex +
  • MiscSex Sex_Promiscuous @@ -131,6 +190,9 @@ MiscSex Sex_Know_Promiscuous
  • +
  • + PromiscuousSex +
  • PromiscuousSex Sex_Promiscuous @@ -140,14 +202,6 @@ Sex_Know_Promiscuous
  • - -
  • - -
  • Anal
  • -
  • Rimming
  • - - -
    @@ -160,6 +214,9 @@ 1000 5 +
  • + VaginalSex +
  • VaginalSex Sex_Promiscuous @@ -168,6 +225,9 @@ VaginalSex Sex_Know_Promiscuous
  • +
  • + AnalSex +
  • AnalSex Sex_Promiscuous @@ -176,6 +236,9 @@ AnalSex Sex_Know_Promiscuous
  • +
  • + MiscSex +
  • MiscSex Sex_Promiscuous @@ -184,6 +247,9 @@ MiscSex Sex_Know_Promiscuous
  • +
  • + PromiscuousSex +
  • PromiscuousSex Sex_Promiscuous @@ -193,15 +259,6 @@ Sex_Know_Promiscuous
  • - -
  • - -
  • Cunnilingus
  • -
  • Fellatio
  • -
  • Beakjob
  • - - -
    @@ -217,6 +274,9 @@ 1.25 +
  • + VaginalSex +
  • VaginalSex Sex_NonPromiscuous @@ -225,6 +285,9 @@ VaginalSex Sex_Know_NonPromiscuous
  • +
  • + AnalSex +
  • AnalSex Sex_NonPromiscuous @@ -233,6 +296,9 @@ AnalSex Sex_Know_NonPromiscuous
  • +
  • + OralSex +
  • OralSex Sex_NonPromiscuous @@ -241,6 +307,9 @@ OralSex Sex_Know_NonPromiscuous
  • +
  • + MiscSex +
  • MiscSex Sex_NonPromiscuous @@ -254,16 +323,6 @@ Sex_Know_Promiscuous_Approval
  • - -
  • - -
  • DoublePenetration
  • -
  • Scissoring
  • -
  • Sixtynine
  • -
  • Fisting
  • - - -