Added PheromoneSpit Gene

This commit is contained in:
Vegapnk 2024-06-01 10:12:00 +02:00
parent 48e06ff97f
commit a68c263aa1
7 changed files with 171 additions and 31 deletions

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<AbilityDef>
<defName>rjw_genes_ability_pheromone_spit</defName>
<label>pheromone spit</label>
<description>Spit a condensed ball of animal pheromones to mark a target. Nearby Animals will try to breed the target. This means all animals - hostile, friendly and wild.</description>
<iconPath>UI/Abilities/PiercingSpine</iconPath>
<cooldownTicksRange>3000</cooldownTicksRange>
<displayOrder>201</displayOrder>
<aiCanUse>true</aiCanUse>
<verbProperties>
<verbClass>Verb_CastAbility</verbClass>
<range>11</range>
<warmupTime>1.2</warmupTime>
<soundCast>PiercingSpine_Launch</soundCast>
<targetParams>
<canTargetHumans>True</canTargetHumans>
<canTargetMechs>False</canTargetMechs>
<canTargetAnimals>False</canTargetAnimals>
<canTargetLocations>False</canTargetLocations>
</targetParams>
</verbProperties>
<comps>
<li Class="RJW_Genes.CompProperties_AbilityPheromoneSpit">
<calldistance>25</calldistance>
</li>
</comps>
</AbilityDef>
</Defs>

View file

@ -94,4 +94,21 @@
<biostatMet>-1</biostatMet>
</GeneDef>
<GeneDef ParentName="BreedingBase">
<defName>rjw_genes_pheromone_spit</defName>
<label>Pheromone Spit</label>
<description>This gene allows to mark targets for breeding, enticing nearby animals for a ride.</description>
<iconPath>UI/Abilities/AnimalBerserkPulse</iconPath>
<displayOrderInCategory>66</displayOrderInCategory>
<abilities>
<li>rjw_genes_ability_pheromone_spit</li>
</abilities>
<descriptionHyperlinks>
<AbilityDef>rjw_genes_ability_pheromone_spit</AbilityDef>
</descriptionHyperlinks>
<biostatCpx>2</biostatCpx>
<biostatMet>-1</biostatMet>
</GeneDef>
</Defs>

View file

@ -28,37 +28,9 @@ namespace RJW_Genes
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
DoAnimalBreedingPulse();
ModLog.Message($"{this.parent.pawn} is casting MatingCall");
AnimalBreedingHelper.DoAnimalBreedingPulse(this.parent.pawn, Props.calldistance);
}
private void DoAnimalBreedingPulse()
{
if (fired) { return; }
IEnumerable<Pawn> animals = this.parent.pawn.Map.mapPawns.AllPawnsSpawned.Where<Pawn>((Func<Pawn, bool>)(p => p.IsNonMutantAnimal && p.Position.InHorDistOf(this.parent.pawn.Position, Props.calldistance)));
int breeder_counter = 0;
foreach (Pawn animal in animals)
{
if (animal.MentalState != null && (animal.MentalState.def == MentalStateDefOf.Manhunter || animal.MentalState.def == MentalStateDefOf.ManhunterPermanent))
{
Log.Warning("Found an angry Animal to Fuck");
animal?.MentalState?.RecoverFromState();
}
if(xxx.is_healthy_enough(animal))
{
// Stopping all Jobs in this way is a bit heavy - but as it's only about Animals this should be fine.
animal.jobs.CaptureAndClearJobQueue();
animal.jobs.StopAll();
Job job = JobMaker.MakeJob(xxx.animalBreed, this.parent.pawn);
animal.jobs.TryTakeOrderedJob(job);
breeder_counter++;
}
}
ModLog.Message($"{breeder_counter} of {animals.Count()} Animals in range are trying to breed {this.parent.pawn}");
fired = true;
}
}
}

View file

