mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Rescued Cocoonweaver, FerventOvipositor and InsectIncubator into Breeding Genes
This commit is contained in:
parent
9c273d5567
commit
51b988f18c
10 changed files with 348 additions and 20 deletions
42
Source/Genes/Breeding/Gene_FerventOvipositor.cs
Normal file
42
Source/Genes/Breeding/Gene_FerventOvipositor.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Verse;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Manages the rjw_genes_fervent_ovipositor to grow eggs much faster.
|
||||
///
|
||||
/// TODO: Move the Multiplier into XML
|
||||
/// TODO: This gene only works after the first egg, the first egg for two new pawns spawns at the same time (strange).
|
||||
/// </summary>
|
||||
public class Gene_FerventOvipositor : Gene
|
||||
{
|
||||
|
||||
const int MULTIPLIER = 3; // Tick 3 times as much, making a pawn with this Gene Produce Eggs 4 times as fast as the normal.
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
base.Tick();
|
||||
|
||||
if (pawn == null) return;
|
||||
|
||||
Hediff_PartBaseNatural OvipositorF = (Hediff_PartBaseNatural)pawn.health.hediffSet.GetFirstHediffOfDef(rjw.Genital_Helper.ovipositorF);
|
||||
|
||||
if (OvipositorF == null) return;
|
||||
|
||||
OvipositorF.nextEggTick = Math.Max(OvipositorF.nextEggTick - MULTIPLIER, -1);
|
||||
|
||||
// DevNote: I first had a for-loop calling OviPositorF.tick(), but I fear that would be a performance sink.
|
||||
// Also, it would double other aspects as well, such as bleeding out through your insect-PP or dropping out the eggs.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
67
Source/Genes/Breeding/Gene_InsectIncubator.cs
Normal file
67
Source/Genes/Breeding/Gene_InsectIncubator.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using RimWorld;
|
||||
using rjw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This Gene checks for all parasitic Insect-Eggs in a Pawn:
|
||||
/// 1. Is it fertilized ? => tick it down "extra".
|
||||
/// 2. Is it not fertilized? => fertilize it with the Incubator as parent
|
||||
///
|
||||
/// To save performance, this gene fires (default) every 0.5h, which also means a slight delay until fertilization happens.
|
||||
/// </summary>
|
||||
public class Gene_InsectIncubator : Gene
|
||||
{
|
||||
const int TICK_INTERVAL = 60000 / 48; // 60k = 1 day, we want 0.5h which is 1/48th of 1 day.
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
base.Tick();
|
||||
|
||||
// Don't check too often, only in the HashTickInterval to safe some computing power
|
||||
if (this.pawn.IsHashIntervalTick(TICK_INTERVAL) && this.pawn.Map != null)
|
||||
{
|
||||
List<Hediff_InsectEgg> eggs = new List<Hediff_InsectEgg>();
|
||||
pawn.health.hediffSet.GetHediffs<Hediff_InsectEgg>(ref eggs);
|
||||
// This part works as intended and shows Non-Human Eggs too
|
||||
//if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Gene_InsectIncubator: Found {eggs.Count} Hediff_InsectEgg in {pawn}");
|
||||
|
||||
|
||||
foreach (Hediff_InsectEgg egg in eggs)
|
||||
{
|
||||
// The implanter check checks if the egg is still in an ovipositor.
|
||||
if (egg.implanter == null || egg.implanter == pawn)
|
||||
continue;
|
||||
|
||||
if (!egg.fertilized && egg.implanter != null)
|
||||
{
|
||||
egg.Fertilize(pawn);
|
||||
// DevNote Issue 38: Sometimes Eggs are not fertilized here, because the normal Fertilize Function is called which has an upper Limit on Gestation.
|
||||
// I will not do anything about it here, maybe upstream, but I print here.
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
|
||||
{
|
||||
if (egg.fertilized)
|
||||
ModLog.Message($"Gene_InsectIncubator: fertilized egg {egg} in {pawn}");
|
||||
else if (egg.GestationProgress > 0.5)
|
||||
ModLog.Message($"Gene_InsectIncubator: Failed to fertilize {egg} in {pawn} due to high gestation progress");
|
||||
else
|
||||
ModLog.Message($"Gene_InsectIncubator: failed to fertiliz egg {egg} in {pawn}");
|
||||
}
|
||||
}
|
||||
// DevNote: There is an issue with Eggs reaching too much gestation progress (>100%), which causes DownStream bugs. To avoid this, there are some extra checks in place.
|
||||
else if (egg.fertilized && egg.GestationProgress <= .93)
|
||||
{
|
||||
egg.lastTick += TICK_INTERVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
using Verse;
|
||||
using RimWorld;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// The CocoonWeaver Ability applies the RJW-Cocoon to a pawn.
|
||||
/// Friendly Pawns can always be cocooned, neutral and hostile pawns must be downed.
|
||||
/// </summary>
|
||||
public class CompAbilityEffect_CocoonWeaver : CompAbilityEffect
|
||||
{
|
||||
private new CompProperties_AbilityCocoonWeaver Props
|
||||
{
|
||||
get
|
||||
{
|
||||
return (CompProperties_AbilityCocoonWeaver)this.props;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
|
||||
{
|
||||
base.Apply(target, dest);
|
||||
|
||||
Pawn CocooningPawn = this.parent.pawn;
|
||||
Pawn PawnToCocoon = target.Pawn;
|
||||
|
||||
// Error Case - Null Pawn
|
||||
if (PawnToCocoon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PawnToCocoon.health.AddHediff(HediffDef.Named("RJW_Cocoon"));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For validity, there are a few checks:
|
||||
/// 0. Target is not already cocooned
|
||||
/// 1. Target is either Colonist / Prisoner
|
||||
/// 2. If the Target is an enemy or neutral, it must be downed.
|
||||
/// </summary>
|
||||
public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
|
||||
{
|
||||
Pawn cocoonTarget = target.Pawn;
|
||||
if (cocoonTarget != null)
|
||||
{
|
||||
bool CocoonTargetIsColonistOrPrisoner = cocoonTarget.Faction == this.parent.pawn.Faction || cocoonTarget.IsPrisonerOfColony;
|
||||
bool CocoonTargetIsHostile = cocoonTarget.HostileTo(this.parent.pawn);
|
||||
bool CocoonTargetIsDowned = cocoonTarget.Downed;
|
||||
|
||||
if (cocoonTarget.health.hediffSet.hediffs.Any(t => t.def.defName == "RJW_Cocoon"))
|
||||
{
|
||||
if (throwMessages)
|
||||
Messages.Message(cocoonTarget.Name + " is already cocooned.", cocoonTarget, MessageTypeDefOf.RejectInput, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CocoonTargetIsColonistOrPrisoner && !(CocoonTargetIsHostile && CocoonTargetIsDowned))
|
||||
{
|
||||
if (throwMessages)
|
||||
{
|
||||
if (CocoonTargetIsHostile && !CocoonTargetIsDowned)
|
||||
{
|
||||
Messages.Message(cocoonTarget.Name + " is hostile, but not downed.", cocoonTarget, MessageTypeDefOf.RejectInput, false);
|
||||
}
|
||||
else if (!CocoonTargetIsColonistOrPrisoner)
|
||||
{
|
||||
Messages.Message(cocoonTarget.Name + " is not a part of the colony or hostile.", cocoonTarget, MessageTypeDefOf.RejectInput, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return base.Valid(target, throwMessages);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
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_AbilityCocoonWeaver : CompProperties_AbilityEffect
|
||||
{
|
||||
public CompProperties_AbilityCocoonWeaver()
|
||||
{
|
||||
this.compClass = typeof(CompAbilityEffect_CocoonWeaver);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue