static bool Prefix(SettlementState __instance, SettlementBuilding building, ref SettlementBuilding __result, BuildingsCollection ___m_Buildings) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } if (!building.IsFinished || !___m_Buildings.HasFact(building) || !building.Blueprint.UpgradesTo) { return(false); } if (!KingdomCurrencyFallback.CanSpend(__instance.GetActualCost(building.Blueprint.UpgradesTo))) { UberDebug.LogWarning("Cannot upgrade " + building.Blueprint + ": not enough BP"); return(false); } KingdomCurrencyFallback.SpendPoints(__instance.GetActualCost(building.Blueprint)); SettlementBuilding result = ___m_Buildings.Upgrade(building); __instance.Update(); EventBus.RaiseEvent((ISettlementBuildUpdate h) => h.OnBuildUpdate(building)); __result = result; return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }
static bool Prefix(SettlementState __instance, ref SettlementBuilding __result, BlueprintSettlementBuilding building, SettlementGridTopology.Slot slot, bool force, ref int ___m_SlotsLeft, BuildingsCollection ___m_Buildings) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } var removedBuilding = true; if (!force) { if (!__instance.CanBuild(building)) { __result = null; return(false); } BuildingSlot slotObject = slot.GetSlotObject(); if (slotObject?.CanBuildHere(building) != true) { return(false); } KingdomCurrencyFallback.SpendPoints(__instance.GetActualCost(building)); removedBuilding = __instance.FreeBuildings.Remove(building) || KingdomState.Instance.FreeBuildings.Remove(building); } SettlementBuilding settlementBuilding = ___m_Buildings.Build(building); settlementBuilding.BuildOnSlot(slot); if (building.SpecialSlot == SpecialSlotType.None) { ___m_SlotsLeft -= building.SlotCount; } if (!force && !removedBuilding || SellDiscountedBuildingGetter(__instance) != building) { SellDiscountedBuildingSetter(__instance, null); } __instance.Update(); EventBus.RaiseEvent((ISettlementBuildingHandler h) => h.OnBuildingStarted(__instance, settlementBuilding)); __result = settlementBuilding; return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }