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
				
			
		| 
						 | 
				
			
			@ -201,7 +201,7 @@
 | 
			
		|||
		<description>Carriers of this gene are able to temporarily increase their strength and resilience, while they are naked.</description>
 | 
			
		||||
		<iconPath>Genes/Icons/rjw_naked_prowess</iconPath>
 | 
			
		||||
		<prerequisite>rjw_genes_lifeforce</prerequisite>
 | 
			
		||||
		<displayOrderInCategory>13</displayOrderInCategory>
 | 
			
		||||
		<displayOrderInCategory>14</displayOrderInCategory>
 | 
			
		||||
		<displayCategory>rjw_genes_fertilin</displayCategory>
 | 
			
		||||
		<abilities>
 | 
			
		||||
			<li>rjw_genes_ability_naked_prowess</li>
 | 
			
		||||
| 
						 | 
				
			
			@ -256,6 +256,34 @@
 | 
			
		|||
		</modExtensions>
 | 
			
		||||
	</GeneDef>
 | 
			
		||||
	
 | 
			
		||||
	<GeneDef>
 | 
			
		||||
		<defName>rjw_genes_lifeforce_empath</defName>
 | 
			
		||||
		<label>empathic lifeforce</label>
 | 
			
		||||
		<geneClass>RJW_Genes.Gene_LifeForce_Empath</geneClass>
 | 
			
		||||
		<description>Carriers of this gene generate lifeforce if nearby pawns are sexually satisfied. Be careful: Sexually frustrated pawns will make your empath loose lifeforce!</description>
 | 
			
		||||
		<iconPath>Genes/Icons/Hypersexual</iconPath>
 | 
			
		||||
		<prerequisite>rjw_genes_lifeforce</prerequisite>
 | 
			
		||||
		<displayOrderInCategory>3</displayOrderInCategory>
 | 
			
		||||
		<displayCategory>rjw_genes_fertilin</displayCategory>
 | 
			
		||||
		<biostatCpx>1</biostatCpx>
 | 
			
		||||
		<biostatMet>-1</biostatMet>
 | 
			
		||||
 | 
			
		||||
		<modExtensions>
 | 
			
		||||
			<li MayRequire="OskarPotocki.VanillaFactionsExpanded.Core" Class="VanillaGenesExpanded.GeneExtension">
 | 
			
		||||
				<backgroundPathEndogenes>Genes/Icons/RJW_Genes_Endogene_Background</backgroundPathEndogenes>
 | 
			
		||||
				<backgroundPathXenogenes>Genes/Icons/RJW_Genes_Xenogene_Background</backgroundPathXenogenes>
 | 
			
		||||
			</li>
 | 
			
		||||
			<li Class="RJW_Genes.LifeForceEmpathExtension">
 | 
			
		||||
				<!-- One day has 60k ticks, so we check every hour with 60000/24 = 2500-->
 | 
			
		||||
				<tickInterval>2500</tickInterval>
 | 
			
		||||
				<empathDistance>25</empathDistance>
 | 
			
		||||
				<aheagoIncrement>0.02</aheagoIncrement>
 | 
			
		||||
				<satisfactionIncrement>0.01</satisfactionIncrement>
 | 
			
		||||
				<frustratedDecrement>-0.01</frustratedDecrement>
 | 
			
		||||
			</li>
 | 
			
		||||
		</modExtensions>
 | 
			
		||||
	</GeneDef>
 | 
			
		||||
 | 
			
		||||
	<GeneDef>
 | 
			
		||||
		<defName>rjw_genes_drainer</defName>
 | 
			
		||||
		<label>vitality drainer</label>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -93,9 +93,10 @@ namespace RJW_Genes
 | 
			
		|||
		public static readonly GeneDef rjw_genes_seduce;
 | 
			
		||||
		public static readonly GeneDef rjw_genes_paralysingkiss;
 | 
			
		||||
		public static readonly GeneDef rjw_genes_cockeater;
 | 
			
		||||
		public static readonly GeneDef rjw_genes_lifeforce_empath;
 | 
			
		||||
 | 
			
		||||
		// Cosmetic
 | 
			
		||||
		public static readonly GeneDef rjw_genes_succubus_tail;
 | 
			
		||||
        // Cosmetic
 | 
			
		||||
        public static readonly GeneDef rjw_genes_succubus_tail;
 | 
			
		||||
		public static readonly GeneDef rjw_genes_succubus_wings;
 | 
			
		||||
 | 
			
		||||
		// Hive 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										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);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -113,6 +113,8 @@
 | 
			
		|||
    <Compile Include="Genes\Hive\Thoughts\ThoughtWorker_QueenPresent_Social.cs" />
 | 
			
		||||
    <Compile Include="Genes\Hive\Thoughts\ThoughtWorker_RivalQueen_Social.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\Abilities\AbilityUtility.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\Defs\LifeForceEmpathExtension.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\Genes\Gene_LifeForce_Empath.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\UI\Alert_LowFertilin.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\Abilities\CompAbilityEffect_CasterIsNaked.cs" />
 | 
			
		||||
    <Compile Include="Genes\Life_Force\Abilities\CompProperties_CasterIsNaked.cs" />
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue