rimworld-animations/Patch_SexToysMasturbation/Source/Patches/HarmonyPatch_JobDriver_SexBaseInitiator.cs

76 lines
2.3 KiB
C#
Raw Normal View History

2022-01-25 02:17:49 +00:00
using HarmonyLib;
using Rimworld_Animations;
using rjw;
using RJW_ToysAndMasturbation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace Patch_SexToysMasturbation
{
[HarmonyPatch(typeof(JobDriver_SexBaseInitiator), "Start")]
public class HarmonyPatch_JobDriver_SexBaseInitiator
{
public static void Postfix(ref JobDriver_SexBaseInitiator __instance)
{
if(__instance is JobDriver_MasturbateWithToy masturbateJobDriver)
{
2022-01-25 20:34:53 +00:00
2022-01-25 02:17:49 +00:00
Log.Message("Rerolling animations...");
Pawn pawn = masturbateJobDriver.pawn;
Thing sexToy = masturbateJobDriver.dildo;
2022-01-25 20:34:53 +00:00
RerollAnimationsForSexToy(pawn, sexToy, masturbateJobDriver.Bed);
2022-01-25 02:17:49 +00:00
}
}
2022-01-25 20:34:53 +00:00
public static void RerollAnimationsForSexToy(Pawn pawn, Thing thing, Thing bed)
2022-01-25 02:17:49 +00:00
{
CompSexToy sextoy = thing.TryGetComp<CompSexToy>();
SexToyAnimationDef anim = AnimSexToyUtility.tryFindAnimation(sextoy, pawn);
if (anim != null)
{
Log.Message("Playing anim " + anim.defName);
2022-01-25 20:34:53 +00:00
if(bed != null)
{
pawn.TryGetComp<CompBodyAnimator>().setAnchor(bed);
thing.TryGetComp<CompThingAnimator>().setAnchor(bed);
}
else
{
pawn.TryGetComp<CompBodyAnimator>().setAnchor(pawn.Position);
thing.TryGetComp<CompThingAnimator>().setAnchor(pawn.Position);
}
bool mirror = GenTicks.TicksGame % 2 == 0;
2022-01-25 02:17:49 +00:00
2022-01-25 20:34:53 +00:00
pawn.TryGetComp<CompBodyAnimator>().StartAnimation(anim, new List<Pawn> { pawn }, 0, mirror);
thing.TryGetComp<CompThingAnimator>().StartAnimation(anim, pawn, mirror);
2022-01-25 02:17:49 +00:00
(pawn.jobs.curDriver as JobDriver_Sex).ticks_left = anim.animationTimeTicks;
(pawn.jobs.curDriver as JobDriver_Sex).sex_ticks = anim.animationTimeTicks;
(pawn.jobs.curDriver as JobDriver_Sex).duration = anim.animationTimeTicks;
}
else
{
Log.Message("No animation found");
}
}
}
}