mirror of
https://gitgud.io/c0ffeeeeeeee/rjw-events.git
synced 2024-08-14 23:57:42 +00:00
103 lines
2.1 KiB
C#
103 lines
2.1 KiB
C#
using RimWorld;
|
|
using rjw;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Verse;
|
|
using Verse.AI;
|
|
using Verse.AI.Group;
|
|
|
|
namespace RJW_Events
|
|
{
|
|
|
|
|
|
public class JobGiver_FindOrgyPartner : ThinkNode_JobGiver
|
|
{
|
|
|
|
protected override Job TryGiveJob(Pawn pawn)
|
|
{
|
|
if (!RJWHookupSettings.HookupsEnabled)
|
|
{
|
|
return null;
|
|
}
|
|
if (pawn.Drafted)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Pawn_MindState mindState = pawn.mindState;
|
|
DutyDef dutyDef;
|
|
if (mindState == null)
|
|
{
|
|
dutyDef = null;
|
|
}
|
|
else
|
|
{
|
|
PawnDuty duty = mindState.duty;
|
|
dutyDef = ((duty != null) ? duty.def : null);
|
|
}
|
|
if (dutyDef == DutyDefOf.TravelOrLeave)
|
|
{
|
|
if (RJWSettings.DebugLogJoinInBed)
|
|
{
|
|
ModLog.Message("JoinInBed.TryGiveJob:(" + xxx.get_pawnname(pawn) + "): has TravelOrLeave, no time for lovin!");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
if (!CasualSex_Helper.CanHaveSex(pawn))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
List<Pawn> targets = LordUtility.GetLord(pawn).ownedPawns;
|
|
|
|
Pawn pawn2 = null;
|
|
if(!BestPawnForOrgyExists(pawn, targets, out pawn2))
|
|
{
|
|
return null;
|
|
}
|
|
if (pawn2 == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (pawn2.jobs.curDriver is JobDriver_SexBaseInitiator)
|
|
{
|
|
pawn2 = (Pawn)pawn2.CurJob.targetA;
|
|
}
|
|
else if (pawn.CurJob != null && pawn.jobs.curDriver != null)
|
|
{
|
|
pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced);
|
|
}
|
|
return JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("OrgySex", true), pawn2);
|
|
}
|
|
|
|
public bool BestPawnForOrgyExists(Pawn pawn1, List<Pawn> targets, out Pawn result)
|
|
{
|
|
if(targets.TryRandomElementByWeight((Pawn p) => {
|
|
|
|
if (p == pawn1) return 0;
|
|
float chance = pawn1.relations.SecondaryRomanceChanceFactor(p);
|
|
if(!(p.jobs.curDriver is JobDriver_Sex))
|
|
{
|
|
//higher chance if person is doing nothing
|
|
chance *= 3f;
|
|
}
|
|
return chance;
|
|
|
|
}, out Pawn option)) {
|
|
result = option;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
result = null;
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|