public static void ApplyInstantRest(UnitEntityData unitEntityData) { if (unitEntityData.Descriptor.State.IsFinallyDead) { unitEntityData.Descriptor.Resurrect(); unitEntityData.Position = Game.Instance.Player.MainCharacter.Value.Position; } RestController.RemoveNegativeEffects(unitEntityData.Descriptor); RestController.ApplyRest(unitEntityData.Descriptor); Rulebook.Trigger(new RuleHealDamage(unitEntityData, unitEntityData, new DiceFormula(), unitEntityData.Descriptor.Stats.HitPoints.ModifiedValue)); foreach (var attribute in StatTypeHelper.Attributes) { Rulebook.Trigger(new RuleHealStatDamage(unitEntityData, unitEntityData, attribute)); } foreach (var attribute in unitEntityData.Stats.Attributes) { attribute.Damage = 0; attribute.Drain = 0; } RestoreAllItemCharges(); }
public static void Postfix(KingdomEventUIView ___m_KingdomEventView, bool __state) { if (__state) { EventBus.RaiseEvent((IKingdomUIStartSpendTimeEvent h) => h.OnStartSpendTimeEvent(___m_KingdomEventView.Blueprint)); KingdomTaskEvent kingdomTaskEvent = ___m_KingdomEventView?.Task; EventBus.RaiseEvent((IKingdomUICloseEventWindow h) => h.OnClose()); kingdomTaskEvent?.Start(false); if (kingdomTaskEvent == null) { return; } if (kingdomTaskEvent.IsFinished || kingdomTaskEvent.AssignedLeader == null || ___m_KingdomEventView.Blueprint.NeedToVisitTheThroneRoom) { return; } kingdomTaskEvent.Event.Resolve(kingdomTaskEvent); if (___m_KingdomEventView.RulerTimeRequired <= 0) { return; } foreach (UnitEntityData unitEntityData in player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } new KingdomTimelineManager().MaybeUpdateTimeline(); } }
public void mod_OnStart() { if (!KingmakerPatchSettings.KingdomEvents.InstantComplete) { this.source_OnStart(); return; } KingdomEventUIView previousView = this.alias_m_KingdomEventView; EventBus.RaiseEvent((IKingdomUIStartSpendTimeEvent h) => h.OnStartSpendTimeEvent(previousView.Blueprint)); KingdomTaskEvent task = previousView.Task; EventBus.RaiseEvent((IKingdomUICloseEventWindow h) => h.OnClose()); task?.Start(false); if (task == null || task.IsFinished || task.AssignedLeader == null || previousView.Blueprint.NeedToVisitTheThroneRoom) { return; } task.Event.Resolve(task); if (previousView.RulerTimeRequired <= 0) { return; } foreach (UnitEntityData unitEntityData in Kingmaker.Game.Instance.Player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } }
public virtual void mod_Start(bool raiseEvent = true) { if (!KingmakerPatchSettings.CurrencyFallback.Enabled) { this.source_Start(raiseEvent); return; } this.alias_IsStarted = true; this.alias_StartedOn = KingdomState.Instance.CurrentDay; KingdomCurrencyFallback.SpendPoints(this.OneTimeBPCost); if (raiseEvent) { this.alias_OnTaskChanged(); } EventBus.RaiseEvent((IKingdomTaskEventsHandler h) => h.OnTaskStarted(this)); if (this.SkipPlayerTime <= 0) { return; } Kingmaker.Game.Instance.AdvanceGameTime(TimeSpan.FromDays(this.SkipPlayerTime)); foreach (UnitEntityData unitEntityData in Kingmaker.Game.Instance.Player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } new KingdomTimelineManager().UpdateTimeline(); }
// can potentially go back in time but some parts of the game don't expect it public static void KingdomTimelineAdvanceDays(int days) { var kingdom = KingdomState.Instance; var timelineManager = kingdom.TimelineManager; // from KingdomState.SkipTime foreach (var kingdomTask in kingdom.ActiveTasks) { if (!kingdomTask.IsFinished && !kingdomTask.IsStarted && !kingdomTask.NeedsCommit && kingdomTask.HasAssignedLeader) { kingdomTask.Start(true); } } // from KingdomTimelineManager.Advance if (!KingdomTimelineManager.CanAdvanceTime()) { return; } Game.Instance.AdvanceGameTime(TimeSpan.FromDays(days)); if (Game.Instance.IsModeActive(GameModeType.Kingdom)) { foreach (var unitEntityData in Game.Instance.Player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } } timelineManager.UpdateTimeline(); }
private void SetupNewCharacher() { this.Unit.Unit.View.UpdateAsks(); this.Unit.BirthDay = this.BirthDay; this.Unit.BirthMonth = this.BirthMonth; if (this.Doll != null) { this.Unit.Doll = this.Doll.CreateData(); this.Unit.LeftHandedOverride = new bool?(this.Doll.LeftHanded); } if (this.State.Mode != LevelUpState.CharBuildMode.PreGen) { ItemsCollection.DoWithoutEvents(delegate { LevelUpHelper.AddStartingItems(this.Unit); }); } else { this.Unit.Body.Initialize(); } this.Unit.AddStartingInventory(); foreach (Spellbook spellbook in this.Unit.Spellbooks) { spellbook.UpdateAllSlotsSize(true); int num = spellbook.GetTotalFreeSlotsCount(); for (int i = 0; i < 100; i++) { if (num <= 0) { break; } foreach (BlueprintAbility blueprint in BlueprintRoot.Instance.Progression.CharGenMemorizeSpells) { AbilityData data = new AbilityData(blueprint, spellbook); spellbook.Memorize(data, null); } int totalFreeSlotsCount = spellbook.GetTotalFreeSlotsCount(); if (num <= totalFreeSlotsCount) { break; } num = totalFreeSlotsCount; } } RestController.ApplyRest(this.Unit); if (this.Unit.IsCustomCompanion() && this.State.Mode != LevelUpState.CharBuildMode.Respec) { Game.Instance.EntityCreator.AddEntity(this.Unit.Unit, Game.Instance.Player.CrossSceneState); Game.Instance.Player.RemoteCompanions.Add(this.Unit.Unit); Game.Instance.Player.InvalidateCharacterLists(); this.Unit.Unit.IsInGame = false; this.Unit.Unit.AttachToViewOnLoad(null); if (this.Unit.Unit.View != null) { this.Unit.Unit.View.transform.SetParent(Game.Instance.DynamicRoot, true); } } }
static bool Prefix(KingdomTask __instance, bool raiseEvent) { try { if (!Main.enabled) { return(true); } if (!Main.settings.currencyFallback) { return(true); } IsStartedSetter(__instance, true); StartedOnSetter(__instance, KingdomState.Instance.CurrentDay); KingdomCurrencyFallback.SpendPoints(__instance.OneTimeBPCost); if (raiseEvent) { OnTaskChanged(__instance); } EventBus.RaiseEvent((IKingdomTaskEventsHandler h) => h.OnTaskStarted(__instance)); if (__instance.SkipPlayerTime <= 0) { return(false); } Kingmaker.Game.Instance.AdvanceGameTime(TimeSpan.FromDays(__instance.SkipPlayerTime)); foreach (UnitEntityData unitEntityData in Kingmaker.Game.Instance.Player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } new KingdomTimelineManager().UpdateTimeline(); return(false); } catch (Exception ex) { Main.Error(ex); return(true); } }
public void mod_OnClose() { if (!KingmakerPatchSettings.KingdomEvents.InstantComplete) { this.source_OnClose(); return; } KingdomEventUIView previousView = this.alias_m_KingdomEventView; // deselects the view EventBus.RaiseEvent((IEventSceneHandler h) => h.OnEventSelected(null, this.alias_m_Cart)); if (previousView == null) { return; } if (previousView.IsFinished || previousView.AssignedLeader == null || previousView.Blueprint.NeedToVisitTheThroneRoom) { return; } bool inProgress = previousView.IsInProgress; BlueprintUnit leader = previousView.AssignedLeader; if (!inProgress || leader == null) { return; } previousView.Event.Resolve(previousView.Task); if (previousView.RulerTimeRequired <= 0) { return; } foreach (UnitEntityData unitEntityData in Kingmaker.Game.Instance.Player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } }
public static void RestSelected() { foreach (var selectedUnit in Game.Instance.UI.SelectionManager.SelectedUnits) { if (selectedUnit.Descriptor.State.IsFinallyDead) { selectedUnit.Descriptor.Resurrect(); selectedUnit.Position = Game.Instance.Player.MainCharacter.Value.Position; } RestController.RemoveNegativeEffects(selectedUnit.Descriptor); RestController.ApplyRest(selectedUnit.Descriptor); Rulebook.Trigger(new RuleHealDamage(selectedUnit, selectedUnit, default(DiceFormula), selectedUnit.Descriptor.Stats.HitPoints.ModifiedValue)); foreach (var attribute in selectedUnit.Stats.Attributes) { attribute.Damage = 0; attribute.Drain = 0; } } }
private void LevelUp(UnitDescriptor unit, int levels, bool fromFact) { using (new IgnorePrerequisites()) { ClassLevelLimit component = unit.Blueprint.GetComponent <ClassLevelLimit>(); int classLevelLimit = component == null ? int.MaxValue : component.LevelLimit; if (ElementsContext.GetData <DefaultBuildData>() != null) { classLevelLimit = 0; } Dictionary <SelectionEntry, HashSet <int> > selectionsHistory = new Dictionary <SelectionEntry, HashSet <int> >(); HashSet <int> spellHistory = (instance.SelectSpells.Length <= 0) ? null : new HashSet <int>(); for (int i = 0; i < levels; i++) { if (unit.Progression.CharacterLevel < classLevelLimit) { Main.Log($"A: Adding level {i} unitlevel {unit.Progression.CharacterLevel}"); this.AddLevel(unit, selectionsHistory, spellHistory); } else { Main.Log($"B: Adding level {i} unitlevel {unit.Progression.CharacterLevel}"); LevelUpPlanUnitHolder levelUpPlanUnitHolder = unit.Get <LevelUpPlanUnitHolder>(); if (levelUpPlanUnitHolder != null) { UnitDescriptor unitDescriptor = levelUpPlanUnitHolder.RequestPlan(); LevelUpController levelUpController = this.AddLevel(unitDescriptor, selectionsHistory, spellHistory); unit.Progression.AddLevelPlan(levelUpController.GetPlan()); } } } this.PrepareSpellbook(unit); unit.Progression.ReapplyFeaturesOnLevelUp(); UnitEntityView view = unit.Unit.View; if (view != null) { view.UpdateClassEquipment(); } RestController.ApplyRest(unit); } }
public static void Postfix(bool __state, KingdomEventUIView ___m_KingdomEventView, KingdomEventHandCartController ___m_Cart) { if (__state) { if (___m_KingdomEventView != null) { EventBus.RaiseEvent((IEventSceneHandler h) => h.OnEventSelected(null, ___m_Cart)); if (___m_KingdomEventView.IsFinished || ___m_KingdomEventView.AssignedLeader == null || ___m_KingdomEventView.Blueprint.NeedToVisitTheThroneRoom) { return; } bool inProgress = ___m_KingdomEventView.IsInProgress; BlueprintUnit leader = ___m_KingdomEventView.AssignedLeader.Blueprint; if (!inProgress || leader == null) { return; } ___m_KingdomEventView.Event.Resolve(___m_KingdomEventView.Task); if (___m_KingdomEventView.RulerTimeRequired <= 0) { return; } foreach (UnitEntityData unitEntityData in player.AllCharacters) { RestController.ApplyRest(unitEntityData.Descriptor); } new KingdomTimelineManager().MaybeUpdateTimeline(); } } }