2023-01-20 07:40:09 +00:00
using System.Collections.Generic ;
2022-12-25 11:38:05 +00:00
using Verse ;
using RimWorld ;
namespace RJW_Genes
{
public class Gene_Aphrodisiac_Pheromones : Gene
2023-02-21 07:25:48 +00:00
{
// Default XML Setting is that it looses 4 Severity per day - so a "fully libido" gives 6h boost.
// This means that adding +.25 equals 1.5h of Libido.
// Tick Speed is hence set to 0.5h
const int APHRODISIAC_DISTANCE = 25 ;
const int TICK_INTERVAL = 60000 / 48 ; // 60k = 1 day, we want 0.5h which is 1/48th of 1 day.
const float SEXFREQ_THRESHOLD = 0.5f ;
2022-12-27 13:54:47 +00:00
2023-01-20 07:40:09 +00:00
// Summary: once every one hour check for all pawns nearby and in line of sight (same room) and add/renew a hediff which lasts for 1 hour.
2022-12-25 11:38:05 +00:00
public override void Tick ( )
{
base . Tick ( ) ;
2023-02-21 07:25:48 +00:00
if ( this . pawn . IsHashIntervalTick ( TICK_INTERVAL ) & & this . pawn . Map ! = null )
2022-12-25 11:38:05 +00:00
{
2023-01-20 07:40:09 +00:00
// Only spread pheromones if sexdrive above 1
2023-01-06 11:42:04 +00:00
float sexfrequency = this . pawn . GetStatValue ( StatDef . Named ( "SexFrequency" ) ) ;
2023-02-21 07:25:48 +00:00
if ( sexfrequency > SEXFREQ_THRESHOLD )
2023-01-06 11:42:04 +00:00
{
foreach ( Pawn pawn in this . AffectedPawns ( this . pawn . Position , this . pawn . Map ) )
{
2023-02-21 07:25:48 +00:00
this . InduceAphrodisiac ( pawn ) ;
2023-01-06 11:42:04 +00:00
}
}
2022-12-25 11:38:05 +00:00
}
}
2023-01-20 07:40:09 +00:00
// Creates an IEnumerable of all pawns which are closeby and in lineofsight, self and other pawns with aphrodisiac pheromones gene are skipped (to prevent loops).
2022-12-25 11:38:05 +00:00
private IEnumerable < Pawn > AffectedPawns ( IntVec3 pos , Map map )
{
foreach ( Pawn pawn in map . mapPawns . AllPawns )
{
2023-01-20 07:40:09 +00:00
if ( pawn ! = null & & this . pawn ! = null & & pawn ! = this . pawn
2023-02-21 07:25:48 +00:00
& & pos . DistanceTo ( pawn . Position ) < APHRODISIAC_DISTANCE & & GenSight . LineOfSight ( pos , pawn . Position , pawn . Map )
2023-01-20 07:40:09 +00:00
& & ! GeneUtility . HasGeneNullCheck ( pawn , GeneDefOf . rjw_genes_aphrodisiac_pheromones ) )
2022-12-25 11:38:05 +00:00
{
yield return pawn ;
}
}
2023-01-20 07:40:09 +00:00
2022-12-25 11:38:05 +00:00
yield break ;
}
2023-02-21 07:25:48 +00:00
private void InduceAphrodisiac ( Pawn pawn )
2022-12-25 11:38:05 +00:00
{
2023-02-21 07:25:48 +00:00
Hediff aphrodisiac = pawn . health . hediffSet . GetFirstHediffOfDef ( HediffDefOf . rjw_genes_aphrodisiac_pheromone ) ;
2023-01-06 11:42:04 +00:00
2023-02-21 07:25:48 +00:00
if ( aphrodisiac ! = null )
2022-12-25 11:38:05 +00:00
{
2023-02-21 07:25:48 +00:00
aphrodisiac . Severity + = 0.25f ;
2022-12-25 11:38:05 +00:00
}
else
{
2023-02-21 07:25:48 +00:00
aphrodisiac = HediffMaker . MakeHediff ( HediffDefOf . rjw_genes_aphrodisiac_pheromone , pawn ) ;
aphrodisiac . Severity = 0.5f ;
pawn . health . AddHediff ( aphrodisiac ) ;
2022-12-25 11:38:05 +00:00
}
}
2023-01-06 11:42:04 +00:00
2022-12-25 11:38:05 +00:00
}
}