mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Added a Lifeforce Empath Gene
This commit is contained in:
parent
d5580ba92a
commit
507c150b38
5 changed files with 171 additions and 3 deletions
19
Source/Genes/Life_Force/Defs/LifeForceEmpathExtension.cs
Normal file
19
Source/Genes/Life_Force/Defs/LifeForceEmpathExtension.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
public class LifeForceEmpathExtension : DefModExtension
|
||||
{
|
||||
public int tickInterval;
|
||||
public int empathDistance;
|
||||
|
||||
public float aheagoIncrement;
|
||||
public float satisfactionIncrement;
|
||||
public float frustratedDecrement;
|
||||
}
|
||||
}
|
118
Source/Genes/Life_Force/Genes/Gene_LifeForce_Empath.cs
Normal file
118
Source/Genes/Life_Force/Genes/Gene_LifeForce_Empath.cs
Normal file
|
@ -0,0 +1,118 @@
|
|||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
public class Gene_LifeForce_Empath : Gene
|
||||
{
|
||||
|
||||
const int EMPATH_DISTANCE_FALLBACK = 25;
|
||||
const int TICK_INTERVAL_FALLBACK = 60000 / 48;
|
||||
|
||||
const float AHEAGO_FALLBACK = 0.02f, SATISFIED_FALLBACK = 0.01f, FRUSTRATED_FALLBACK = -0.01f;
|
||||
|
||||
int empathDistance = 25;
|
||||
int tickInterval = 60000 / 48 ; // 60k = 1 day, we want 0.5h which is 1/48th of 1 day.
|
||||
|
||||
float aheagoIncrement = 0.02f;
|
||||
float satisfiedIncrement = 0.01f;
|
||||
float frustratedDecrement = -0.01f;
|
||||
|
||||
|
||||
Gene_LifeForce_Empath() : base()
|
||||
{
|
||||
SetValuesFromExtension();
|
||||
}
|
||||
|
||||
private void SetValuesFromExtension()
|
||||
{
|
||||
LifeForceEmpathExtension empathExt = GeneDefOf.rjw_genes_lifeforce_empath.GetModExtension<LifeForceEmpathExtension>();
|
||||
|
||||
tickInterval = empathExt?.tickInterval ?? TICK_INTERVAL_FALLBACK;
|
||||
empathDistance = empathExt?.empathDistance ?? EMPATH_DISTANCE_FALLBACK;
|
||||
|
||||
aheagoIncrement = empathExt?.aheagoIncrement ?? AHEAGO_FALLBACK;
|
||||
satisfiedIncrement = empathExt?.satisfactionIncrement ?? SATISFIED_FALLBACK;
|
||||
frustratedDecrement = empathExt?.frustratedDecrement ?? FRUSTRATED_FALLBACK;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
base.Tick();
|
||||
if (this.pawn.IsHashIntervalTick(tickInterval) && this.pawn.Map != null)
|
||||
{
|
||||
foreach (Pawn pawn in this.AffectedPawns(this.pawn.Position, this.pawn.Map))
|
||||
{
|
||||
this.FarmLifeForce(pawn);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an IEnumerable of all pawns which are closeby and in lineofsight, self and other pawns with lifeforce gene are skipped (to prevent loops).
|
||||
/// </summary>
|
||||
/// <param name="pos">The position of the empath on the map</param>
|
||||
/// <param name="map">The map the empath is on</param>
|
||||
/// <returns>A list of all pawns that are close enough for the empath to connect.</returns>
|
||||
private IEnumerable<Pawn> AffectedPawns(IntVec3 pos, Map map)
|
||||
{
|
||||
foreach (Pawn pawn in map.mapPawns.AllPawns)
|
||||
{
|
||||
// Return for trivial errors
|
||||
if (pawn == null || this.pawn == null || pawn == this.pawn)
|
||||
continue;
|
||||
// Check for position-existance
|
||||
if (pawn.Position == null || pos == null || pawn.Map == null)
|
||||
continue;
|
||||
// Do nothing if pawn is carried
|
||||
if (pawn.CarriedBy != null)
|
||||
continue;
|
||||
// Do nothing if Pawn is Baby or Child (#25)
|
||||
if (!pawn.ageTracker.Adult)
|
||||
continue;
|
||||
// Do nothing for pawns that also have lifeforce
|
||||
if (GeneUtility.HasGeneNullCheck(pawn, GeneDefOf.rjw_genes_lifeforce))
|
||||
continue;
|
||||
|
||||
// Actual Logic:
|
||||
// Pawn qualifies in right distance and needs line of sight.
|
||||
if (pos.DistanceTo(pawn.Position) < empathDistance && GenSight.LineOfSight(pos, pawn.Position, pawn.Map))
|
||||
{
|
||||
yield return pawn;
|
||||
}
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjust the empaths lifeforce depending on the farmed pawns sexneed.
|
||||
/// </summary>
|
||||
/// <param name="farmedPawn">The pawn affecting the empath, increasing or decreasing his lifeforce. </param>
|
||||
private void FarmLifeForce(Pawn farmedPawn)
|
||||
{
|
||||
// Short rename to make rest more obvious.
|
||||
Pawn empath = pawn;
|
||||
|
||||
if (farmedPawn == null)
|
||||
return;
|
||||
|
||||
var sexneed = farmedPawn.needs.TryGetNeed<rjw.Need_Sex>();
|
||||
|
||||
// Shortwire: do nothing on no sexneed.
|
||||
if (sexneed == null)
|
||||
return;
|
||||
|
||||
if (sexneed.CurLevel >= sexneed.thresh_ahegao())
|
||||
GeneUtility.OffsetLifeForce(GeneUtility.GetLifeForceGene(empath), aheagoIncrement);
|
||||
else if (sexneed.CurLevel >= sexneed.thresh_satisfied())
|
||||
GeneUtility.OffsetLifeForce(GeneUtility.GetLifeForceGene(empath), satisfiedIncrement);
|
||||
else if (sexneed.CurLevel <= sexneed.thresh_frustrated())
|
||||
GeneUtility.OffsetLifeForce(GeneUtility.GetLifeForceGene(empath), frustratedDecrement);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue