2021-07-30 01:33:08 +00:00
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
{
2022-10-15 01:10:00 +00:00
public class CompLactation : ThingComp
{
public int lastHumanLactationIngestedTick = 0 ;
public override void PostExposeData ( )
{
base . PostExposeData ( ) ;
Scribe_Values . Look < int > ( ref this . lastHumanLactationIngestedTick , "lastHumanLactationIngestedTick" , 0 ) ;
}
2022-10-25 20:46:15 +00:00
public override string CompInspectStringExtra ( )
{
2023-02-06 03:05:01 +00:00
//if ((parent as Pawn).health?.hediffSet?.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation) != null
// && (parent as Pawn).health.hediffSet.GetFirstHediffOfDef(HediffDefOf_Milk.InducingLactation).TryGetComp<HediffComp_LactationInduction>().canMassage())
if ( ( parent as Pawn ) . health ? . hediffSet ? . GetFirstHediffOfDef ( HediffDefOf_Milk . InducingLactation ) ! = null
& & ( parent as Pawn ) . health . hediffSet . GetFirstHediffOfDef ( HediffDefOf_Milk . InducingLactationCooldown ) = = null )
2022-10-25 20:46:15 +00:00
{
return "Ready to stimulate breasts for lactation." ;
}
else
{
return "" ;
}
}
2022-10-15 01:10:00 +00:00
}
/ *
public class CompLactation : ThingComp
2021-07-30 01:33:08 +00:00
{
private readonly int OneDayInTicks = 60000 ;
private int TicksSinceLastMassage = - 60000 ;
private float InductionCompletionPercent = 0f ;
2021-11-17 17:59:06 +00:00
2021-07-30 01:33:08 +00:00
public bool isActive = false ;
public bool CanMassage = true ;
2021-11-17 17:59:06 +00:00
public int lastHumanLactationIngestedTick = 0 ;
2021-07-30 01:33:08 +00:00
public override void CompTick ( )
{
base . CompTick ( ) ;
Pawn p = this . parent as Pawn ;
if ( ! p . IsHashIntervalTick ( 100 ) )
{
return ;
}
2021-11-24 00:50:33 +00:00
if ( LactationUtility . IsLactating ( p ) | | ! isActive )
2021-08-02 18:55:46 +00:00
{
return ;
}
2021-07-30 01:33:08 +00:00
if ( TicksSinceLastMassage + OneDayInTicks / Props . TimesMassagedADay < GenTicks . TicksGame )
{
CanMassage = true ;
}
if ( InductionCompletionPercent > = 1 )
{
string main = p . Name . ToStringShort + "'s breasts have been stimulated enough to induce lactation! They can now begin producing milk for their colony's consumption." ;
var letter = LetterMaker . MakeLetter ( p . Name . ToStringShort + " induced lactation" , main , LetterDefOf . PositiveEvent ) ;
Find . LetterStack . ReceiveLetter ( letter ) ;
LactationUtility . StartLactating ( p , true ) ;
2021-11-24 00:50:33 +00:00
InductionCompletionPercent = 0.90f + Random . Range ( 0f , 5f ) ; //start at 90-95% in case they ever lose lactating again
2021-07-30 01:33:08 +00:00
}
}
public void MassageBreasts ( )
{
InductionCompletionPercent + = ( float ) 1 / ( Props . DaysToLactating * ( Props . TimesMassagedADay + Rand . Value ) ) ;
TicksSinceLastMassage = GenTicks . TicksGame ;
CanMassage = false ;
}
public CompProperties_InduceLactation Props
{
get
{
return ( CompProperties_InduceLactation ) props ;
}
}
public override IEnumerable < FloatMenuOption > CompFloatMenuOptions ( Pawn pawn )
{
2021-08-01 23:17:04 +00:00
if ( pawn ! = this . parent as Pawn & & ! ( ( this . parent as Pawn ) . IsSlaveOfColony | | ( this . parent as Pawn ) . IsPrisonerOfColony ) ) yield break ;
2021-07-30 01:33:08 +00:00
if ( LactationUtility . IsLactating ( pawn ) ) yield break ;
if ( LactationUtility . HasMilkableBreasts ( this . parent as Pawn ) )
{
if ( isActive )
{
//stop trying to induce lactation
2021-11-24 00:50:33 +00:00
yield return new FloatMenuOption ( "Stop inducing lactation" , ( ) = >
2021-07-30 01:33:08 +00:00
{
isActive = false ;
} ) ;
}
else
{
//induce lactation
2021-11-24 00:50:33 +00:00
yield return new FloatMenuOption ( "Start inducing lactation" , ( ) = >
2021-07-30 01:33:08 +00:00
{
isActive = true ;
} ) ;
}
}
else
{
2021-11-24 00:50:33 +00:00
yield return new FloatMenuOption ( "Start inducing lactation (no milkable breasts)" , null ) ;
2021-07-30 01:33:08 +00:00
}
yield break ;
}
public override void PostExposeData ( )
{
base . PostExposeData ( ) ;
Scribe_Values . Look < float > ( ref this . InductionCompletionPercent , "InductionCompletionPercent" , 0f ) ;
Scribe_Values . Look < int > ( ref this . TicksSinceLastMassage , "TicksSinceLastMassage" , - 60000 ) ;
2021-11-17 17:59:06 +00:00
Scribe_Values . Look < int > ( ref this . lastHumanLactationIngestedTick , "lastHumanLactationIngestedTick" , 0 ) ;
2021-07-30 01:33:08 +00:00
Scribe_Values . Look < bool > ( ref this . isActive , "IsActive" , false ) ;
Scribe_Values . Look < bool > ( ref this . CanMassage , "CanMassage" , false ) ;
}
public override string CompInspectStringExtra ( )
{
if ( ! isActive ) return null ;
string result = "Induce lactation completion: " + InductionCompletionPercent . ToStringPercent ( ) ;
if ( CanMassage )
{
result + = "\nReady to massage." ;
}
return result ;
}
}
2022-10-15 01:10:00 +00:00
* /
}