Added Spelopede

This commit is contained in:
Vegapnk 2023-04-18 09:06:29 +02:00
parent 697e3ba7fb
commit 6777861903
8 changed files with 171 additions and 26 deletions

View file

@ -127,26 +127,3 @@ namespace RJW_Genes
}
}
/*
Exception in Verse.AI.ThinkNode_Priority TryIssueJobPackage: System.NullReferenceException: Object reference not set to an instance of an object
at RJW_Genes.GeneUtility.HasLowLifeForce (Verse.Pawn pawn) [0x00014] in < 881b7541af8144a78a14c9dad08e43c7 >:0
at RJW_Genes.ThinkNode_ConditionalLowLifeForce.Satisfied(Verse.Pawn p) [0x00000] in < 881b7541af8144a78a14c9dad08e43c7 >:0
at Verse.AI.ThinkNode_Conditional.TryIssueJobPackage(Verse.Pawn pawn, Verse.AI.JobIssueParams jobParams) [0x00000] in < 38562b1a2ab64eacb931fb5df05ca994 >:0
at Verse.AI.ThinkNode_Priority.TryIssueJobPackage(Verse.Pawn pawn, Verse.AI.JobIssueParams jobParams) [0x00022] in < 38562b1a2ab64eacb931fb5df05ca994 >:0
UnityEngine.StackTraceUtility:ExtractStackTrace()
Verse.Log:Error(string)
Verse.AI.ThinkNode_Priority:TryIssueJobPackage(Verse.Pawn, Verse.AI.JobIssueParams)
Verse.AI.ThinkNode_SubtreesByTag:TryIssueJobPackage(Verse.Pawn, Verse.AI.JobIssueParams)
Verse.AI.ThinkNode_Priority:TryIssueJobPackage(Verse.Pawn, Verse.AI.JobIssueParams)
Verse.AI.Pawn_JobTracker:DetermineNextJob(Verse.ThinkTreeDef &)
Verse.AI.Pawn_JobTracker:TryFindAndStartJob()
Verse.AI.Pawn_JobTracker:EndCurrentJob(Verse.AI.JobCondition, bool, bool)
Verse.AI.Pawn_JobTracker:JobTrackerTick()
Verse.Pawn:Tick()
Verse.TickList:Tick()
(wrapper dynamic - method) Verse.TickManager:Verse.TickManager.DoSingleTick_Patch2(Verse.TickManager)
Verse.TickManager:TickManagerUpdate()
Verse.Game:UpdatePlay()
Verse.Root_Play:Update()
*/

View file

@ -0,0 +1,80 @@
using Verse;
using RimWorld;
using rjw;
using RimWorld.Planet;
using System;
namespace RJW_Genes
{
/// <summary>
/// Spawns tame spelopedes at the caster.
///
/// TODO: Play some sound? I think this can be done with some CompProperties.
/// </summary>
public class CompAbilityEffect_SpawnSpelopede : CompAbilityEffect
{
public CompProperties_AbilitySpawnSpelopede Props => (CompProperties_AbilitySpawnSpelopede) this.props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
int spelopedesToSpawn = CalculateSpelopedeAmount();
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Using Spelopede Spawn, spawning {spelopedesToSpawn}");
for (int i = 0; i < spelopedesToSpawn; i++) {
var request = new PawnGenerationRequest(
this.Props.pawnKindDef,
faction: this.parent.pawn.Faction,
forceGenerateNewPawn: true,
fixedBiologicalAge: 0.0f,
fixedChronologicalAge: 0.0f,
canGeneratePawnRelations: false,
colonistRelationChanceFactor: 0.0f
);
Pawn insect = PawnGenerator.GeneratePawn(request);
PawnUtility.TrySpawnHatchedOrBornPawn(insect, this.parent.pawn);
if (Props.tamed)
{
insect.training.Train(TrainableDefOf.Tameness, this.parent.pawn, true);
insect.training.Train(TrainableDefOf.Obedience, this.parent.pawn, true);
insect.training.Train(TrainableDefOf.Release, this.parent.pawn, true);
// I could do bonding here, but I think it's nicer if the queen is not "bonded" to their offspring.
}
}
MakeDirt(1);
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message("Finished Spelopede Spawn");
}
private int CalculateSpelopedeAmount()
{
Pawn caster = this.parent.pawn;
float spelopedes = Props.sensitivityMultiplier * caster.psychicEntropy.PsychicSensitivity;
return (spelopedes > 1.49f) ? (int)Math.Round(spelopedes) : 1;
}
private void MakeDirt(int multiplier = 1)
{
Pawn caster = this.parent.pawn;
FilthMaker.TryMakeFilth(caster.Position, caster.Map, ThingDefOf.Filth_AmnioticFluid, caster.LabelIndefinite(), count: Rand.Range(5,5*multiplier));
}
public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
{
if (!target.Cell.Filled(this.parent.pawn.Map) && (target.Cell.GetEdifice(this.parent.pawn.Map) == null))
return true;
if (throwMessages)
Messages.Message((string)("CannotUseAbility".Translate((NamedArgument)this.parent.def.label) + ": " + "AbilityOccupiedCells".Translate()), (LookTargets)target.ToTargetInfo(this.parent.pawn.Map), MessageTypeDefOf.RejectInput, false);
return false;
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
namespace RJW_Genes
{
public class CompProperties_AbilitySpawnSpelopede : CompProperties_AbilityEffect
{
public PawnKindDef pawnKindDef;
public float sensitivityMultiplier;
public bool tamed;
public CompProperties_AbilitySpawnSpelopede()
{
this.compClass = typeof(CompAbilityEffect_SpawnSpelopede);
}
}
}