mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Moved Insect Incubator and Breeder to Hive Genes
This commit is contained in:
parent
8605a09941
commit
765ef964c4
6 changed files with 36 additions and 28 deletions
|
@ -1,54 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HarmonyLib;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// This Class patches the RJW-DoEgg to allow up to MaxEggSizeMul times the original amount of eggs.
|
||||
/// This harmony patch was kindly provided by 'shabalox' https://github.com/Shabalox/RJW_Genes_Addons/
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PregnancyHelper), "DoEgg")]
|
||||
static class PatchPregnancyHelper
|
||||
{
|
||||
[HarmonyTranspiler]
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
|
||||
{
|
||||
//MethodInfo isinsectincubator = AccessTools.Method(typeof(GeneUtility), "IsInsectIncubator");
|
||||
MethodInfo maxeggsizemul = AccessTools.Method(typeof(GeneUtility), "MaxEggSizeMul");
|
||||
FieldInfo partner = AccessTools.Field(typeof(SexProps), "partner");
|
||||
|
||||
Label skiplabel = il.DefineLabel();
|
||||
bool finished = false;
|
||||
foreach (CodeInstruction codeInstruction in instructions)
|
||||
{
|
||||
if (!finished)
|
||||
{
|
||||
if (codeInstruction.opcode == OpCodes.Ldc_R4 && codeInstruction.operand.ToString() == "0")
|
||||
{
|
||||
yield return new CodeInstruction(OpCodes.Ldarg_0, null);
|
||||
yield return new CodeInstruction(OpCodes.Ldfld, partner);
|
||||
//yield return new CodeInstruction(OpCodes.Call, isinsectincubator);
|
||||
yield return new CodeInstruction(OpCodes.Callvirt, maxeggsizemul);
|
||||
//yield return new CodeInstruction(OpCodes.Brfalse_S, skiplabel);
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_0, null);
|
||||
//yield return new CodeInstruction(OpCodes.Ldc_R4, 2f);
|
||||
yield return new CodeInstruction(OpCodes.Mul, null);
|
||||
yield return new CodeInstruction(OpCodes.Stloc_0, null);
|
||||
//codeInstruction.labels.Add(skiplabel);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
yield return codeInstruction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Verse;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// This Class patches the AfterSexUtility to also fertilize eggs if Pawn A has "InsectBreeder" and Pawn B has Insect Eggs.
|
||||
/// Patched Class is https://gitgud.io/Ed86/rjw/-/blob/master/1.4/Source/Common/Helpers/SexUtility.cs
|
||||
///
|
||||
/// Normal Egg-Pregnancy logic is in https://gitgud.io/Ed86/rjw/-/blob/master/1.4/Source/Modules/Pregnancy/Pregnancy_Helper.cs
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
|
||||
static class Patch_EggFertilization
|
||||
{
|
||||
public static void Postfix(SexProps props)
|
||||
{
|
||||
// Only Fertilize on vaginal / anal sex
|
||||
if (!(props.sexType == xxx.rjwSextype.Vaginal || props.sexType == xxx.rjwSextype.Anal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (canDoEggFertilization(props.pawn, props.partner))
|
||||
{
|
||||
// Pawn has gene and Partner has eggs
|
||||
if (props.pawn.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder) && !getEggsforPawn(props.partner).NullOrEmpty())
|
||||
{
|
||||
Pawn eggHolder = props.partner;
|
||||
Pawn impregnator = props.pawn;
|
||||
|
||||
foreach (Hediff_InsectEgg egg in getEggsforPawn(eggHolder))
|
||||
{
|
||||
if (!egg.fertilized)
|
||||
egg.Fertilize(impregnator);
|
||||
}
|
||||
}
|
||||
|
||||
// Partner has gene and Pawn has eggs
|
||||
if (props.partner.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder) && !getEggsforPawn(props.pawn).NullOrEmpty())
|
||||
{
|
||||
Pawn eggHolder = props.pawn;
|
||||
Pawn impregnator = props.partner;
|
||||
|
||||
foreach (Hediff_InsectEgg egg in getEggsforPawn(eggHolder))
|
||||
{
|
||||
if (!egg.fertilized)
|
||||
egg.Fertilize(impregnator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static bool canDoEggFertilization(Pawn a, Pawn b)
|
||||
{
|
||||
|
||||
// No Partner / Other Errors
|
||||
if (a != null || b != null)
|
||||
return false;
|
||||
// None of the pawns has the relevant gene
|
||||
if (!a.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder) && !b.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder))
|
||||
return false;
|
||||
// None of the pawns has eggs
|
||||
if (getEggsforPawn(a).NullOrEmpty() && getEggsforPawn(b).NullOrEmpty())
|
||||
return false;
|
||||
|
||||
// A has gene and B has eggs
|
||||
if (a.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder) && !getEggsforPawn(b).NullOrEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// B has gene and A has eggs
|
||||
if (b.genes.GenesListForReading.Any(x => x.def == GeneDefOf.rjw_genes_insectbreeder) && !getEggsforPawn(a).NullOrEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// Any other case: Do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<Hediff_InsectEgg> getEggsforPawn(Pawn pawn)
|
||||
{
|
||||
List<Hediff_InsectEgg> eggs = new List<Hediff_InsectEgg>();
|
||||
pawn.health.hediffSet.GetHediffs(ref eggs);
|
||||
foreach (var egg in eggs)
|
||||
egg.Fertilize(pawn);
|
||||
|
||||
return eggs;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue