예제 #1
0
 public static void Postfix(PilotDef __instance, LoadRequest loadRequest)
 {
     if (__instance.PortraitSettings != null)
     {
         // perform this here on the first save load after character creation
         // this avoids all sorts of exceptions and problems with the character customization UIs
         // this also means we only need to do this in one patch instead of many
         if (!string.IsNullOrEmpty(__instance.PortraitSettings.Description.Icon))
         {
             __instance.Description.SetIcon(__instance.PortraitSettings.Description.Icon);
             __instance.PortraitSettings = null;
             Logger.LogLine(string.Format("Applying Hardset Icon to Pilot: {0}, {1}", (object)__instance.Description.Callsign, (object)__instance.Description.Icon));
         }
     }
     if (!string.IsNullOrEmpty(__instance.Description.Icon))
     {
         //Logger.LogLine(string.Format("Loading Pilot: {0}, {1}", (object)__instance.Description.Callsign, (object)__instance.Description.Icon));
         // Issue a Load request for any custom sprites
         try
         {
             Logger.LogLine(string.Format("Issuing  Load Request Icon for Pilot: {0}, {1}", (object)__instance.Description.Callsign, (object)__instance.Description.Icon));
             loadRequest.AddBlindLoadRequest(BattleTechResourceType.Sprite, __instance.Description.Icon, new bool?(false));
         }
         catch (Exception e)
         {
             Logger.LogError(e);
         }
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
            static bool Prefix(UnitSpawnPointOverride __instance, LoadRequest request, MetadataDatabase mdd, string lanceName, string lanceDefId, string unitName, int unitIndex, DateTime?currentDate, TagSet companyTags)
            {
                if (__instance.IsUnitDefTagged &&
                    __instance.unitTagSet.Contains("unit_mech") &&
                    currentDate != null)
                {
                    __instance.selectedUnitDefId = Core.xotlTables.RequestUnit(currentDate.Value, __instance.unitTagSet, __instance.unitExcludedTagSet, companyTags);
                    __instance.selectedUnitType  = UnitType.Mech;

                    request.AddBlindLoadRequest(BattleTechResourceType.MechDef, __instance.selectedUnitDefId, new bool?(false));
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
예제 #5
0
        static bool Prefix(UnitSpawnPointOverride __instance, ref LoadRequest request, MetadataDatabase mdd, string lanceName, int unitIndex)
        {
            if (UnityGameInstance.BattleTechGame.Simulation != null && Core.Settings.UpgradePilots)
            {
                try
                {
                    DataManager dataManager = Traverse.Create(__instance).Field("dataManager").GetValue <DataManager>();

                    if (__instance.pilotDefId == UnitSpawnPointGameLogic.PilotDef_Tagged &&
                        __instance.selectedUnitType == UnitType.Mech &&
                        __instance.selectedUnitDefId != UnitSpawnPointGameLogic.MechDef_None &&
                        dataManager != null &&
                        __instance.pilotTagSet.IsEmpty &&
                        __instance.pilotExcludedTagSet.IsEmpty)
                    {
                        //Logger.Log($"Adding Exclusions to pilot: {__instance.pilotDefId}, for lance: {lanceName}, unit index: {unitIndex}, in Mech: {__instance.selectedUnitDefId}");

                        /*
                         * Skill	    -	            Gunnery 8	    Piloting 8	    Guts 8	        Tactics 8
                         * Gunnery 5	Gunner		    -               Flanker	        Gladiator	    Striker
                         * Piloting 5	Pilot	        Skirmisher	    -               Brawler	        Scout
                         * Guts 5      Defender	    Lancer	        Outrider	    -               Vanguard
                         * Tactics 5	Tactician	    Sharpshooter	Recon	        Sentinel        -
                         */

                        // Add the Tags we want
                        MechDef mechDef     = dataManager.MechDefs.Get(__instance.selectedUnitDefId);
                        TagSet  excludeTags = new TagSet();


                        if (mechDef.Chassis.ChassisTags.Contains("mech_quirk_multitrac"))
                        {
                            // Excluding tier 2 skilled pilots that don't have Multi Target for Multi-Trac quirk
                            excludeTags.Add("pilot_npc_outrider");
                            excludeTags.Add("pilot_npc_recon");
                            excludeTags.Add("pilot_npc_brawler");
                            excludeTags.Add("pilot_npc_sentinel");
                            excludeTags.Add("pilot_npc_scout");
                            excludeTags.Add("pilot_npc_vanguard");
                        }

                        // Brawlers
                        if (mechDef.MechTags.Contains("unit_role_brawler"))
                        {
                            // Excluding tier 2 pilots that have no or next to no survivability skills in brawlers
                            excludeTags.Add("pilot_npc_sharpshooter");
                            excludeTags.Add("pilot_npc_skirmisher");

                            if (!mechDef.MechTags.Contains("unit_speed_high"))
                            {
                                // We aren't fast, get rid of shoot and move with no additional survivability
                                excludeTags.Add("pilot_npc_striker");
                            }

                            if (mechDef.MechTags.Contains("unit_speed_low") &&
                                !mechDef.MechTags.Contains("unit_jumpOK"))
                            {
                                // We are slow, can't jump and want to brawl, tactics 8 with Piloting 5 will not be enough for us to live on
                                excludeTags.Add("pilot_npc_scout");
                            }
                        }

                        // Snipers
                        if (mechDef.MechTags.Contains("unit_role_sniper"))
                        {
                            if (mechDef.MechTags.Contains("unit_speed_low") ||
                                (!mechDef.MechTags.Contains("unit_speed_high") && !mechDef.MechTags.Contains("unit_jumpOK")))
                            {
                                // Excluding all piloting 8 if a sniper in medium speed or less mech
                                excludeTags.Add("pilot_npc_flanker");
                                excludeTags.Add("pilot_npc_outrider");
                                excludeTags.Add("pilot_npc_recon");
                            }
                        }

                        // Scouts
                        if (mechDef.MechTags.Contains("unit_role_scout"))
                        {
                            // Let's throw away Coolant Vent in scouts
                            excludeTags.Add("pilot_npc_gladiator");
                            excludeTags.Add("pilot_npc_brawler");
                            excludeTags.Add("pilot_npc_sentinel");

                            if (mechDef.MechTags.Contains("unit_light") ||
                                mechDef.MechTags.Contains("unit_medium"))
                            {
                                // Excluding Gunnery 8 on light and medium scouts
                                excludeTags.Add("pilot_npc_skirmisher");
                                excludeTags.Add("pilot_npc_lancer");
                                excludeTags.Add("pilot_npc_sharpshooter");
                            }
                        }

                        // Slow ass Mechs
                        if (mechDef.MechTags.Contains("unit_speed_low"))
                        {
                            if (!mechDef.MechTags.Contains("unit_jumpOK"))
                            {
                                // Excluding non Outrider, piloting 8 in slow, non JJ Mechs
                                // Leaving Outrider as a brawler might want it even if slow
                                excludeTags.Add("pilot_npc_flanker");
                                excludeTags.Add("pilot_npc_recon");
                            }
                        }

                        // Fast fuckers
                        if (mechDef.MechTags.Contains("unit_speed_high"))
                        {
                            if (mechDef.MechTags.Contains("unit_armor_low") &&
                                !mechDef.MechTags.Contains("unit_role_sniper"))
                            {
                                // We are protected by paper but fast, we are not a sniper, let's use certain combos if we have a tier 2 skill
                                // Excluding Gunnery 8
                                excludeTags.Add("pilot_npc_skirmisher");
                                excludeTags.Add("pilot_npc_lancer");
                                excludeTags.Add("pilot_npc_sharpshooter");

                                // Excluding Gunnery 5 if we don't have Piloting 8
                                excludeTags.Add("pilot_npc_striker");
                                excludeTags.Add("pilot_npc_gladiator");
                            }

                            if (!mechDef.MechTags.Contains("unit_armor_high"))
                            {
                                if (!mechDef.MechTags.Contains("unit_hot"))
                                {
                                    // We aren't high armour, we are fast, and we aren't hot
                                    // Let's throw away Coolant Vent in non hot mechs to improve chances of more appropriate skills
                                    excludeTags.Add("pilot_npc_brawler");
                                    excludeTags.Add("pilot_npc_sentinel");
                                }
                            }
                        }

                        /*
                         * Logger.Log($"Exclusions:");
                         * foreach (string anExclude in excludeTags)
                         * {
                         *  Logger.Log("   " + anExclude);
                         * }*/

                        // TagSet should remove duplicates so no need to do that
                        __instance.pilotExcludedTagSet.AddRange(excludeTags);

                        /*Logger.Log($"Final Exclusions:");
                         * foreach (string anExclude in __instance.pilotExcludedTagSet)
                         * {
                         *  Logger.Log("   " + anExclude);
                         * }*/

                        // Now do the same as the method would and don't call original method
                        PilotDef_MDD pilotDef_MDD = UnitSpawnPointOverride.SelectTaggedPilotDef(mdd, __instance.pilotTagSet, __instance.pilotExcludedTagSet, lanceName, unitIndex);
                        __instance.selectedPilotDefId = pilotDef_MDD.PilotDefID;

                        request.AddBlindLoadRequest(BattleTechResourceType.PilotDef, __instance.selectedPilotDefId, new bool?(false));

                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
            return(true);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }