public static void Postfix(Player __instance) { bool featureEnabled = ModMain.settings.autoTowersSettings.enabled.Value; bool modEnabled = ModMain.settings.enabled.Value; if (!featureEnabled || !modEnabled) { ResetAutoTowers(); return; } switch (autoTowersState) { case 0: // Open all archer and ballista towers. if (ModMain.InvasionInProgress()) { OpenClosedTowers(); autoTowersState = 1; } break; case 1: // Close towers that were closed before the invasion. if (!ModMain.InvasionInProgress()) { CloseOpenedTowers(); autoTowers.Clear(); autoTowersState = 0; } break; default: break; } }
public static void Postfix(ChamberOfWar __instance) { bool featureEnabled = ModMain.settings.autoHazardPaySettings.enabled.Value; bool modEnabled = ModMain.settings.enabled.Value; if (!featureEnabled || !modEnabled) { ResetAutoHazardPay(); return; } try { // Refer to ChamberOfWarUI::Update if hazard pay requirements change. int goldNeeded = 50; bool fullyStaffed = (double)__instance.b.GetWorkerPercent() > 0.95; bool hasEnoughGold = World.GetLandmassOwner(__instance.b.LandMass()).Gold >= goldNeeded; bool canActivate = fullyStaffed && hasEnoughGold; switch (hazardPayState) { case 0: // Activation state // If an invasion starts and hazard pay is not activated, auto-activates it if the // requirements are met, then maximizes tax rates. Else if hazard pay is already activated, // prevents from auto-deactivation. if (!Player.inst.hazardPay && ModMain.InvasionInProgress() && canActivate) { // Refer to: ChamberOfWarUI::OnHazardButtonToggled if hazard pay activation changes. World.GetLandmassOwner(__instance.b.LandMass()).Gold -= goldNeeded; SfxSystem.inst.PlayFromBank("ui_merchant_sellto", Camera.main.transform.position); Player.inst.ChangeHazardPayActive(true, true); ModMain.chamberOfWarUI_hazardPayToggle_m_IsOn.SetValue(false); // Crank up the tax rates to maximum in order to afford hazard pay. Save the previous // rates to restore them when the invasion is over. MaximizeTaxRates(); hazardPayState = 1; } else if (Player.inst.hazardPay || Player.inst.hazardPayWarmup.Enabled) { hazardPayState = 3; } break; case 1: // Activation warmup state // Hazard pay must finish activation before auto-deactivation. if (!Player.inst.hazardPayWarmup.Enabled && Player.inst.hazardPay) { ModMain.chamberOfWarUI_hazardPayToggle_m_IsOn.SetValue(true); hazardPayState = 2; } break; case 2: // Deactivation state // If the invasion is over, deactivates an auto-activated hazard pay. Else if hazard pay is // deactivated during an invasion (manually or out of gold), prevents auto-activation until // the next invasion. Restores tax rates to original in both cases. if (Player.inst.hazardPay && !ModMain.InvasionInProgress()) { Player.inst.ChangeHazardPayActive(false, false); ModMain.chamberOfWarUI_hazardPayToggle_m_IsOn.SetValue(false); RestoreTaxRates(); hazardPayState = 0; } else if (!Player.inst.hazardPay) { ModMain.chamberOfWarUI_hazardPayToggle_m_IsOn.SetValue(false); RestoreTaxRates(); hazardPayState = 3; } break; case 3: // Auto-activation/deactivation disabled state // Waits out the current invasion before going back to the activation state. Goes to this // state when hazard pay is activated before, or deactivated during an invasion. if (!ModMain.InvasionInProgress()) { hazardPayState = 0; } break; default: break; } } catch (Exception e) { ModMain.helper.Log("ERROR: Exception raised in AutoHazardPayPatch."); ModMain.helper.Log(e.ToString()); } }