using System;
using System.Collections.Generic;
using Verse;
using Verse.AI;
using RimWorld;
using rjw;

namespace SCE
{
    /* A duplicate implementation of JobDriver_SexBaseReceiverLoved.
     * Necessary as sibling class only checks against hardcoded JobDefs
     * for some inexplicable reason and MakeSexToils is private for some
     * equally inexplicable reason, so I need to duplicate both of its 
     * methods anyway. One of these days I'm just going to submit a PR 
     * that tears that whole class tree out and reimplements it,
     * compatibility and short term bugginess be damned. It probably
     * wouldn't be accepted, but ridiculous fantasies like this are a 
     * natural response to the fantastical ridiculousness that is RJW.
     */
    public class JobDriver_SexBaseReceiverPartiallyUnfucked : JobDriver_SexBaseReciever
    {
        // First order of business
        public List<Pawn> partners { get => parteners; set => parteners = value; }

        public Job partnerJob;

        protected override IEnumerable<Toil> MakeNewToils()
        {
            setup_ticks();
            partners.Add(Partner);

            if (!(Partner.jobs.curDriver is JobDriver_SexBaseInitiator driver && driver.Sexprops.isRape))
            {
                int opinionOfPartner = pawn.relations.OpinionOf(Partner);
                if (opinionOfPartner < 0)
                    ticks_between_hearts += 50;
                else if (opinionOfPartner > 60)
                    ticks_between_hearts -= 25;
            }

            partnerJob = Partner.CurJob;
            
            this.FailOnDespawnedOrNull(iTarget);
			this.FailOn(() => !Partner.health.capacities.CanBeAwake);
			this.FailOn(() => pawn.Drafted);
			this.FailOn(() => Partner.Drafted);
            this.FailOn(() => Partner.CurJobDef == null);

            yield return Toils_Reserve.Reserve(iTarget, 1, 0);

            yield return Toils_Sex.SexToilReceiver(this);
        }
        
        public override void ExposeData()
        {
            base.ExposeData();
            Scribe_References.Look(ref partnerJob, "partnerJob");
        }
    }
}