public static void Postfix(CombatGameState __instance) { Mod.Log.Trace?.Write("CGS:_I entered."); DataManager dm = UnityGameInstance.BattleTechGame.DataManager; LoadRequest loadRequest = dm.CreateLoadRequest(); // Need to load each unique icon Mod.Log.Info?.Write("LOADING EFFECT ICONS..."); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.ElectronicWarfare, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.SensorsDisabled, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.VisionAndSensors, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetSensorsMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetVisualsMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetTaggedMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetNarcedMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetStealthMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetMimeticMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetECMShieldedMark, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.TargetActiveProbePingedMark, null); loadRequest.ProcessRequests(); Mod.Log.Info?.Write(" ICON LOADING COMPLETE!"); ModState.Combat = __instance; }
public static void Postfix(SimGameState __instance) { LoadRequest loadRequest = __instance.DataManager.CreateLoadRequest(null, true); loadRequest.AddAllOfTypeBlindLoadRequest(BattleTechResourceType.LanceDef, new bool?(true)); loadRequest.ProcessRequests(10U); }
public static T LoadResource <T>(BattleTechResourceType resourceType, string resourceId, TimeSpan?timeout = null) where T : class { TimeSpan timeoutNotNull = timeout ?? TimeSpan.FromMinutes(1); DateTime errorTime = DateTime.Now + timeoutNotNull; T resource = null; GameInstance gameInstance = UnityGameInstance.BattleTechGame; DataManager dataManager = gameInstance.DataManager; LoadRequest loadRequest = dataManager.CreateLoadRequest(null, false); loadRequest.AddLoadRequest <T>(resourceType, resourceId, (s, resourceReturned) => { resource = resourceReturned; }, false); loadRequest.ProcessRequests(10u); do { dataManager.Update(UnityEngine.Time.deltaTime); if (DateTime.Now > errorTime) { throw new Exception("Failed to load resource: " + resourceId); } } while (resource is null); return(resource); }
public void RequestResourcesAndProcess(BattleTechResourceType resourceType, string resourceId, bool filterByOwnership = false) { LoadRequest loadRequest = UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest(delegate(LoadRequest request) { Main.LogDebug($"[RequestResourcesAndProcess] Finished load request for {resourceId}"); }, filterByOwnership); loadRequest.AddBlindLoadRequest(resourceType, resourceId); loadRequest.ProcessRequests(1000u); }
public void RequestResourcesAndProcess(BattleTechResourceType resourceType, string resourceId, bool filterByOwnership = false) { LoadRequest loadRequest = UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest(delegate(LoadRequest request) { Main.LogDebug($"[RequestResourcesAndProcess] Finished load request for {resourceId}"); }, filterByOwnership); loadRequest.AddBlindLoadRequest(resourceType, resourceId); // Without 1000u this does not work for my usecase // Data loading has been updated for the Main Menu loads so it no longer should cause deadlocks loadRequest.ProcessRequests(1000u); }
static void Postfix(SimGameState __instance, GameInstance game, SimGameDifficulty difficulty) { DataManager dm = UnityGameInstance.BattleTechGame.DataManager; LoadRequest loadRequest = dm.CreateLoadRequest(); // Need to load each unique icon Mod.Log.Info?.Write("-- Loading HUD icons"); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_Aerospace, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_MechTech, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_MedTech, null); loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_Vehicle, null); loadRequest.ProcessRequests(); Mod.Log.Info?.Write("-- Done!"); // Reinitialize state ModState.Reset(); ModState.SimGameState = __instance; }
public static void LoadAmbushResources(CombatGameState combat) { // Load the necessary turret defs Mod.Log.Info?.Write($"== BEGIN load request for all possible ambush spawns"); LoadRequest asyncSpawnReq = combat.DataManager.CreateLoadRequest( delegate(LoadRequest loadRequest) { OnLoadComplete(combat); }, false ); Mod.Log.Info?.Write($" -- Pre-load counts => weaponDefs: {combat.DataManager.WeaponDefs.Count} " + $"pilotDefs: {combat.DataManager.PilotDefs.Count} mechDefs: {combat.DataManager.MechDefs.Count}" + $"turretDefs: {combat.DataManager.TurretDefs.Count} vehicleDefs: {combat.DataManager.VehicleDefs.Count}"); // Filter requests so we don't load multiple times HashSet <string> turretsToLoad = new HashSet <string>(); HashSet <string> pilotsToLoad = new HashSet <string>(); foreach (TurretAndPilotDef ambushDef in ModState.InfantryAmbushDefForContract.SpawnPool) { turretsToLoad.Add(ambushDef.TurretDefId); pilotsToLoad.Add(ambushDef.PilotDefId); } HashSet <string> battleArmorToLoad = new HashSet <string>(); foreach (MechAndPilotDef ambushDef in ModState.BattleArmorAmbushDefForContract.SpawnPool) { battleArmorToLoad.Add(ambushDef.MechDefId); pilotsToLoad.Add(ambushDef.PilotDefId); } HashSet <string> mechToLoad = new HashSet <string>(); foreach (MechAndPilotDef ambushDef in ModState.MechAmbushDefForContract.SpawnPool) { mechToLoad.Add(ambushDef.MechDefId); pilotsToLoad.Add(ambushDef.PilotDefId); } HashSet <string> vehiclesToLoad = new HashSet <string>(); foreach (VehicleAndPilotDef ambushDef in ModState.VehicleAmbushDefForContract.SpawnPool) { vehiclesToLoad.Add(ambushDef.VehicleDefId); pilotsToLoad.Add(ambushDef.PilotDefId); } // Add the filtered requests to the async load foreach (string defId in turretsToLoad) { Mod.Log.Info?.Write($" - TurretDefId: {defId}"); asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.TurretDef, defId, new bool?(false)); } foreach (string defId in pilotsToLoad) { Mod.Log.Info?.Write($" - PilotDefId: {defId}"); asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.PilotDef, defId, new bool?(false)); } foreach (string defId in battleArmorToLoad) { Mod.Log.Info?.Write($" - MechDefId: {defId}"); asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.MechDef, defId, new bool?(false)); } foreach (string defId in mechToLoad) { Mod.Log.Info?.Write($" - MechDefId: {defId}"); asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.MechDef, defId, new bool?(false)); } foreach (string defId in vehiclesToLoad) { Mod.Log.Info?.Write($" - VehicleDefId: {defId}"); asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.VehicleDef, defId, new bool?(false)); } // Fire the load request asyncSpawnReq.ProcessRequests(1000U); }
public BehaviorVariableScopeManager(GameInstance gameInstance) { scopeDescriptions = new List <ScopeDesc> { new ScopeDesc("global", AIMood.Undefined), new ScopeDesc("global_def", AIMood.Defensive), new ScopeDesc("global_sensorlock", AIMood.SensorLocking), new ScopeDesc("global_ruthless", AIMood.Ruthless), new ScopeDesc("role_brawler", AIMood.Undefined, UnitRole.Brawler), new ScopeDesc("role_brawler_def", AIMood.Defensive, UnitRole.Brawler), new ScopeDesc("role_ecmcarrier", AIMood.Undefined, UnitRole.EcmCarrier), new ScopeDesc("role_ecmcarrier_def", AIMood.Defensive, UnitRole.EcmCarrier), new ScopeDesc("role_ewe", AIMood.Undefined, UnitRole.Ewe), new ScopeDesc("role_ewe_def", AIMood.Defensive, UnitRole.Ewe), new ScopeDesc("role_activeprobe", AIMood.Undefined, UnitRole.ActiveProbe), new ScopeDesc("role_activeprobe_def", AIMood.Defensive, UnitRole.ActiveProbe), new ScopeDesc("role_sniper", AIMood.Undefined, UnitRole.Sniper), new ScopeDesc("role_sniper_def", AIMood.Defensive, UnitRole.Sniper), new ScopeDesc("role_scout", AIMood.Undefined, UnitRole.Scout), new ScopeDesc("role_scout_def", AIMood.Defensive, UnitRole.Scout), new ScopeDesc("role_lastmanstanding", AIMood.Undefined, UnitRole.LastManStanding), new ScopeDesc("role_lastmanstanding_def", AIMood.Defensive, UnitRole.LastManStanding), new ScopeDesc("role_meleeonly", AIMood.Undefined, UnitRole.MeleeOnly), new ScopeDesc("role_meleeonly_def", AIMood.Defensive, UnitRole.MeleeOnly), new ScopeDesc("role_noncombatant", AIMood.Undefined, UnitRole.NonCombatant), new ScopeDesc("role_noncombatant_def", AIMood.Defensive, UnitRole.NonCombatant), new ScopeDesc("role_turret", AIMood.Undefined, UnitRole.Turret), new ScopeDesc("role_turret_def", AIMood.Defensive, UnitRole.Turret), new ScopeDesc("role_vehicle", AIMood.Undefined, UnitRole.Vehicle), new ScopeDesc("role_vehicle_def", AIMood.Defensive, UnitRole.Vehicle), }; List <FactionValue> factionList = FactionEnumeration.AIBehaviorVariableScopeList; for (int i = 0; i < factionList.Count; ++i) { FactionValue faction = factionList[i]; if (faction.HasAIBehaviorVariableScope) { string undefined = string.Format("faction_{0}", faction.Name.ToLower()); string defensive = string.Format("{0}_def", undefined); scopeDescriptions.Add(new ScopeDesc(undefined, AIMood.Undefined, faction)); scopeDescriptions.Add(new ScopeDesc(defensive, AIMood.Defensive, faction)); } } scopeDescriptions.Add(new ScopeDesc("personality_disciplined", AIMood.Undefined, AIPersonality.Disciplined)); scopeDescriptions.Add(new ScopeDesc("personality_disciplined_def", AIMood.Defensive, AIPersonality.Disciplined)); scopeDescriptions.Add(new ScopeDesc("personality_aggressive", AIMood.Undefined, AIPersonality.Aggressive)); scopeDescriptions.Add(new ScopeDesc("personality_aggressive_def", AIMood.Defensive, AIPersonality.Aggressive)); scopeDescriptions.Add(new ScopeDesc("personality_qapersonality", AIMood.Undefined, AIPersonality.QAPersonality)); scopeDescriptions.Add(new ScopeDesc("personality_qapersonality_def", AIMood.Defensive, AIPersonality.QAPersonality)); scopeDescriptions.Add(new ScopeDesc("skill_reckless", AIMood.Undefined, AISkillID.Reckless)); scopeDescriptions.Add(new ScopeDesc("skill_reckless_def", AIMood.Defensive, AISkillID.Reckless)); scopesByRole = new Dictionary <UnitRole, BehaviorVariableScope>(); scopesByFaction = new Dictionary <int, BehaviorVariableScope>(); scopesByAIPersonality = new Dictionary <AIPersonality, BehaviorVariableScope>(); scopesByAISkill = new Dictionary <AISkillID, BehaviorVariableScope>(); LoadRequest loadRequest = gameInstance.DataManager.CreateLoadRequest(); for (int i = 0; i < scopeDescriptions.Count; ++i) { ScopeDesc scopeDescription = scopeDescriptions[i]; loadRequest.AddLoadRequest <string>(BattleTechResourceType.BehaviorVariableScope, scopeDescription.Name, OnBehaviorVariableScopeLoaded); switch (scopeDescription.ScopeKind) { case ScopeKind.Global: if (scopeDescription.Mood == AIMood.Undefined) { globalBehaviorVariableScope = new BehaviorVariableScope(); } else { globalBehaviorVariableScope.ScopesByMood[scopeDescription.Mood] = new BehaviorVariableScope(); } break; case ScopeKind.UnitRole: if (scopeDescription.Mood == AIMood.Undefined) { scopesByRole[scopeDescription.UnitRole] = new BehaviorVariableScope(); } else { scopesByRole[scopeDescription.UnitRole].ScopesByMood[scopeDescription.Mood] = new BehaviorVariableScope(); } break; case ScopeKind.Faction: if (scopeDescription.Mood == AIMood.Undefined) { scopesByFaction[scopeDescription.FactionValue.ID] = new BehaviorVariableScope(); } else { scopesByFaction[scopeDescription.FactionValue.ID].ScopesByMood[scopeDescription.Mood] = new BehaviorVariableScope(); } break; case ScopeKind.Personality: if (scopeDescription.Mood == AIMood.Undefined) { scopesByAIPersonality[scopeDescription.AIPersonality] = new BehaviorVariableScope(); } else { scopesByAIPersonality[scopeDescription.AIPersonality].ScopesByMood[scopeDescription.Mood] = new BehaviorVariableScope(); } break; case ScopeKind.SkillBased: if (scopeDescription.Mood == AIMood.Undefined) { scopesByAISkill[scopeDescription.AISkillID] = new BehaviorVariableScope(); } else { scopesByAISkill[scopeDescription.AISkillID].ScopesByMood[scopeDescription.Mood] = new BehaviorVariableScope(); } break; } } loadRequest.ProcessRequests(); }
public static void Postfix(UnitSpawnPointOverride __instance, DataManager ___dataManager, string lanceName) { try { Logger.Debug("----------------------------------------------------------------------------------------------------"); // Ignore untagged (players lance, empty spawnpoints, or manually defined in the contracts json) units if (!__instance.IsUnitDefTagged || !__instance.IsPilotDefTagged) { //Logger.Info("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] UnitSpawnPointOverride.IsUnitDefTagged: " + __instance.IsUnitDefTagged); //Logger.Info("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] UnitSpawnPointOverride.IsPilotDefTagged: " + __instance.IsPilotDefTagged); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Unit or Pilot was either specified exactly via configuration or excluded from spawning. Aborting."); return; } // Ignore all units that are NOT Mechs if (__instance.selectedUnitType != UnitType.Mech) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Unit is not a Mech. Aborting."); return; } // Info Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] ---"); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] UnitSpawnPointOverride.selectedUnitDefId: " + __instance.selectedUnitDefId); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] UnitSpawnPointOverride.selectedUnitType: " + __instance.selectedUnitType); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] UnitSpawnPointOverride.selectedPilotDefId: " + __instance.selectedPilotDefId); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] ---"); // Prepare vars string selectedMechDefId = __instance.selectedUnitDefId; MechDef selectedMechDef = null; string replacementMechDefId = ""; string replacementPilotDefId = ""; int mechThreatLevel = 0; // Get data Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechDefId(" + selectedMechDefId + ") is requested from DataManager..."); if (!___dataManager.MechDefs.TryGet(selectedMechDefId, out selectedMechDef)) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechDefId(" + selectedMechDefId + ") couldn't get fetched. Aborting."); return; } else { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechDefId(" + selectedMechDefId + ") successfully requested. Continuing."); } // Check lance info if (Fields.CurrentLanceName != lanceName) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Lance (" + lanceName + ") is a new lance, resetting counters"); Fields.CurrentLanceName = lanceName; Fields.CurrentLanceCustomUnitCount = 0; } // Prepare load requests LoadRequest loadRequest = ___dataManager.CreateLoadRequest(null, false); // Check for custom units if (selectedMechDef.MechTags.Contains("unit_madlabs")) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechDefId(" + selectedMechDefId + ") is a custom unit and thus needs adjustment"); // Count Fields.CurrentLanceCustomUnitCount++; // Collect constraints Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Fields.CurrentLanceCustomUnitCount: " + Fields.CurrentLanceCustomUnitCount); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Fields.MaxCustomUnitsPerLance: " + Fields.MaxCustomUnitsPerLance); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Fields.CurrentContractEliteUnits: " + Fields.CurrentContractEliteUnits); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Fields.MaxEliteUnitsPerContract: " + Fields.MaxEliteUnitsPerContract); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Fields.MaxThreatLevelByProgression: " + Fields.MaxThreatLevelByProgression); int selectedMechsThreatLevel = Utilities.GetThreatLevelByTag(selectedMechDef.MechTags); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechsThreatLevel: " + selectedMechsThreatLevel); int maxThreatLevel = Fields.MaxThreatLevelByProgression; Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] maxThreatLevel: " + maxThreatLevel); // Limit elite units per contract if (selectedMechsThreatLevel == 3 && maxThreatLevel == 3) { Fields.CurrentContractEliteUnits++; if (Fields.CurrentContractEliteUnits > Fields.MaxEliteUnitsPerContract) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Already pulled an elite unit, reducing maxThreatLevel to 2"); maxThreatLevel = 2; } } // Limit custom units per lance if (Fields.CurrentLanceCustomUnitCount > Fields.MaxCustomUnitsPerLance) { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] Already " + Fields.MaxCustomUnitsPerLance + " custom units in this lance, reducing maxThreatLevel to 0"); maxThreatLevel = 0; } Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] maxThreatLevel: " + maxThreatLevel); // Replace if necessary if (selectedMechsThreatLevel > maxThreatLevel) { // Replace with less powerful version of the same Mech (Fallback to STOCK included) replacementMechDefId = Utilities.GetMechDefIdBasedOnSameChassis(selectedMechDef.ChassisID, maxThreatLevel, ___dataManager); __instance.selectedUnitDefId = replacementMechDefId; mechThreatLevel = maxThreatLevel; // Add to load request loadRequest.AddBlindLoadRequest(BattleTechResourceType.MechDef, __instance.selectedUnitDefId, new bool?(false)); } else { mechThreatLevel = selectedMechsThreatLevel; } } else { Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] selectedMechDefId(" + selectedMechDefId + ") is no custom Unit. Let it pass unchanged..."); } // Pilot handling (will also potentially place better pilots in stock and light mechs in late game) replacementPilotDefId = Utilities.GetPilotIdForMechDef(selectedMechDef, __instance.selectedPilotDefId, __instance.pilotTagSet, mechThreatLevel, Fields.GlobalDifficulty); __instance.selectedPilotDefId = replacementPilotDefId; // Add new pilot to load request loadRequest.AddBlindLoadRequest(BattleTechResourceType.PilotDef, __instance.selectedPilotDefId, new bool?(false)); // Fire load requests loadRequest.ProcessRequests(1000u); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] ---"); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] CHECK UnitSpawnPointOverride.selectedUnitDefId: " + __instance.selectedUnitDefId); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] CHECK UnitSpawnPointOverride.selectedUnitType: " + __instance.selectedUnitType); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] CHECK UnitSpawnPointOverride.selectedPilotDefId: " + __instance.selectedPilotDefId); Logger.Debug("[UnitSpawnPointOverride_GenerateUnit_POSTFIX] ---"); } catch (Exception e) { Logger.Error(e); } }