@ -0,0 +1,31 @@
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;
namespace RJW_Genes
{
public class CompAbilityEffect_PheromoneSpit : CompAbilityEffect
{
bool fired = false;
private new CompProperties_AbilityPheromoneSpit Props
{
get
{
return (CompProperties_AbilityPheromoneSpit)this.props;
}
}
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
AnimalBreedingHelper.DoAnimalBreedingPulse(target.Pawn, Props.calldistance);
}
}
}

View file

@ -0,0 +1,18 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RJW_Genes {
public class CompProperties_AbilityPheromoneSpit : CompProperties_AbilityEffect
{
public int calldistance;
public CompProperties_AbilityPheromoneSpit()
{
this.compClass = typeof(CompAbilityEffect_PheromoneSpit);
}
}
}

View file

@ -0,0 +1,70 @@
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse.AI;
using Verse;
namespace RJW_Genes
{
public class AnimalBreedingHelper
{
/// <summary>
/// Finds animals in a distance around a pawn, and schedules a breeding job.
/// This is done regardless of the animals genitalia at the moment.
/// This function has no checks if the Pawn is hostile, downed, etc., such checks must be done upstream!
/// </summary>
/// <param name="toBeBred">The pawn that will be target of breeding animals</param>
/// <param name="pulse_distance">The range around the pawn for which animals will be triggered.</param>
public static void DoAnimalBreedingPulse(Pawn toBeBred, int pulse_distance, bool ends_manhunter = true)
{
IEnumerable<Pawn> animals = GetAnimalsInRange(toBeBred.Map, toBeBred.Position, pulse_distance);
int breeder_counter = 0;
foreach (Pawn animal in animals)
{
if (ends_manhunter)
EndManHunter(animal);
ForceBreedingJob(toBeBred, animal);
breeder_counter++;
}
ModLog.Message($"{breeder_counter} of {animals.Count()} Animals in range are trying to breed {toBeBred}");
}
private static IEnumerable<Pawn> GetAnimalsInRange(Map map, IntVec3 position, int distance)
{
IEnumerable<Pawn> animals =
map.mapPawns
.AllPawnsSpawned
.Where<Pawn>((Func<Pawn, bool>)(p =>
p.IsNonMutantAnimal
&& p.Position.InHorDistOf(position, distance)
&& xxx.is_healthy_enough(p))
);
return animals;
}
private static void ForceBreedingJob(Pawn toBeBred, Pawn animal)
{
// Stopping all Jobs in this way is a bit heavy - but as it's only about Animals this should be fine.
animal.jobs.CaptureAndClearJobQueue();
animal.jobs.StopAll();
Job job = JobMaker.MakeJob(xxx.animalBreed, toBeBred);
animal.jobs.TryTakeOrderedJob(job);
}
private static void EndManHunter(Pawn animal)
{
if (animal.MentalState != null && (animal.MentalState.def == MentalStateDefOf.Manhunter || animal.MentalState.def == MentalStateDefOf.ManhunterPermanent))
{
animal?.MentalState?.RecoverFromState();
}
}
}
}

View file

@ -65,7 +65,10 @@
<Compile Include="Common\Defs\TickIntervalExtension.cs" />
<Compile Include="Common\Patches\PatchImplants.cs" />
<Compile Include="Genes\Breeding\Abilities\CompAbilityEffect_MatingCall.cs" />
<Compile Include="Genes\Breeding\Abilities\CompAbilityEffect_PheromoneSpit.cs" />
<Compile Include="Genes\Breeding\Abilities\CompProperties_AbilityMatingCall.cs" />
<Compile Include="Genes\Breeding\Abilities\CompProperties_AbilityPheromoneSpit.cs" />
<Compile Include="Genes\Breeding\AnimalBreedingHelper.cs" />
<Compile Include="Genes\Breeding\Genes\Gene_FerventOvipositor.cs" />
<Compile Include="Genes\Breeding\Genes\Gene_InsectIncubator.cs" />
<Compile Include="Genes\Damage\Gene_Elasticity.cs" />