/// <summary> /// Daylight occurs when glow levels rise above 60%. /// I used a stopwatch to determine the average time between /// the percentage raises is about 161 ticks. /// For instance, if the current glow is 40%, 60% - 40% = 20%. /// Then 20 multiplied by 161, which yields 3220 total ticks until daylight. /// </summary> /// <param name="map"></param> /// <returns></returns> public static int DetermineTicksUntilDaylight(Map map) { int result = Int32.MaxValue; if (VampireUtility.IsSunRisingOrDaylight(map)) { int curLightLevel = (int)(GenCelestial.CurCelestialSunGlow(map) * 100); int maxLightLevel = 60; int diffLightLevel = maxLightLevel - curLightLevel; int ticksLeftForTravel = TicksBetweenLightChanges * diffLightLevel; result = ticksLeftForTravel; } return(result); }
/// <summary> /// Creates a fake path to test the number of cells in sunlight vs ticks to survive sunlight damage. /// </summary> /// <param name="dest"></param> /// <param name="pawn"></param> /// <returns></returns> public static bool CanSurviveTimeInSunlight(IntVec3 dest, Pawn pawn) { if (!VampireUtility.IsSunRisingOrDaylight(pawn.MapHeld)) { return(true); } if (!dest.IsValid) { return(false); //Avoids downed/dead/despawned pathing issues. } if (dest == pawn.PositionHeld) { if (VampireUtility.IsDaylight(pawn)) { return(false); } return(true); } PawnPath path = pawn.MapHeld.pathFinder.FindPath(pawn.PositionHeld, dest, pawn); IntVec3 curVec; int cellsInSunlight = 0; while (path.NodesLeftCount > 1) { curVec = path.ConsumeNextNode(); if (!curVec.Roofed(pawn.MapHeld)) { cellsInSunlight++; } } path.Dispose(); if (cellsInSunlight > 0) { int sunExpTicks = 0; if (pawn?.health?.hediffSet?.GetFirstHediffOfDef(VampDefOf.ROMV_SunExposure) is HediffWithComps_SunlightExposure sunExp) { sunExpTicks = (int)(TicksOfSurvivingSunlight * 0.75f * sunExp.CurStageIndex); } int ticksToArrive = cellsInSunlight * pawn.TicksPerMoveDiagonal + sunExpTicks; if (ticksToArrive > TicksOfSurvivingSunlight) { return(false); } } return(true); }