From eab18ce2bba3d09a03a5768f452e91237d745feb Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sun, 12 Jun 2022 11:50:36 +0500 Subject: [PATCH] Move trait manipulation to a separate class --- RJWSexperience/RJWSexperience/DebugAction.cs | 6 +-- .../ExtensionMethods/PawnExtensions.cs | 23 +--------- .../RJWSexperience/Patches/Rimworld_Patch.cs | 2 +- .../RJWSexperience/RJWSexperience.csproj | 1 + RJWSexperience/RJWSexperience/RJWUtility.cs | 16 ------- .../RJWSexperience/Virginity/TraitHandler.cs | 46 +++++++++++++++++++ 6 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 RJWSexperience/RJWSexperience/Virginity/TraitHandler.cs diff --git a/RJWSexperience/RJWSexperience/DebugAction.cs b/RJWSexperience/RJWSexperience/DebugAction.cs index ef2abd1..022664a 100644 --- a/RJWSexperience/RJWSexperience/DebugAction.cs +++ b/RJWSexperience/RJWSexperience/DebugAction.cs @@ -1,6 +1,5 @@ using RimWorld; using rjw; -using RJWSexperience.ExtensionMethods; using Verse; namespace RJWSexperience @@ -14,7 +13,7 @@ namespace RJWSexperience if (virgin != null) p.story.traits.RemoveTrait(virgin); ResetRecord(p, true); if (ResetRecord(p, false)) - p.AddVirginTrait(); + Virginity.TraitHandler.AddVirginTrait(p); MoteMaker.ThrowText(p.TrueCenter(), p.Map, "Records resetted!"); } @@ -22,11 +21,10 @@ namespace RJWSexperience private static void ResetRecordsZero(Pawn p) { ResetRecord(p, true); - p.AddVirginTrait(); + Virginity.TraitHandler.AddVirginTrait(p); MoteMaker.ThrowText(p.TrueCenter(), p.Map, "Records resetted!\nVirginified!"); } - [DebugAction("RJW Sexperience", "Reset lust", false, false, actionType = DebugActionType.ToolMapForPawns, allowedGameStates = AllowedGameStates.PlayingOnMap)] private static void ResetLust(Pawn p) { diff --git a/RJWSexperience/RJWSexperience/ExtensionMethods/PawnExtensions.cs b/RJWSexperience/RJWSexperience/ExtensionMethods/PawnExtensions.cs index c2523eb..9e1c8ef 100644 --- a/RJWSexperience/RJWSexperience/ExtensionMethods/PawnExtensions.cs +++ b/RJWSexperience/RJWSexperience/ExtensionMethods/PawnExtensions.cs @@ -86,14 +86,14 @@ namespace RJWSexperience if (pawn.IsVirgin()) { pawn.TryGetComp()?.RecordFirst(partner, props); - if (RJWUtility.RemoveVirginTrait(pawn, partner, props)) + if (Virginity.TraitHandler.RemoveVirginTrait(pawn, partner, props)) { Messages.Message(Keyed.RS_LostVirgin(pawn.LabelShort, partner.LabelShort), MessageTypeDefOf.NeutralEvent, true); } } else { - RJWUtility.RemoveVirginTrait(pawn, partner, props); + Virginity.TraitHandler.RemoveVirginTrait(pawn, partner, props); } } } @@ -111,24 +111,5 @@ namespace RJWSexperience else return Gender.Male; } } - - public static void AddVirginTrait(this Pawn pawn) - { - if (pawn.story?.traits == null) - return; - - if (pawn.IsVirgin()) - { - Virginity.TraitDegree degree = Virginity.TraitDegree.MaleVirgin; - if (pawn.gender == Gender.Female) degree = Virginity.TraitDegree.FemaleVirgin; - Trait virgin = new Trait(VariousDefOf.Virgin, (int)degree, true); - pawn.story.traits.GainTrait(virgin); - } - else if (pawn.gender == Gender.Female && Rand.Chance(0.05f)) - { - Trait virgin = new Trait(VariousDefOf.Virgin, (int)Virginity.TraitDegree.FemaleAfterSurgery, true); - pawn.story.traits.GainTrait(virgin); - } - } } } diff --git a/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs b/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs index d2ca991..3241752 100644 --- a/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs +++ b/RJWSexperience/RJWSexperience/Patches/Rimworld_Patch.cs @@ -19,7 +19,7 @@ namespace RJWSexperience doVirginTrait = RecordRandomizer.Randomize(__result); if (doVirginTrait) - __result.AddVirginTrait(); + Virginity.TraitHandler.AddVirginTrait(__result); } } } diff --git a/RJWSexperience/RJWSexperience/RJWSexperience.csproj b/RJWSexperience/RJWSexperience/RJWSexperience.csproj index e6e913b..bfcc186 100644 --- a/RJWSexperience/RJWSexperience/RJWSexperience.csproj +++ b/RJWSexperience/RJWSexperience/RJWSexperience.csproj @@ -93,6 +93,7 @@ + diff --git a/RJWSexperience/RJWSexperience/RJWUtility.cs b/RJWSexperience/RJWSexperience/RJWUtility.cs index fd9381c..f15cbeb 100644 --- a/RJWSexperience/RJWSexperience/RJWUtility.cs +++ b/RJWSexperience/RJWSexperience/RJWUtility.cs @@ -11,22 +11,6 @@ namespace RJWSexperience { public static class RJWUtility { - public static bool RemoveVirginTrait(Pawn pawn, Pawn partner, SexProps props) - { - Trait virgin = pawn.story?.traits?.GetTrait(VariousDefOf.Virgin); - if (virgin == null) - return false; - - int degree = virgin.Degree; - if (pawn.gender == Gender.Female && degree > 0 && !pawn.Dead) - { - FilthMaker.TryMakeFilth(pawn.Position, pawn.Map, ThingDefOf.Filth_Blood, pawn.LabelShort, 1, FilthSourceFlags.Pawn); - } - ThrowVirginHIstoryEvent(pawn, partner, props, degree); - pawn.story.traits.RemoveTrait(virgin); - return true; - } - /// /// For ideo patch /// diff --git a/RJWSexperience/RJWSexperience/Virginity/TraitHandler.cs b/RJWSexperience/RJWSexperience/Virginity/TraitHandler.cs new file mode 100644 index 0000000..a97689d --- /dev/null +++ b/RJWSexperience/RJWSexperience/Virginity/TraitHandler.cs @@ -0,0 +1,46 @@ +using RimWorld; +using rjw; +using Verse; + +namespace RJWSexperience.Virginity +{ + public static class TraitHandler + { + private const float hymenSurgeryChance = 0.05f; + + public static void AddVirginTrait(Pawn pawn) + { + if (pawn.story?.traits == null) + return; + + if (pawn.IsVirgin()) + { + TraitDegree degree = TraitDegree.MaleVirgin; + if (pawn.gender == Gender.Female) degree = TraitDegree.FemaleVirgin; + Trait virgin = new Trait(VariousDefOf.Virgin, (int)degree, true); + pawn.story.traits.GainTrait(virgin); + } + else if (pawn.gender == Gender.Female && Rand.Chance(hymenSurgeryChance)) + { + Trait virgin = new Trait(VariousDefOf.Virgin, (int)TraitDegree.FemaleAfterSurgery, true); + pawn.story.traits.GainTrait(virgin); + } + } + + public static bool RemoveVirginTrait(Pawn pawn, Pawn partner, SexProps props) + { + Trait virgin = pawn.story?.traits?.GetTrait(VariousDefOf.Virgin); + if (virgin == null) + return false; + + int degree = virgin.Degree; + if (pawn.gender == Gender.Female && degree > 0 && !pawn.Dead) + { + FilthMaker.TryMakeFilth(pawn.Position, pawn.Map, ThingDefOf.Filth_Blood, pawn.LabelShort, 1, FilthSourceFlags.Pawn); + } + RJWUtility.ThrowVirginHIstoryEvent(pawn, partner, props, degree); + pawn.story.traits.RemoveTrait(virgin); + return true; + } + } +}