Ludeon Forums

Ludeon Forums

  • October 18, 2021, 01:04:22 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Is it possible to patch a GameCondition?  (Read 374 times)

arkyte

  • Muffalo
  • *
  • Posts: 16
  • Refugee
    • View Profile
Is it possible to patch a GameCondition?
« 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.
« Last Edit: April 27, 2021, 05:26:50 PM by arkyte »
Logged

LWM

  • Planetologist
  • ****
  • Posts: 1083
  • Little White Mouse
    • View Profile
Re: Is it possible to patch a GameCondition?
« Reply #1 on: April 27, 2021, 05:27:35 PM »

Also patch Init() to set your variable to 0?
Logged

arkyte

  • Muffalo
  • *
  • Posts: 16
  • Refugee
    • View Profile
Re: Is it possible to patch a GameCondition?
« Reply #2 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
« Last Edit: April 27, 2021, 05:46:52 PM by arkyte »
Logged

LWM

  • Planetologist
  • ****
  • Posts: 1083
  • Little White Mouse
    • View Profile
Re: Is it possible to patch a GameCondition?
« Reply #3 on: April 27, 2021, 06:46:19 PM »

Yep; public static variable :)  Which you figured out - you got this!
Logged