Ludeon Forums

RimWorld => Mods => Help => Topic started by: arkyte on April 27, 2021, 05:24:08 PM

Title: Is it possible to patch a GameCondition?
Post by: arkyte on April 27, 2021, 05:24:08 PM
I want to patch lightning strikes. My main problem is that I don't know how to create a variable and give it a starting value at the beginning of the flashstorm. Then this variable would change value during the flashstorm. At the beginning of another flashstorm it would be reset.

Code: [Select]
namespace Mod
{
[HarmonyPatch(typeof(GameCondition_Flashstorm), "GameConditionTick")]
public static class GameCondition_Flashstorm_GameConditionTick_Patch
{
static int nextCheckTicks = 0;
static bool doThisOncePerFlashstorm = true;

public static void Postfix(GameCondition_Flashstorm __instance)
{
if (doThisOnePerFlashstorm)
{
longStuff;
doThisOnePerFlashstorm = false;
}
if (Find.TickManager.TicksGame >= nextCheckTicks)
{
nextCheckTicks = Find.TickManager.TicksGame + 1000;
}
}
}
}

My issue is: nextCheckTicks does not reset to 0 at the next flashstorm neither does doThisOncePerFlashstorm turns false.

Thank you.
Title: Re: Is it possible to patch a GameCondition?
Post by: LWM on April 27, 2021, 05:27:35 PM
Also patch Init() to set your variable to 0?
Title: Re: Is it possible to patch a GameCondition?
Post by: arkyte on April 27, 2021, 05:30:40 PM
Genius. I'm so dumb hahahah

My variables carry between harmony patches? Or this one carries because both methods are inside the same GameCondition_Flashstorm?

Edit:
Is there a way to do it? I can't seem to assign values to variables from another harmonypatch

Edit:
Managed to do it. Set the variable to public and call it by
GameCondition_Flashstorm_GameConditionTick_Patch.werePawnsChecked = false;
Inside the other patch
Title: Re: Is it possible to patch a GameCondition?
Post by: LWM on April 27, 2021, 06:46:19 PM
Yep; public static variable :)  Which you figured out - you got this!