using System.Collections.Generic; using System.Linq; using Verse; using Verse.AI; using Verse.AI.Group; using RimWorld; using rjw; using UnityEngine; using HarmonyLib; namespace Privacy_Please { public static class SexInteractionUtility { public static bool PawnCaughtLovinByWitness(Pawn pawn, Pawn witness) { if (witness == null || pawn == witness || witness.IsUnableToSenseSex() || witness.CanSee(pawn) == false) return false; List sexParticipants = pawn.GetAllSexParticipants(); bool witnessIsJoiningSex = witness.jobs.curDriver is JobDriver_SexBaseInitiator && sexParticipants.Contains((witness.jobs.curDriver as JobDriver_SexBaseInitiator).Partner); if (sexParticipants.Contains(witness) || witnessIsJoiningSex) return false; return true; } public static bool PawnWorriesAboutSexWitness(Pawn pawn, Pawn witness) { JobDriver_Sex jobDriver = pawn.jobs.curDriver as JobDriver_Sex; if (pawn.IsUnableToSenseSex() || pawn.AnimalOrWildMan() || pawn.RaceProps.IsMechanoid || pawn.Faction.HostileTo(Faction.OfPlayer)) return false; if (BasicSettings.rapeIsUninteruptable && jobDriver?.Sexprops.isRape == true) return true; if (witness.HostileTo(pawn)) return true; if (witness.RaceProps.Animal || witness.RaceProps.IsMechanoid) return false; if (pawn.Drafted == true || pawn.mindState?.duty?.def?.alwaysShowWeapon == true) return false; if (BasicSettings.slavesIgnoreSex && (pawn.IsPrisoner || pawn.IsSlave || witness.IsPrisoner || witness.IsSlave)) return false; if (BasicSettings.otherFactionsIgnoreSex && (pawn.Faction.IsPlayer == false || witness.Faction.IsPlayer == false)) return false; if (BasicSettings.whoringIsUninteruptable && jobDriver?.Sexprops.isWhoring == true) return true; return true; } public static bool PawnIsCheatingOnPartner(Pawn pawn, Pawn partner) { List spouses = pawn.GetSpouses(false); if (BasicSettings.worryAboutInfidelity == false || partner.IsLoverOfOther(pawn) == false || pawn.HasTrait("Polygamous") || partner.HasTrait("Polygamous") || partner.IsMasturbating() || partner.IsHavingSex() == false || SexActIsXenophilia(partner.jobs.curDriver as JobDriver_Sex) || SexActIsBestiality(partner.jobs.curDriver as JobDriver_Sex) || partner.GetAllSexParticipants().Contains(pawn) || (spouses.NullOrEmpty() == false && partner.GetAllSexParticipants().Any(x => spouses.Contains(x)))) { return false; } return true; } public static bool SexParticipantsIncludesACheatingPartner(Pawn pawn, List participants) { foreach (Pawn participant in participants) { if (PawnIsCheatingOnPartner(pawn, participant)) { return true; } } return false; } public static bool PasserbyCanBePropositionedForSex(Pawn passerby, List participants) { if (passerby == null || participants.Contains(passerby) || participants.Any(x => x.CanSee(passerby) == false)) { return false; } if (participants.Count > 2 || participants.Any(x => x.IsForbidden(passerby) || x.HostileTo(passerby)) || CasualSex_Helper.CanHaveSex(passerby) == false || xxx.IsTargetPawnOkay(passerby) == false) { return false; } if (SexUtility.ReadyForHookup(passerby) && (passerby?.jobs?.curJob == null || (passerby.jobs.curJob.playerForced == false && CasualSex_Helper.quickieAllowedJobs.Contains(passerby.jobs.curJob.def))) && participants.Any(x => SexAppraiser.would_fuck(x, passerby) > 0.1f && SexAppraiser.would_fuck(passerby, x) > 0.1f) && participants.All(x => SexAppraiser.would_fuck(x, passerby, false, false, true) > 0.1f && SexAppraiser.would_fuck(passerby, x, false, false, true) > 0.1f)) { return true; } return false; } public static void GetReactionsToSexDiscovery(JobDriver_Sex jobDriver, Pawn witness, out ReactionToSexDiscovery reactionOfPawn, out ReactionToSexDiscovery reactionOfWitness, bool applyThoughtDefs = false) { Pawn pawn = jobDriver.pawn; reactionOfPawn = ReactionToSexDiscovery.Acceptance; reactionOfWitness = ReactionToSexDiscovery.Acceptance; // Determine if there are any issues with the sex event and the witness' morals foreach (SexActReactionDef sexActReactionDef in DefDatabase.AllDefs) { var methodInfo = AccessTools.Method(typeof(SexInteractionUtility), sexActReactionDef.sexActCheck, null, null); if (methodInfo == null) { DebugMode.Message("Method '" + sexActReactionDef.sexActCheck + "' was not found"); continue; } if ((bool)methodInfo.Invoke(null, new object[] { jobDriver })) { sexActReactionDef.DetermineReactionOfPawns(pawn, witness, out reactionOfPawn, out reactionOfWitness, applyThoughtDefs); } } // Exit here if thoughtDefs are not being applied if (applyThoughtDefs == false) return; // Panic reaction if (reactionOfWitness == ReactionToSexDiscovery.Panic) { Job job = JobMaker.MakeJob(JobDefOf.FleeAndCower, CellFinderLoose.GetFleeDest(witness, new List() { pawn }, 24f), pawn); witness.jobs.EndCurrentJob(JobCondition.InterruptForced, false, false); witness.jobs.StartJob(job); } // Vomit reaction else if (reactionOfWitness == ReactionToSexDiscovery.Nausea) { Job jobVomit = JobMaker.MakeJob(JobDefOf.Vomit); Job jobFlee = JobMaker.MakeJob(JobDefOf.FleeAndCower, CellFinderLoose.GetFleeDest(witness, new List() { pawn }, 24f), pawn); witness.jobs.EndCurrentJob(JobCondition.InterruptForced, false, false); if (Random.value <= 0.25f) { witness.jobs.StartJob(jobVomit); witness.jobs.jobQueue.EnqueueFirst(jobFlee); } else { witness.jobs.StartJob(jobFlee); } } } public static bool SexActIsNecrophilia(JobDriver_Sex jobDriver) { return jobDriver.Partner != null && jobDriver.Partner.Dead; } public static bool SexActIsBestiality(JobDriver_Sex jobDriver) { return jobDriver.Partner != null && jobDriver.Partner.RaceProps.Animal; } public static bool SexActIsRape(JobDriver_Sex jobDriver) { return jobDriver is JobDriver_Rape || jobDriver is JobDriver_RapeEnemy || jobDriver is JobDriver_SexBaseRecieverRaped; } public static bool SexActIsXenophilia(JobDriver_Sex jobDriver) { return jobDriver.Partner != null && jobDriver.Partner.def.defName != jobDriver.pawn.def.defName; } public static bool SexActIsMasturbation(JobDriver_Sex jobDriver) { return jobDriver.pawn.IsMasturbating(); } public static bool SexActIsExhibitionism(JobDriver_Sex jobDriver) { return jobDriver.pawn.IsHavingSex(); } public static bool SexActIsInfidelity(JobDriver_Sex jobDriver) { return jobDriver.pawn.IsHavingSex(); } } }