Added Faction Penalties for Age Draining, Youth Fountain and Genetic Diseases

This commit is contained in:
Vegapnk 2024-07-05 15:04:45 +02:00
parent b12e9afbc0
commit f5917052ab
7 changed files with 114 additions and 0 deletions

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_StoleGene</defName>
<label>Stole a gene</label>
</HistoryEventDef>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_infected_with_disease</defName>
<label>Infected a pawn with a genetic disease</label>
</HistoryEventDef>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_spread_genetic_disease</defName>
<label>Spread a genetic disease</label>
</HistoryEventDef>
</Defs>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_aged_pawn_with_sex_gene</defName>
<label>Aged a pawn with sexual age transfer</label>
</HistoryEventDef>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene</defName>
<label>Youthed a pawn with youth fountain</label>
</HistoryEventDef>
</Defs>

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
@ -14,6 +15,9 @@ namespace RJW_Genes
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public class Patch_AfterSexUtility_ApplyGeneticInfectors
{
const int FACTION_GOODWILL_CHANGE = -3;
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null) return;
@ -48,10 +52,25 @@ namespace RJW_Genes
continue;
if ((new Random()).NextDouble() < application_chance)
{
partner.genes.AddGene(diseaseGeneDef, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
HandleFactionGoodWillPenalties(infector, partner);
}
}
}
}
private static void HandleFactionGoodWillPenalties(Pawn infector, Pawn partner)
{
if (
partner.Faction != null && infector.Faction != null
&& partner.Faction != infector.Faction
&& partner.Faction != Faction.OfPlayer)
{
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_infected_with_disease");
partner.Faction.TryAffectGoodwillWith(infector.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, partner);
}
}
}
}

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
@ -13,6 +14,8 @@ namespace RJW_Genes
public class Patch_AftersexUtility_TransferGeneticDiseases
{
public const int FACTION_GOODWILL_CHANGE = -2;
public static void Postfix(SexProps props)
{
if (!RJW_Genes_Settings.rjw_genes_genetic_disease_spread) return;
@ -48,9 +51,22 @@ namespace RJW_Genes
if ((new Random()).NextDouble() <= DiseaseHelper.LookupDiseaseInfectionChance(disease))
{
infected.genes.AddGene(disease, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
HandleFactionGoodWillPenalties(infector, infected);
}
}
}
private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
{
if (
target.Faction != null && actor.Faction != null
&& target.Faction != actor.Faction
&& target.Faction != Faction.OfPlayer)
{
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_spread_genetic_disease");
target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
}
}
}
}

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
@ -24,6 +25,8 @@ namespace RJW_Genes.Genes.Special
// 18 Years * 60 Days / Year * 60k Ticks/Day + 1 for safety
const long MINIMUM_AGE_FALLBACK = 18 * 60 * 60000 + 1;
const int FACTION_GOODWILL_CHANGE = -1;
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal() )
@ -80,6 +83,20 @@ namespace RJW_Genes.Genes.Special
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
ModLog.Message($"[Sexual Age Drainer] {receiver} was too young ({receiver.ageTracker.AgeBiologicalYears}), and remains unchanged.");
}
HandleFactionGoodWillPenalties(receiver, giver);
}
private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
{
if (
target.Faction != null && actor.Faction != null
&& target.Faction != actor.Faction
&& target.Faction != Faction.OfPlayer)
{
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene");
target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
}
}
}
}

View file

@ -1,4 +1,6 @@
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using rjw;
using System;
using System.Collections.Generic;
@ -13,6 +15,9 @@ namespace RJW_Genes
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public class Patch_GeneticSexThief
{
public const int FACTION_GOODWILL_CHANGE = -10;
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal())
@ -62,6 +67,15 @@ namespace RJW_Genes
stealer.genes.AddGene(stolenGene.def, AddAsXenogene);
victim.genes.RemoveGene(stolenGene);
if (
victim.Faction != null && stealer.Faction != null
&& victim.Faction != stealer.Faction
&& victim.Faction != Faction.OfPlayer) {
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_StoleGene");
victim.Faction.TryAffectGoodwillWith(stealer.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, victim);
}
}
}

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using RimWorld;
using rjw;
using System;
using System.Collections.Generic;
@ -23,6 +24,8 @@ namespace RJW_Genes.Genes.Special
// 18 Years * 60 Days / Year * 60k Ticks/Day + 1 for safety
const long MINIMUM_AGE_FALLBACK = 18 * 60 * 60000 + 1;
const int FACTION_GOODWILL_CHANGE = 1;
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal())
@ -39,10 +42,12 @@ namespace RJW_Genes.Genes.Special
if (GeneUtility.IsYouthFountain(props.pawn))
{
ChangeAgeForPawn(props.partner, props.pawn);
HandleFactionGoodWillPenalties(props.pawn, props.partner);
}
if (GeneUtility.IsYouthFountain(props.partner))
{
ChangeAgeForPawn(props.pawn,props.partner);
HandleFactionGoodWillPenalties(props.partner, props.pawn);
}
}
@ -65,6 +70,18 @@ namespace RJW_Genes.Genes.Special
ModLog.Message($"[Youth Fountain] {ToYouth} was too young ({ToYouth.ageTracker.AgeBiologicalYears}), and remains unchanged.");
}
private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
{
if (
target.Faction != null && actor.Faction != null
&& target.Faction != actor.Faction
&& target.Faction != Faction.OfPlayer)
{
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene");
target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
}
}
}
}