private void Initialize(MapEvent battle, PartyBase attackerParty, PartyBase defenderParty) { if (SimulationModel.IsValidEventType(battle.EventType)) { var simulationModel = new SimulationModel(battle, attackerParty, defenderParty); if (!simulationModel.IsPlayerInvolved && !Config.CurrentConfig.EnabledForAI) { return; } if (SimulationsPool.AddModelToSimulations(simulationModel)) { if (simulationModel.IsPlayerInvolved) { if (Config.CurrentConfig.ShouldLogThis(simulationModel.IsPlayerInvolved)) { MessageHelper.DisplayText($"Initialized {simulationModel.EventDescription}", DisplayTextStyle.Info); } } else { // battle observer for battles started by AI battle.AddSimulationObserver(); } } } }
internal static void TroopNumberChangedInternal(BattleSideEnum side, IBattleCombatant battleCombatant, BasicCharacterObject character, int number = 0, int numberKilled = 0, int numberWounded = 0, int numberRouted = 0, int killCount = 0, int numberReadyToUpgrade = 0) { if (battleCombatant is PartyBase party) { if (party.MapEvent != null && SimulationModel.IsValidEventType(party.MapEvent.EventType)) { if (SimulationsPool.TryGetSimulationModel(party.MapEvent.Id, out SimulationModel simulationModel)) { while (numberKilled > 0) { simulationModel.RemoveTroop(side, character.Id); numberKilled--; } while (numberWounded > 0) { simulationModel.RemoveTroop(side, character.Id); numberWounded--; } while (numberRouted > 0) { simulationModel.RemoveTroop(side, character.Id); numberRouted--; } } } } }
private void Finalize(MapEvent battle) { if (SimulationModel.IsValidEventType(battle.EventType) && SimulationsPool.TryRemoveSimulationModel(battle.Id, out var simulationModel)) { if (Config.CurrentConfig.ShouldLogThis(simulationModel.IsPlayerInvolved)) { MessageHelper.DisplayText($"Finished {simulationModel.EventDescription}", DisplayTextStyle.Info); } } }
internal static void Postfix(ref MapEvent __instance, PartyBase involvedParty, BattleSideEnum side) { if (SimulationsPool.TryGetSimulationModel(__instance.Id, out var simulationModel)) { simulationModel.AddTroopsFromInvolvedParty(involvedParty, side); if (Config.CurrentConfig.ShouldLogThis(simulationModel.IsPlayerInvolved)) { MessageHelper.DisplayText($"{involvedParty} joined {simulationModel.EventDescription}", DisplayTextStyle.Info); } } }
private static bool Prefix(ref int __result, CharacterObject strikerTroop, CharacterObject strikedTroop, PartyBase strikerParty, PartyBase strikedParty, float strikerAdvantage, MapEvent battle) { if (SimulationsPool.TryGetSimulationModel(battle.Id, out SimulationModel simulationModel)) { try { __result = simulationModel.SimulateHit(strikerTroop.Id, strikedTroop.Id, strikerAdvantage); return(false); } catch (Exception ex) { if (Config.CurrentConfig.ShouldLogThis(simulationModel.IsPlayerInvolved)) { MessageHelper.DisplayText($"{simulationModel.EventDescription} Critical error simulating hit: " + ex.Message, DisplayTextStyle.Warning); } return(true); } } else { return(true); } }
internal static bool Prefix(ref bool __result, ref MapEventSide __instance, ref CharacterObject ____selectedSimulationTroop, ref UniqueTroopDescriptor ____selectedSimulationTroopDescriptor, int damage, DamageTypes damageType, out int troopState, PartyBase strikerParty) { if (strikerParty.MapEvent != null && SimulationModel.IsValidEventType(strikerParty.MapEvent.EventType)) { if (SimulationsPool.TryGetSimulationModel(strikerParty.MapEvent.Id, out var simulationModel)) { SimulationTroopState simulationTroopState = SimulationTroopState.Alive; __result = false; // try to find the attacked troop in our model. Id doesn't exist call vanilla method var troopId = ____selectedSimulationTroop.Id; var troop = simulationModel.Parties[(int)__instance.MissionSide].Troops.Find(t => t.CharacterObject.Id == troopId); if (troop == null) { troopState = (int)simulationTroopState; return(true); } var battleObserver = MapEventSideAccessTools.GetBattleObserver(__instance); var allocatedTroops = MapEventSideAccessTools.GetAllocatedTroops(__instance); // troop is a Hero logic if (____selectedSimulationTroop.IsHero) { __instance.AddHeroDamage(____selectedSimulationTroop.HeroObject, damage); if (____selectedSimulationTroop.HeroObject.IsWounded) { __result = true; simulationTroopState = SimulationTroopState.Wounded; if (battleObserver != null) { battleObserver.TroopNumberChanged(__instance.MissionSide, __instance.GetAllocatedTroopParty(____selectedSimulationTroopDescriptor), ____selectedSimulationTroop, -1, 0, 1, 0, 0, 0); } } } // regular logic else if (troop.ApplyDamage(damage)) { PartyBase party = allocatedTroops[____selectedSimulationTroopDescriptor].Party; float survivalChance = Campaign.Current.Models.PartyHealingModel.GetSurvivalChance(party, ____selectedSimulationTroop, damageType, strikerParty); if (MBRandom.RandomFloat < survivalChance) { __instance.OnTroopWounded(____selectedSimulationTroopDescriptor); simulationTroopState = SimulationTroopState.Wounded; if (battleObserver != null) { battleObserver.TroopNumberChanged(__instance.MissionSide, __instance.GetAllocatedTroopParty(____selectedSimulationTroopDescriptor), ____selectedSimulationTroop, -1, 0, 1, 0, 0, 0); } SkillLevelingManager.OnSurgeryApplied(party.MobileParty, 1f); } else { __instance.OnTroopKilled(____selectedSimulationTroopDescriptor); simulationTroopState = SimulationTroopState.Kille; if (battleObserver != null) { battleObserver.TroopNumberChanged(__instance.MissionSide, __instance.GetAllocatedTroopParty(____selectedSimulationTroopDescriptor), ____selectedSimulationTroop, -1, 1, 0, 0, 0, 0); } SkillLevelingManager.OnSurgeryApplied(party.MobileParty, 0.5f); } __result = true; } if (__result) { __instance.RemoveSelectedTroopFromSimulationList(); } troopState = (int)simulationTroopState; return(false); } } troopState = 1; return(true); }