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

namespace rjw
{
	public class HediffComp_GrowsWithOwner : HediffComp
	{
		public float lastOwnerSize = -1;

		public float lastCheckTick = 0;

		public HediffCompProperties_GrowsWithOwner Props => (HediffCompProperties_GrowsWithOwner)props;

		public override void CompPostTick(ref float severityAdjustment)
		{
			var thisTick = Find.TickManager.TicksGame;

			//change size for growing pawn/child
			if ((thisTick - lastCheckTick) >= GenDate.TicksPerDay)
			{
				//change pawn parts sizes for kids(?)
				//update size if pawn bodysize changed from last check
				if (Pawn.BodySize != lastOwnerSize)
				{
					var partComp = parent.TryGetComp<HediffComp_SexPart>();
					if (partComp != null && (!partComp.isTransplant || Props.evenIfTransplanted))
					{
						partComp.UpdateSeverity(); // update/reset part size
						lastOwnerSize = Pawn.BodySize;
					}
				}
				lastCheckTick = thisTick;
			}
		}

		public override void CompExposeData()
		{
			base.CompExposeData();

			Scribe_Values.Look(ref lastOwnerSize, "lastOwnerSize");
			Scribe_Values.Look(ref lastCheckTick, "lastCheckTick");
		}
	}
}