public bool mod_CheckRestrictions(SettlementState settlement, SettlementGridTopology.Slot slot) { if (KingmakerPatchSettings.Restrictions.IgnoreBuildingRestrictions) { return(true); } return(this.GetComponents <BuildingRestriction>().All(r => r.CanBuildHere(this, settlement, slot))); }
public void mod_FoundSettlement(RegionSettlementLocation settlementLocation, string name = null) { if (!KingmakerPatchSettings.CurrencyFallback.Enabled) { this.source_FoundSettlement(settlementLocation, name); return; } if (!this.Blueprint.SettlementBuildArea) { UberDebug.LogError("Cannot found a settlement in {0}: no building area set up", settlementLocation); return; } if (this.Settlement != null) { UberDebug.LogError("Cannot found a settlement in {0}: already built", settlementLocation); return; } if (settlementLocation != null && settlementLocation.AssociatedLocation == null) { UberDebug.LogError("Cannot found a settlement in {0}: no globalmap location associated", settlementLocation); return; } if (settlementLocation == null && this.Blueprint.SettlementGlobalmapLocations.Length == 0) { UberDebug.LogError("Cannot found a settlement in {0}: no location specified and no default found", this.Blueprint); return; } KingdomCurrencyFallback.SpendPoints(KingdomRoot.Instance.SettlementBPCost); var settlementState = new SettlementState(SettlementState.LevelType.Village) { Region = this }; SettlementState settlementState2 = settlementState; settlementState2.HasWaterSlot = settlementLocation?.HasWaterSlot == true; settlementState.Name = name ?? this.Blueprint.DefaultSettlementName; settlementState.Location = settlementLocation?.AssociatedLocation ?? this.Blueprint.SettlementGlobalmapLocations.FirstOrDefault(); settlementState.SettlementLocation = settlementLocation; this.Settlement = settlementState; this.SetSettlementUIMarkers(); EventBus.RaiseEvent((ISettlementFoundingHandler h) => h.OnSettlementFounded(this.Settlement)); }
private void SetUpSettlementState() { SettlementState = new SettlementState() { MainRoad = new Road(_engine.MainRoad), CurrentIteration = _engine.Iteration, Time = (int)_stopWatch.ElapsedMilliseconds / 1000, CurrentEpoch = _engine.CurrentEpoch, Roads = _engine.Settlement.Roads, LastSettlementUpdate = _engine.LastSettlementUpdate, SettlementCenter = _engine.Settlement.SettlementCenter }; }
static bool Prefix(SettlementState __instance, ref bool __result, BlueprintSettlementBuilding building, int ___m_SlotsLeft) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } if (!KingdomCurrencyFallback.CanSpend(__instance.GetActualCost(building))) { UberDebug.LogSystem("[KingdomResolution] SettlementState_CanBuild_Patch: Cannot spend"); __result = false; return(false); } SpecialSlotType specialSlot = building.SpecialSlot; if (specialSlot != SpecialSlotType.None) { if (__instance.IsSpecialSlotFilled(specialSlot)) { return(false); } } else if (___m_SlotsLeft < building.SlotCount) { return(false); } __result = CanBuildByLevel(__instance, building); return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }
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 bool __result, BlueprintSettlementBuilding building) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } __result = KingdomCurrencyFallback.CanSpend(__instance.GetActualCost(building)) && building.MinLevel <= __instance.Level && __instance.Buildings.Any(b => b.Blueprint.UpgradesTo == building); 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); } }
static bool Prefix(RegionState __instance, RegionSettlementLocation settlementLocation, string name) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } if (!__instance.Blueprint.SettlementBuildArea) { UberDebug.LogError("Cannot found a settlement in {0}: no building area set up", settlementLocation); return(false); } if (__instance.Settlement != null) { UberDebug.LogError("Cannot found a settlement in {0}: already built", settlementLocation); return(false); } if (settlementLocation != null && settlementLocation.AssociatedLocation == null) { UberDebug.LogError("Cannot found a settlement in {0}: no globalmap location associated", settlementLocation); return(false); } if (settlementLocation == null && __instance.Blueprint.SettlementGlobalmapLocations.Length == 0) { UberDebug.LogError("Cannot found a settlement in {0}: no location specified and no default found", __instance.Blueprint); return(false); } KingdomCurrencyFallback.SpendPoints(KingdomRoot.Instance.SettlementBPCost); var settlementState = new SettlementState(SettlementState.LevelType.Village) { Region = __instance }; SettlementState settlementState2 = settlementState; settlementState2.HasWaterSlot = settlementLocation?.HasWaterSlot == true; settlementState.Name = name ?? __instance.Blueprint.DefaultSettlementName; settlementState.Location = settlementLocation?.AssociatedLocation ?? __instance.Blueprint.SettlementGlobalmapLocations.FirstOrDefault(); settlementState.SettlementLocation = settlementLocation; __instance.Settlement = settlementState; __instance.SetSettlementUIMarkers(); EventBus.RaiseEvent((ISettlementFoundingHandler h) => h.OnSettlementFounded(__instance.Settlement)); return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }
static bool Prefix(object __instance, BlueprintSettlementBuilding building, SettlementBuilding settlementBuilding, SettlementState settlement, Image ___Slots, TextMeshProUGUI ___Cost, Image ___DiscountLayer) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } string costFormat = KingdomCurrencyFallback.costFormat; string costSplitFormat = KingdomCurrencyFallback.costSplitFormat; ___Slots.sprite = KingdomUIRoot.Instance.Settlement.GetSlotSprite(building.SlotCount); if (settlementBuilding == null) { int actualCost = settlement.GetActualCost(building, out bool isDiscounted); ___DiscountLayer?.gameObject?.SetActive(actualCost == 0 || isDiscounted); if (actualCost == 0) { ___Cost.text = string.Format(costFormat, KingdomUIRoot.Instance.Texts.BuildFreeCost); } else { Tuple <int, int> costSplit = KingdomCurrencyFallback.SplitCost(actualCost); LocalizedString format = isDiscounted ? KingdomUIRoot.Instance.Texts.BuildPointsDiscountFormat : KingdomUIRoot.Instance.Texts.BuildPointsFormat; if (costSplit.Item2 == 0) { ___Cost.text = string.Format(costFormat, string.Format(format, costSplit.Item1)); } else { ___Cost.text = string.Format(costSplitFormat, string.Format(format, costSplit.Item1), costSplit.Item2); } } } else { try { ___DiscountLayer.gameObject.SetActive(false); } catch (NullReferenceException) { //accessing ___DiscountLayer.gameObject after the gameObject has been destroyed causes the getter to throw an exception } ___Cost.text = string.Format(costFormat, string.Format(KingdomUIRoot.Instance.Texts.BuildPointsFormat, settlementBuilding.Owner.GetSellPrice(building))); } SetColor(__instance, building, settlementBuilding, settlement); return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }
/* * Pause Kingdom works by keeping current day constant, and increasing kingdom start day to compensate * To manage kingdom while paused, event start and finish days are moved backwards to simulate currentday moving forwards * any events that depend on CurrentDay need to be manually triggered */ public static void FixTimeline(int delta) { if (delta < 1) { return; } if (!Main.settings.enablePausedKingdomManagement) { return; } foreach (KingdomBuff kingdomBuff in KingdomState.Instance.ActiveBuffs.Enumerable) { if (kingdomBuff.EndsOnDay > 0 && KingdomState.Instance.CurrentDay >= kingdomBuff.EndsOnDay) { kingdomBuff.EndsOnDay = (int)Math.Max(1, kingdomBuff.EndsOnDay - delta); } } foreach (RegionState regionState in KingdomState.Instance.Regions) { SettlementState settlement = regionState.Settlement; if (settlement != null) { foreach (var building in settlement.Buildings) { if (building.IsFinished) { continue; } building.FinishedOn = building.FinishedOn - delta; } } } foreach (RegionState regionState2 in KingdomState.Instance.Regions) { foreach (Artisan artisan in regionState2.Artisans) { if (artisan.HasHelpProject) { continue; } artisan.ProductionStartedOn = artisan.ProductionStartedOn - delta; artisan.ProductionEndsOn = artisan.ProductionEndsOn - delta; } } foreach (KingdomTask task in KingdomState.Instance.ActiveTasks) { if (!(task is KingdomTaskEvent kte)) { continue; } if (!kte.IsInProgress) { continue; } if (kte.Event.EventBlueprint is BlueprintKingdomProject bkp) { StartedOnSetter(task, task.StartedOn - delta); } } foreach (var kingdomEvent in KingdomState.Instance.ActiveEvents) { if (kingdomEvent.IsFinished) { continue; } m_StartedOnRef(kingdomEvent) = m_StartedOnRef(kingdomEvent) - delta; } for (int i = 0; i < delta; i++) { var totalDays = (int)Game.Instance.TimeController.GameTime.TotalDays; if ((totalDays - delta) % 7 == 0) { KingdomState.Instance.BPPerTurnTotal = Rulebook.Trigger <RuleCalculateBPGain>(new RuleCalculateBPGain()).BPToAdd; KingdomState.Instance.BuildPoints += KingdomState.Instance.BPPerTurnTotal; KingdomState.Instance.CurrentTurn++; EventBus.RaiseEvent(delegate(IKingdomLogHandler h) { h.OnBPGained(KingdomState.Instance.BPPerTurnTotal); }); } } KingdomState.Instance.LastRavenVisitDay -= delta; }
IEnumerator ExecuteAttackOrder_EnterState() { D.Log("{0}.ExecuteAttackOrder_EnterState called.", Data.Name); Call(SettlementState.Attacking); yield return null; // required immediately after Call() to avoid FSM bug CurrentState = SettlementState.Idling; }
private void alias_SetColor(BlueprintSettlementBuilding building, SettlementBuilding settlementBuilding, SettlementState settlement) { throw new DeadEndException("source_SetColor"); }
public void mod_Initialize(BlueprintSettlementBuilding building, SettlementBuilding settlementBuilding, SettlementState settlement) { if (!KingmakerPatchSettings.CurrencyFallback.Enabled) { this.source_Initialize(building, settlementBuilding, settlement); return; } string costFormat = LocalizationManagerNew.LoadString("9191fbc8-23ac-4bd4-8167-28de8d418122"); string costSplitFormat = LocalizationManagerNew.LoadString("da676fed-170f-4099-8b09-ba516d632dd7"); this.alias_Slots.sprite = KingdomUIRoot.Instance.Settlement.GetSlotSprite(building.SlotCount); if (settlementBuilding == null) { int actualCost = settlement.GetActualCost(building, out bool isDiscounted); this.alias_DiscountLayer.gameObject.SetActive(actualCost == 0 || isDiscounted); if (actualCost == 0) { this.alias_Cost.text = string.Format(costFormat, KingdomUIRoot.Instance.Texts.BuildFreeCost); } else { Tuple <int, int> costSplit = KingdomCurrencyFallback.SplitCost(actualCost); LocalizedString format = isDiscounted ? KingdomUIRoot.Instance.Texts.BuildPointsDiscountFormat : KingdomUIRoot.Instance.Texts.BuildPointsFormat; if (costSplit.Item2 == 0) { this.alias_Cost.text = string.Format(costFormat, string.Format(format, costSplit.Item1)); } else { this.alias_Cost.text = string.Format(costSplitFormat, string.Format(format, costSplit.Item1), costSplit.Item2); } } } else { this.alias_DiscountLayer.gameObject.SetActive(false); this.alias_Cost.text = string.Format(costFormat, string.Format(KingdomUIRoot.Instance.Texts.BuildPointsFormat, settlementBuilding.Owner.GetSellPrice(building))); } this.alias_SetColor(building, settlementBuilding, settlement); }
public void source_Initialize(BlueprintSettlementBuilding building, SettlementBuilding settlementBuilding, SettlementState settlement) { throw new DeadEndException("source_Initialize"); }