diff --git a/Common/Defs/GeneDefs/GeneDefs_Diseases.xml b/Common/Defs/GeneDefs/GeneDefs_Diseases.xml index e5c8723..ecc3ee8 100644 --- a/Common/Defs/GeneDefs/GeneDefs_Diseases.xml +++ b/Common/Defs/GeneDefs/GeneDefs_Diseases.xml @@ -186,4 +186,20 @@ + + + rjw_genes_size_blinded + + This genetic disease makes the carrier dramatically more drawn to pawns with huge cocks. + UI/Icons/ColonistBar/Idle + 1 + 1 + 11 + +
  • + 0.1 +
  • +
    +
    + \ No newline at end of file diff --git a/Source/GeneDefOf.cs b/Source/GeneDefOf.cs index e4f4aff..2e59f20 100644 --- a/Source/GeneDefOf.cs +++ b/Source/GeneDefOf.cs @@ -126,6 +126,7 @@ namespace RJW_Genes public static readonly GeneDef rjw_genes_minor_vulnerability; public static readonly GeneDef rjw_genes_major_vulnerability; public static readonly GeneDef rjw_genes_fluctual_sexual_needs; + public static readonly GeneDef rjw_genes_size_blinded; //Other Defs public static readonly XenotypeDef rjw_genes_succubus; diff --git a/Source/Genes/Diseases/Patches/Patch_SecondaryRomanceChanceFactor_Gene_SizeBlinded.cs b/Source/Genes/Diseases/Patches/Patch_SecondaryRomanceChanceFactor_Gene_SizeBlinded.cs new file mode 100644 index 0000000..fa36398 --- /dev/null +++ b/Source/Genes/Diseases/Patches/Patch_SecondaryRomanceChanceFactor_Gene_SizeBlinded.cs @@ -0,0 +1,56 @@ +using HarmonyLib; +using RimWorld; +using rjw; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace RJW_Genes +{ + /// + /// This patch helps with the gene `rjw_genes_size_blinded`. + /// Within RJW the CasualSexHelper utilizes the basefunction "pawn.relations.SecondaryRomanceChanceFactor" + /// https://gitgud.io/Ed86/rjw/-/blob/master/1.5/Source/Common/Helpers/CasualSex_Helper.cs + /// + /// We check on hookup for the other pawn if they have a penis. + /// If yes, we modulate the romance chance based on the following: + /// (Severity * BodySize - 0.5) * romance_multiplier + /// So pawns with a cock smaller than 0.5 will be penalized, while pawns with more than 0.5 will be preferred. + /// + [HarmonyPatch(typeof(Pawn_RelationsTracker), "SecondaryRomanceChanceFactor")] + public class Patch_SecondaryRomanceChanceFactor_Gene_SizeBlinded + { + + const float romance_multiplier = 2f; + + public static void Postfix( Pawn ___pawn, Pawn otherPawn, ref float __result) + { + if (otherPawn == null || ___pawn == null || ___pawn.genes == null || otherPawn.genes == null) + { + return; + } + if (___pawn.genes.HasActiveGene(GeneDefOf.rjw_genes_size_blinded) && Genital_Helper.has_penis_fertile(otherPawn) || (Genital_Helper.has_penis_infertile(otherPawn))) + { + Hediff biggest_cock = GenitaliaUtility.GetBiggestPenis(otherPawn); + if (biggest_cock != null) + { + float bodysize = GenitaliaUtility.GetBodySizeOfSexPart(biggest_cock); + // Bodysize can only be a bonus, not a minus. + bodysize = Math.Max(1.0f, bodysize); + + float attraction_bonus = (biggest_cock.Severity * bodysize - 0.5f) * romance_multiplier; + float result_backup = __result; + __result += attraction_bonus; + // Don't make it smaller than 0, to not get issues. + __result = __result < 0 ? 0.0f : __result; + + ModLog.Debug($"Gene_SizeBlind: Modulate Romance-Chance {___pawn}-->{otherPawn} from {result_backup} by {attraction_bonus} to {__result}"); + } + } + } + + } +} diff --git a/Source/Genes/Genitalia/GenitaliaUtility.cs b/Source/Genes/Genitalia/GenitaliaUtility.cs index 6a6ba79..581ba64 100644 --- a/Source/Genes/Genitalia/GenitaliaUtility.cs +++ b/Source/Genes/Genitalia/GenitaliaUtility.cs @@ -73,5 +73,48 @@ namespace RJW_Genes { return candidate.def.defName.ToLower().Contains("breast"); } + + /// + /// Returns the biggest penis of a pawn. + /// In case of a identical severity, the highest body size is returned. + /// For women, or pawns without a penis, null is returned. + /// + /// + /// The biggest penis of a pawn. Null on women or error. + public static Hediff GetBiggestPenis(Pawn pawn) + { + Hediff best = null; + var parts = Genital_Helper.get_AllPartsHediffList(pawn); + + foreach (var part in parts) + { + if (Genital_Helper.is_sex_part(part) && Genital_Helper.is_penis(part)) + { + if (best == null) best = part; + + // On a draw of size, we check the body-size. + if (part.Severity == best.Severity) { + var partSize = part.TryGetComp(); + var bestSize = part.TryGetComp(); + if (partSize == null || bestSize == null) { continue; } + + best = partSize.SizeOwner > bestSize.SizeOwner ? part : best; + } else if (part.Severity > best.Severity) { + best = part; + } + } + } + + return best; + } + + public static float GetBodySizeOfSexPart(Hediff part) + { + if (part == null || part.TryGetComp() == null) + return 0.0f; + else + return part.TryGetComp().SizeOwner; + } } + } diff --git a/Source/Rjw-Genes.csproj b/Source/Rjw-Genes.csproj index f684926..e467c9a 100644 --- a/Source/Rjw-Genes.csproj +++ b/Source/Rjw-Genes.csproj @@ -78,6 +78,7 @@ +