replaced compinducelactation with hediffcomp; cleaner

todo:
add abilitydef to hucow handler to begin inducing lactation; give lactation induction hediff to recipient pawn
add thoughtdef w/ thoughtworker_hediff to give pawns thoughts on inducing lactation
This commit is contained in:
c0ffee 2022-10-14 18:10:00 -07:00
parent 1d6ecb3f95
commit 5b4b203d13
19 changed files with 233 additions and 70 deletions

View file

@ -1,23 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using rjw;
using Milk;
using UnityEngine;
namespace CRIALactation
{
public class CompProperties_InduceLactation : CompProperties
{
public CompProperties_InduceLactation()
{
this.compClass = typeof(CompInduceLactation);
}
public float DaysToLactating = 15;
public float TimesMassagedADay = 2.5f;
}
}

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using rjw;
using Milk;
using UnityEngine;
namespace CRIALactation
{
public class CompProperties_Lactation : CompProperties
{
public CompProperties_Lactation()
{
this.compClass = typeof(CompLactation);
}
//public float DaysToLactating = 15;
//public float TimesMassagedADay = 2.5f;
}
}

View file

@ -0,0 +1,28 @@
using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace CRIALactation
{
public class CompAbilityEffect_BeginInducingLactation : CompAbilityEffect
{
public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
{
Pawn pawn = target.Pawn;
if (pawn == null) return false;
if (!pawn.IsColonistPlayerControlled || !pawn.IsSlaveOfColony || !pawn.IsPrisonerOfColony) return false;
if (LactationUtility.IsLactating(pawn)) return false;
return true;
}
}
}

View file

@ -10,7 +10,20 @@ using UnityEngine;
namespace CRIALactation
{
public class CompInduceLactation : ThingComp
public class CompLactation : ThingComp
{
public int lastHumanLactationIngestedTick = 0;
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look<int>(ref this.lastHumanLactationIngestedTick, "lastHumanLactationIngestedTick", 0);
}
}
/*
public class CompLactation : ThingComp
{
private readonly int OneDayInTicks = 60000;
private int TicksSinceLastMassage = -60000;
@ -124,4 +137,6 @@ namespace CRIALactation
return result;
}
}
}
*/
}

View file

@ -17,8 +17,8 @@ namespace CRIALactation
if(__instance?.def == ThingDefOf_Milk.HumanMilk || __instance?.def == ThingDefOf_Milk.HumanoidMilk)
{
if (ingester.TryGetComp<CompInduceLactation>() == null) return;
ingester.TryGetComp<CompInduceLactation>().lastHumanLactationIngestedTick = Find.TickManager.TicksGame;
if (ingester.TryGetComp<CompLactation>() == null) return;
ingester.TryGetComp<CompLactation>().lastHumanLactationIngestedTick = Find.TickManager.TicksGame;
}
}

View file

@ -19,6 +19,9 @@ namespace CRIALactation
public static HediffDef Lactating_Permanent;
public static HediffDef Heavy_Lactating_Permanent;
public static HediffDef Lactating_Natural;
public static HediffDef InducingLactation;
public static HediffDef Hucow;

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace CRIALactation
{
public class HediffCompProperties_LactationInduction : HediffCompProperties
{
public HediffCompProperties_LactationInduction()
{
this.compClass = typeof(HediffComp_LactationInduction);
}
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace CRIALactation
{
public class HediffComp_LactationInduction : HediffComp
{
private readonly int OneDayInTicks = 60000;
private float TimesMassagedADay = 2.5f;
private int tickLastMassaged = 0, DaysToLactating = 15;
public void massage(Pawn massager)
{
this.parent.Severity += (float)1 / (DaysToLactating * (TimesMassagedADay + Rand.Value));
}
public bool canMassage()
{
return tickLastMassaged + OneDayInTicks / TimesMassagedADay < GenTicks.TicksGame;
}
public override void CompExposeData()
{
Scribe_Values.Look<int>(ref this.tickLastMassaged, "lastLactationInductionMassagedTick", 0);
base.CompExposeData();
}
}
}

View file

@ -28,6 +28,7 @@ namespace CRIALactation
Toil massage = new Toil();
massage.FailOnDespawnedOrNull(TargetIndex.A);
massage.FailOnAggroMentalStateAndHostile(TargetIndex.A);
float massageProgress = 0;
massage.initAction = delegate
{
Pawn p = job.GetTarget(TargetIndex.A).Thing as Pawn;
@ -46,14 +47,9 @@ namespace CRIALactation
Pawn p = job.GetTarget(TargetIndex.A).Thing as Pawn;
if (massageProgress >= WorkTotal)
{
p.TryGetComp<CompInduceLactation>().MassageBreasts();
p.health.hediffSet.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation).TryGetComp<HediffComp_LactationInduction>().massage(pawn);
return JobCondition.Succeeded;
}
if (!(p.TryGetComp<CompInduceLactation>().isActive && p.TryGetComp<CompInduceLactation>().CanMassage))
{
return JobCondition.Incompletable;
}
return JobCondition.Ongoing;
@ -74,7 +70,5 @@ namespace CRIALactation
yield break;
}
float massageProgress = 0f;
}
}

View file

@ -55,13 +55,10 @@ namespace CRIALactation
public static bool isMassageable(Pawn p)
{
CompInduceLactation c = p.TryGetComp<CompInduceLactation>();
if (c != null && c.isActive && c.CanMassage)
{
return true;
}
Hediff lactationInductionHediff = p.health?.hediffSet?.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation);
if (lactationInductionHediff == null) return false;
return false;
return true;
}

View file

@ -18,7 +18,7 @@ namespace CRIALactation
protected override ThoughtState ShouldHaveThought(Pawn p)
{
int num = Mathf.Max(0, p.TryGetComp<CompInduceLactation>().lastHumanLactationIngestedTick);
int num = Mathf.Max(0, p.TryGetComp<CompLactation>().lastHumanLactationIngestedTick);
return Find.TickManager.TicksGame - num > 480000 && !LactationUtility.IsHucow(p);
}

View file

@ -36,13 +36,15 @@ namespace CRIALactation
public override bool HasJobOnThing(Pawn p, Thing t, bool forced = false)
{
Pawn pawn2 = t as Pawn;
if(pawn2?.TryGetComp<CompInduceLactation>() == null)
if(pawn2?.health?.hediffSet.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation) == null)
{
return false;
}
CompInduceLactation c = pawn2.TryGetComp<CompInduceLactation>();
Hediff lactationInductionHediff = pawn2?.health?.hediffSet?.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation);
if (lactationInductionHediff == null) return false;
return p != pawn2 && c.isActive && c.CanMassage && !pawn2.Downed && !pawn2.Drafted && !pawn2.InAggroMentalState && !pawn2.IsFormingCaravan() && pawn2.CanCasuallyInteractNow(false, true, false) && p.CanReserve(pawn2, 1, -1, null, forced);
HediffComp_LactationInduction lactInductComp = lactationInductionHediff.TryGetComp<HediffComp_LactationInduction>();
return p != pawn2 && lactInductComp.canMassage() && !pawn2.Downed && !pawn2.Drafted && !pawn2.InAggroMentalState && !pawn2.IsFormingCaravan() && pawn2.CanCasuallyInteractNow(false, true, false) && p.CanReserve(pawn2, 1, -1, null, forced);
}