From 94711f740ae7addf05eda10fb59827c815c28f49 Mon Sep 17 00:00:00 2001 From: Stardust3D <3dstardust@gmail.com> Date: Wed, 19 Oct 2022 18:50:30 +0200 Subject: [PATCH] moved most surgery logic into Recipe_Plastic_Surgery.cs --- .../RJW_PlasticSurgeries.csproj | 1 + .../Recipe_Plastic_Surgery.cs | 55 +++++++ .../Recipe_Surgery_Mammoplasty.cs | 136 +++++++++++------- .../Recipe_Surgery_Penoplasty.cs | 74 ++++------ .../Recipe_Surgery_Sphinctoplasty.cs | 72 ++++------ .../Recipe_Surgery_Vaginoplasty.cs | 72 ++++------ 6 files changed, 227 insertions(+), 183 deletions(-) create mode 100644 Source/RJW_PlasticSurgeries/Recipe_Plastic_Surgery.cs diff --git a/Source/RJW_PlasticSurgeries/RJW_PlasticSurgeries.csproj b/Source/RJW_PlasticSurgeries/RJW_PlasticSurgeries.csproj index 085cb80..98d6f3a 100644 --- a/Source/RJW_PlasticSurgeries/RJW_PlasticSurgeries.csproj +++ b/Source/RJW_PlasticSurgeries/RJW_PlasticSurgeries.csproj @@ -70,6 +70,7 @@ + diff --git a/Source/RJW_PlasticSurgeries/Recipe_Plastic_Surgery.cs b/Source/RJW_PlasticSurgeries/Recipe_Plastic_Surgery.cs new file mode 100644 index 0000000..9e39b4d --- /dev/null +++ b/Source/RJW_PlasticSurgeries/Recipe_Plastic_Surgery.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using Dyspareunia; +using RimWorld; +using rjw; +using Verse; +using DamageDefOf = Dyspareunia.DamageDefOf; + +namespace RJW_PlasticSurgeries +{ + public abstract class Recipe_Plastic_Surgery : Recipe_Surgery + { + protected readonly bool HasDyspareunia = ModLister.HasActiveModWithName("Dyspareunia"); + + public override IEnumerable GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) + { + var part = GetPartCandidate(pawn); + if (part != null) + { + var hediffs = Genital_Helper.get_PartsHediffList(pawn, part); + if (HasPart(pawn, hediffs)) yield return part; + } + } + + protected abstract BodyPartRecord GetPartCandidate(Pawn pawn); + protected abstract bool HasPart(Pawn pawn, List hediffs); + + public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List ingredients, + Bill bill) + { + if (billDoer != null) + { + TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); + SurgeryResult(pawn); + } + } + + protected abstract void SurgeryResult(Pawn pawn); + + private static void DamageHediff(Hediff hed) + { + PenetrationUtility.AddDamageHediff(DamageDefOf.SexStretch, 0.5f, hed, null); + } + + protected void SurgeryX(Pawn pawn, float severity, bool useDyspareunia = false) + { + GetHediffs(pawn).ForEach(hed => + { + hed.Severity = severity; + if (useDyspareunia && HasDyspareunia) DamageHediff(hed); + }); + } + + protected abstract List GetHediffs(Pawn pawn); + } +} \ No newline at end of file diff --git a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Mammoplasty.cs b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Mammoplasty.cs index 9cf7d81..3ab8e49 100644 --- a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Mammoplasty.cs +++ b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Mammoplasty.cs @@ -1,57 +1,39 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; -using RimWorld; using rjw; using Verse; namespace RJW_PlasticSurgeries { - public abstract class Recipe_Surgery_Mammoplasty : Recipe_Surgery + public abstract class Recipe_Surgery_Mammoplasty : Recipe_Plastic_Surgery { - public override IEnumerable GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) + protected override BodyPartRecord GetPartCandidate(Pawn pawn) { - var part = Genital_Helper.get_genitalsBPR(pawn); - if (part != null) - { - var hediffs = Genital_Helper.get_PartsHediffList(pawn, part); - if (Genital_Helper.has_breasts(pawn, hediffs) && pawn.GetBreastList().Any(hed => hed.Severity >= 0.02f)) - yield return part; - } + return Genital_Helper.get_genitalsBPR(pawn); } - public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List ingredients, - Bill bill) + protected override bool HasPart(Pawn pawn, List hediffs) { - if (billDoer != null) - { - TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); - SurgeryResult(pawn); - } + return Genital_Helper.has_breasts(pawn, hediffs) && + pawn.GetBreastList().Any(hed => hed.Severity >= 0.02f); } - public abstract void SurgeryResult(Pawn pawn); - /*{ - pawn.GetBreastList().ForEach(hed => hed.Severity = Math.Min(1.0f, hed.Severity * 1.25f)); - //Log.Message($"Cup sizes: {pawn.GetBreastList().SelectMany(hed => hed.def.GetModExtension().cupSizes.Join()).Join(delimiter: ";")}"); - float val = 0; - PartSizeExtension.TryGetCupSize(pawn.GetBreastList().First(), out val); - pawn.GetBreastList().First().def.stages.First(); - Log.Message($"Cup size: {val}"); - }*/ + protected override List GetHediffs(Pawn pawn) + { + throw new NotSupportedException(); + } protected void SurgeryCupX(Pawn pawn, int stage) { pawn.GetBreastList().ForEach(hed => { float severity; - if (TryGetSeverityFromSize(hed, stage, out severity)) - { - hed.Severity = severity; - } + if (TryGetSeverityFromSize(hed, stage, out severity)) hed.Severity = severity; }); } - static bool TryGetSeverityFromSize(Hediff hediff, float cupSize, out float severity) + private static bool TryGetSeverityFromSize(Hediff hediff, float cupSize, out float severity) { if (!hediff.def.HasModExtension()) { @@ -77,91 +59,145 @@ namespace RJW_PlasticSurgeries public class Recipe_Surgery_Mammoplasty_A : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 1); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 1); + } } public class Recipe_Surgery_Mammoplasty_B : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 2); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 2); + } } public class Recipe_Surgery_Mammoplasty_C : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 3); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 3); + } } public class Recipe_Surgery_Mammoplasty_D : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 4); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 4); + } } public class Recipe_Surgery_Mammoplasty_E : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 6); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 6); + } } public class Recipe_Surgery_Mammoplasty_F : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 7); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 7); + } } public class Recipe_Surgery_Mammoplasty_G : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 9); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 9); + } } public class Recipe_Surgery_Mammoplasty_H : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 11); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 11); + } } public class Recipe_Surgery_Mammoplasty_J : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 13); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 13); + } } public class Recipe_Surgery_Mammoplasty_K : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 15); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 15); + } } public class Recipe_Surgery_Mammoplasty_L : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 17); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 17); + } } public class Recipe_Surgery_Mammoplasty_M : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 19); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 19); + } } public class Recipe_Surgery_Mammoplasty_N : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 21); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 21); + } } public class Recipe_Surgery_Mammoplasty_O : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 23); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 23); + } } public class Recipe_Surgery_Mammoplasty_P : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 25); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 25); + } } public class Recipe_Surgery_Mammoplasty_Q : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 27); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 27); + } } public class Recipe_Surgery_Mammoplasty_R : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 29); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 29); + } } public class Recipe_Surgery_Mammoplasty_Unknown : Recipe_Surgery_Mammoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryCupX(pawn, 31); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryCupX(pawn, 31); + } } } \ No newline at end of file diff --git a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Penoplasty.cs b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Penoplasty.cs index 5d39898..ea205d9 100644 --- a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Penoplasty.cs +++ b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Penoplasty.cs @@ -1,81 +1,65 @@ -using System; -using System.Collections.Generic; -using Dyspareunia; -using RimWorld; +using System.Collections.Generic; using rjw; using Verse; -using DamageDefOf = Dyspareunia.DamageDefOf; namespace RJW_PlasticSurgeries { - public abstract class Recipe_Surgery_Penoplasty : Recipe_Surgery + public abstract class Recipe_Surgery_Penoplasty : Recipe_Plastic_Surgery { - private readonly bool hasDyspareunia = ModLister.HasActiveModWithName("Dyspareunia"); - - public override IEnumerable GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) + protected override BodyPartRecord GetPartCandidate(Pawn pawn) { - var part = Genital_Helper.get_genitalsBPR(pawn); - if (part != null) - { - var hediffs = Genital_Helper.get_PartsHediffList(pawn, part); - if (Genital_Helper.has_penis_fertile(pawn, hediffs) || - Genital_Helper.has_penis_infertile(pawn, hediffs)) yield return part; - } + return Genital_Helper.get_genitalsBPR(pawn); } - /// - public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List ingredients, - Bill bill) + protected override bool HasPart(Pawn pawn, List hediffs) { - if (billDoer != null) - { - TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); - SurgeryResult(pawn); - } + return Genital_Helper.has_penis_fertile(pawn, hediffs) || + Genital_Helper.has_penis_infertile(pawn, hediffs); } - public abstract void SurgeryResult(Pawn pawn); - - protected void SurgeryX(Pawn pawn, float severity) + protected override List GetHediffs(Pawn pawn) { - pawn.GetGenitalsList().FindAll(Genital_Helper.is_penis).ForEach(hed => - { - hed.Severity = severity; - if (hasDyspareunia) - { - DamageHediff(hed); - } - }); - } - - private static void DamageHediff(Hediff hed) - { - PenetrationUtility.AddDamageHediff(DamageDefOf.SexStretch, 0.5f, hed, null); + return pawn.GetGenitalsList().FindAll(Genital_Helper.is_penis); } } public class Recipe_Surgery_Penoplasty_Micro : Recipe_Surgery_Penoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.1f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.1f, true); + } } public class Recipe_Surgery_Penoplasty_Small : Recipe_Surgery_Penoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.3f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.3f, true); + } } public class Recipe_Surgery_Penoplasty_Average : Recipe_Surgery_Penoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.5f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.5f, true); + } } public class Recipe_Surgery_Penoplasty_Large : Recipe_Surgery_Penoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.7f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.7f, true); + } } public class Recipe_Surgery_Penoplasty_Huge : Recipe_Surgery_Penoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.9f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.9f, true); + } } } \ No newline at end of file diff --git a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Sphinctoplasty.cs b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Sphinctoplasty.cs index 1ceef5c..0534776 100644 --- a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Sphinctoplasty.cs +++ b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Sphinctoplasty.cs @@ -1,80 +1,64 @@ -using System; -using System.Collections.Generic; -using Dyspareunia; -using RimWorld; +using System.Collections.Generic; using rjw; using Verse; -using DamageDefOf = Dyspareunia.DamageDefOf; namespace RJW_PlasticSurgeries { - public abstract class Recipe_Surgery_Sphinctoplasty : Recipe_Surgery + public abstract class Recipe_Surgery_Sphinctoplasty : Recipe_Plastic_Surgery { - private readonly bool hasDyspareunia = ModLister.HasActiveModWithName("Dyspareunia"); - - public override IEnumerable GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) + protected override BodyPartRecord GetPartCandidate(Pawn pawn) { - var part = Genital_Helper.get_anusBPR(pawn); - if (part != null) - { - var hediffs = Genital_Helper.get_PartsHediffList(pawn, part); - if (Genital_Helper.has_anus(pawn, hediffs)) yield return part; - } + return Genital_Helper.get_anusBPR(pawn); } - /// - public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List ingredients, - Bill bill) + protected override bool HasPart(Pawn pawn, List hediffs) { - if (billDoer != null) - { - TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); - SurgeryResult(pawn); - } + return Genital_Helper.has_anus(pawn, hediffs); } - public abstract void SurgeryResult(Pawn pawn); - - protected void SurgeryX(Pawn pawn, float severity) + protected override List GetHediffs(Pawn pawn) { - pawn.GetAnusList().ForEach(hed => - { - hed.Severity = severity; - if (hasDyspareunia) - { - DamageHediff(hed); - } - }); - } - - private static void DamageHediff(Hediff hed) - { - PenetrationUtility.AddDamageHediff(DamageDefOf.SexStretch, 0.5f, hed, null); + return pawn.GetAnusList(); } } public class Recipe_Surgery_Sphinctoplasty_Micro : Recipe_Surgery_Sphinctoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.1f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.1f, true); + } } public class Recipe_Surgery_Sphinctoplasty_Tight : Recipe_Surgery_Sphinctoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.3f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.3f, true); + } } public class Recipe_Surgery_Sphinctoplasty_Average : Recipe_Surgery_Sphinctoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.5f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.5f, true); + } } public class Recipe_Surgery_Sphinctoplasty_Accomodating : Recipe_Surgery_Sphinctoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.7f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.7f, true); + } } public class Recipe_Surgery_Sphinctoplasty_Cavernous : Recipe_Surgery_Sphinctoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.9f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.9f, true); + } } } \ No newline at end of file diff --git a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Vaginoplasty.cs b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Vaginoplasty.cs index 73209ca..aec6dc4 100644 --- a/Source/RJW_PlasticSurgeries/Recipe_Surgery_Vaginoplasty.cs +++ b/Source/RJW_PlasticSurgeries/Recipe_Surgery_Vaginoplasty.cs @@ -1,80 +1,64 @@ -using System; -using System.Collections.Generic; -using Dyspareunia; -using RimWorld; +using System.Collections.Generic; using rjw; using Verse; -using DamageDefOf = Dyspareunia.DamageDefOf; namespace RJW_PlasticSurgeries { - public abstract class Recipe_Surgery_Vaginoplasty : Recipe_Surgery + public abstract class Recipe_Surgery_Vaginoplasty : Recipe_Plastic_Surgery { - private readonly bool hasDyspareunia = ModLister.HasActiveModWithName("Dyspareunia"); - - public override IEnumerable GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) + protected override BodyPartRecord GetPartCandidate(Pawn pawn) { - var part = Genital_Helper.get_genitalsBPR(pawn); - if (part != null) - { - var hediffs = Genital_Helper.get_PartsHediffList(pawn, part); - if (Genital_Helper.has_vagina(pawn, hediffs)) yield return part; - } + return Genital_Helper.get_genitalsBPR(pawn); } - /// - public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List ingredients, - Bill bill) + protected override bool HasPart(Pawn pawn, List hediffs) { - if (billDoer != null) - { - TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); - SurgeryResult(pawn); - } + return Genital_Helper.has_vagina(pawn, hediffs); } - public abstract void SurgeryResult(Pawn pawn); - - protected void SurgeryX(Pawn pawn, float severity) + protected override List GetHediffs(Pawn pawn) { - pawn.GetGenitalsList().FindAll(Genital_Helper.is_vagina).ForEach(hed => - { - hed.Severity = severity; - if (hasDyspareunia) - { - DamageHediff(hed); - } - }); - } - - private static void DamageHediff(Hediff hed) - { - PenetrationUtility.AddDamageHediff(DamageDefOf.SexStretch, 0.5f, hed, null); + return pawn.GetGenitalsList().FindAll(Genital_Helper.is_vagina); } } public class Recipe_Surgery_Vaginoplasty_Micro : Recipe_Surgery_Vaginoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.1f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.1f, true); + } } public class Recipe_Surgery_Vaginoplasty_Tight : Recipe_Surgery_Vaginoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.3f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.3f, true); + } } public class Recipe_Surgery_Vaginoplasty_Average : Recipe_Surgery_Vaginoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.5f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.5f, true); + } } public class Recipe_Surgery_Vaginoplasty_Accomodating : Recipe_Surgery_Vaginoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.7f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.7f, true); + } } public class Recipe_Surgery_Vaginoplasty_Cavernous : Recipe_Surgery_Vaginoplasty { - public override void SurgeryResult(Pawn pawn) => SurgeryX(pawn, 0.9f); + protected override void SurgeryResult(Pawn pawn) + { + SurgeryX(pawn, 0.9f, true); + } } } \ No newline at end of file