Skip to content

Commit

Permalink
Fix strategies getting deactivated in Editor due to Planetarium time …
Browse files Browse the repository at this point in the history
…not getting updated on reverts.

Closes #2354
  • Loading branch information
siimav committed Apr 21, 2024
1 parent 4602acb commit 0ab0384
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/RP0/Harmony/Strategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Strategies;
using RP0.Programs;
using KSP.Localization;
using KSP.UI.Screens;

namespace RP0.Harmony
{
Expand Down Expand Up @@ -104,5 +105,30 @@ internal static bool Prefix_Deactivate(Strategy __instance, ref bool __result)
}
return true;
}

// Fix strategies getting deactivated in Editor due to Planetarium time not getting updated on reverts
[HarmonyPrefix]
[HarmonyPatch("Update")]
internal static bool Prefix_Update(Strategy __instance)
{
if (__instance.LongestDuration != 0d &&
__instance.dateActivated + __instance.LongestDuration <= Planetarium.GetUniversalTime())
{
__instance.SendStateMessage(Strategy.cacheAutoLOC_304909, __instance.MessageDeactivatedMaxTime(),
MessageSystemButton.MessageButtonColor.ORANGE, MessageSystemButton.ButtonIcons.ALERT);
__instance.Deactivate();
return false;
}

__instance.OnUpdate();

int i = 0;
for (int count = __instance.effects.Count; i < count; i++)
{
__instance.effects[i].Update();
}

return false;
}
}
}

0 comments on commit 0ab0384

Please sign in to comment.