mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-18 02:09:37 -06:00
AutoHotboxSpotter Patch for caboose consist presence, making checks happen between every 15-30 seconds vs 60-300 (default)
This commit is contained in:
@@ -62,5 +62,32 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
oiler.PayWages();
|
oiler.PayWages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IEnumerator MrocAutoHotboxSpotterLoop(this AutoHotboxSpotter spotter, Serilog.ILogger _log)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
bool hasCaboose = spotter._cars.CabooseInConsist();
|
||||||
|
if (!spotter.HasCars)
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_log.Information("AutoHotboxSpotter {name}: Hotbox Spotter Running, Has Caboose => {hasCaboose}; Has Cars {hasCars}", spotter.name, hasCaboose, spotter.HasCars);
|
||||||
|
spotter.CheckForHotbox();
|
||||||
|
while (spotter.HasCars)
|
||||||
|
{
|
||||||
|
int num = Random.Range(60, 300);
|
||||||
|
if (hasCaboose)
|
||||||
|
{
|
||||||
|
var numOrig = num;
|
||||||
|
num = Random.Range(15, 30);
|
||||||
|
_log.Information("AutoHotboxSpotter {name}: Next check went from num(60,300) => {numOrig}; to num(15,30) => {hasCaboose}", spotter.name, numOrig, num);
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(num);
|
||||||
|
spotter.CheckForHotbox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Model.AI;
|
||||||
|
using Railloader;
|
||||||
|
using RMROC451.TweaksAndThings.Extensions;
|
||||||
|
using Serilog;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace RMROC451.TweaksAndThings.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(AutoHotboxSpotter))]
|
||||||
|
[HarmonyPatch(nameof(AutoHotboxSpotter.SpotterLoop))]
|
||||||
|
[HarmonyPatchCategory("RMROC451TweaksAndThings")]
|
||||||
|
internal class AutoHotboxSpotter_SpotterLoop_Patch
|
||||||
|
{
|
||||||
|
private static ILogger _log => Log.ForContext<AutoHotboxSpotter_SpotterLoop_Patch>();
|
||||||
|
|
||||||
|
public static bool Prefix(AutoHotboxSpotter __instance, ref IEnumerator __result)
|
||||||
|
{
|
||||||
|
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||||
|
if (!tweaksAndThings.IsEnabled) return true;
|
||||||
|
bool buttonsHaveCost = tweaksAndThings?.settings?.EndGearHelpersRequirePayment ?? false;
|
||||||
|
|
||||||
|
if (buttonsHaveCost) __result = __instance.MrocAutoHotboxSpotterLoop(_log);
|
||||||
|
return !buttonsHaveCost; //only hit this if !buttonsHaveCost, since Loop is a coroutine
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user