diff --git a/Source/Common/ModLog.cs b/Source/Common/ModLog.cs new file mode 100644 index 0000000..407520a --- /dev/null +++ b/Source/Common/ModLog.cs @@ -0,0 +1,34 @@ +using Verse; + +namespace RJW_Genes +{ + internal class ModLog + { + public static string ModId => "RJW-Genes"; + + /// + /// Logs the given message with [SaveStorage.ModId] appended. + /// + public static void Error(string message) + { + Log.Error($"[{ModId}] {message}"); + } + + /// + /// Logs the given message with [SaveStorage.ModId] appended. + /// + public static void Message(string message) + { + Log.Message($"[{ModId}] {message}"); + } + + /// + /// Logs the given message with [SaveStorage.ModId] appended. + /// + public static void Warning(string message) + { + Log.Warning($"[{ModId}] {message}"); + } + + } +} diff --git a/Source/Genes/GeneUtility.cs b/Source/Genes/GeneUtility.cs index 07a5c24..e2ac018 100644 --- a/Source/Genes/GeneUtility.cs +++ b/Source/Genes/GeneUtility.cs @@ -32,7 +32,7 @@ namespace RJW_Genes return pawn.genes.HasGene(GeneDefOf.rjw_genes_youth_fountain); } - internal static bool IsAgeDrainer(Pawn pawn) + public static bool IsAgeDrainer(Pawn pawn) { if (pawn.genes == null) { diff --git a/Source/Genes/Special/Patch_AgeDrain.cs b/Source/Genes/Special/Patch_AgeDrain.cs index 981f483..2c7e55d 100644 --- a/Source/Genes/Special/Patch_AgeDrain.cs +++ b/Source/Genes/Special/Patch_AgeDrain.cs @@ -13,9 +13,11 @@ namespace RJW_Genes.Genes.Special { const long AGE_TRANSFERED = 120000; // 120k == 2 days + // 20 Years * 60 Days / Year * 60k Ticks/Day + 1 for safety + const long MINIMUM_AGE = 20 * 60 * 60000 + 1; // Comment Below in for debugging, changes years - // const long AGE_TRANSFERED = 6000000; // 6000k == 100 days + // const long AGE_TRANSFERED = 12000000; public static void Postfix(SexProps props) { if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal() ) @@ -25,12 +27,12 @@ namespace RJW_Genes.Genes.Special if (GeneUtility.IsAgeDrainer(props.pawn)) { var pawnAge = props.pawn.ageTracker.AgeBiologicalTicks; - var pawnMinAge = props.pawn.ageTracker.AdultMinAgeTicks; + //ModLog.Error($"Firing Age Drain \nMinimum Age is \t{MINIMUM_AGE} \nPawn Age is \t{pawnAge} \nTransferred \t{AGE_TRANSFERED}\nResulting in \t{pawnAge - AGE_TRANSFERED}"); // Make Partner older props.partner.ageTracker.AgeBiologicalTicks += AGE_TRANSFERED; // Make Pawn younger - props.pawn.ageTracker.AgeBiologicalTicks = Math.Max(pawnMinAge, pawnAge - AGE_TRANSFERED); + props.pawn.ageTracker.AgeBiologicalTicks = Math.Max(MINIMUM_AGE, (pawnAge - AGE_TRANSFERED)); } } diff --git a/Source/Genes/Special/Patch_Youth_Fountain.cs b/Source/Genes/Special/Patch_Youth_Fountain.cs index f2c7e13..a1a1840 100644 --- a/Source/Genes/Special/Patch_Youth_Fountain.cs +++ b/Source/Genes/Special/Patch_Youth_Fountain.cs @@ -13,9 +13,11 @@ namespace RJW_Genes.Genes.Special { const long AGE_REDUCTION = 60000; // 60k == 1 day + // 20 Years * 60 Days / Year * 60k Ticks/Day + 1 for safety + const long MINIMUM_AGE = 20 * 60 * 60000 + 1; // Comment Below in for debugging - //const long AGE_REDUCTION = 6000000; // 6000k == 100 days + // const long AGE_REDUCTION = 6000000; // 6000k == 100 days public static void Postfix(SexProps props) { if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal()) @@ -25,12 +27,18 @@ namespace RJW_Genes.Genes.Special if (GeneUtility.IsYouthFountain(props.pawn)) { var partnerAge = props.partner.ageTracker.AgeBiologicalTicks; - var minAge = props.partner.ageTracker.AdultMinAgeTicks; - props.partner.ageTracker.AgeBiologicalTicks = Math.Max(minAge, partnerAge - AGE_REDUCTION); + //ModLog.Error($"Firing Youth Fountain \nMinimum Age is \t{MINIMUM_AGE}\t{ticksToYears(MINIMUM_AGE)}y\nPawn Age is \t{partnerAge}\t{ticksToYears(partnerAge)}y \nTransferred \t {AGE_REDUCTION}\t{ticksToYears(AGE_REDUCTION)}y\nResulting in \t{partnerAge - AGE_REDUCTION}\t{ticksToYears(partnerAge - AGE_REDUCTION)}y"); + + props.partner.ageTracker.AgeBiologicalTicks = Math.Max(MINIMUM_AGE, partnerAge - AGE_REDUCTION); } } + private static float ticksToYears(long ticks) + { + return (ticks / 60000f) / 60f; + } } + }