Exemple #1
0
        private void IncreaseLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride, int lanceSizeOverride = -1)
        {
            List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
            int factionLanceSize = lanceSizeOverride <= -1 ? Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString()) : lanceSizeOverride;

            Main.LogDebug($"[AddExtraLanceMembers] Faction '{teamOverride.faction}' lance size is '{factionLanceSize}'");

            foreach (LanceOverride lanceOverride in lanceOverrides)
            {
                int  intendedLanceSize            = factionLanceSize;
                int  numberOfUnitsInLanceOverride = lanceOverride.unitSpawnPointOverrideList.Count;
                bool mLanceOverrideSkipAutofill   = false;

                if (lanceOverride is MLanceOverride)
                {
                    MLanceOverride mLanceOverride = (MLanceOverride)lanceOverride;
                    if (!mLanceOverride.SupportAutofill)
                    {
                        Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] [Lance {lanceOverride.GUID}] Lance is an MC defined Lance. It is defined to not support autofilling.");
                    }
                    mLanceOverrideSkipAutofill = !mLanceOverride.SupportAutofill;
                }

                // Store original LanceOverride unitOverride count for later logic
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] [Lance {lanceOverride.GUID}] Saving original LanceOverride UnitOverrideList count of '{numberOfUnitsInLanceOverride}'");
                this.state.Set($"LANCE_ORIGINAL_UNIT_OVERRIDE_COUNT_{lanceOverride.GUID}", numberOfUnitsInLanceOverride);

                // If any lance should be skipped, check and skip
                if (CheckForLanceOverrideSkips(teamOverride, lanceOverride))
                {
                    continue;
                }

                if (IsLanceOverrideForced(lanceOverride))
                {
                    Main.LogDebug($"[AddExtraLanceMembers] Force overriding lance override '{lanceOverride.name}' from faction size of '{intendedLanceSize}' to '{numberOfUnitsInLanceOverride}'");
                    this.state.Set($"LANCE_OVERRIDE_FORCED_{lanceOverride.GUID}", true);
                    intendedLanceSize = numberOfUnitsInLanceOverride;
                }

                ApplyDifficultyMod(teamOverride, lanceOverride);

                // To support LanceDefs that have more than four units in them we need to populate the ContractOverride to contain empty unitSpawnPointOverrides
                // If the lance is: 'Manual', 'Tagged', 'UseLance', or a direct lance reference
                //    - If 'Autofill' is off: we populate with empty slots but we leave the actual resolved filling for later in the life cycle (AddExtraLanceSpawnPoints handles it).
                //    - If 'Autofill' is on: we make copies of any of the tagged unitSpawnPointOverrides in the lance to fill up the slots required
                if (numberOfUnitsInLanceOverride < intendedLanceSize)
                {
                    if (Main.Settings.ExtendedLances.IsAutofillAllowed(contractOverride) && !mLanceOverrideSkipAutofill && !lanceOverride.IsATurretLance() && (lanceOverride.unitSpawnPointOverrideList.Count > 0))
                    {
                        AutofillWithTaggedOrFirstUnitOverrideSlots(teamOverride, lanceOverride, numberOfUnitsInLanceOverride, intendedLanceSize);
                    }
                    else
                    {
                        AutofillWithEmptyUnitOverrideSlots(teamOverride, lanceOverride, numberOfUnitsInLanceOverride, intendedLanceSize);
                    }
                }
            }
        }
Exemple #2
0
        public MLanceOverride SelectAppropriateLanceOverride(string teamType)
        {
            string biome = Enum.GetName(typeof(Biome.BIOMESKIN), MissionControl.Instance.CurrentContract.ContractBiome);

            biome = biome.Capitalise();
            string     contractType = MissionControl.Instance.CurrentContractType;
            FactionDef faction      = MissionControl.Instance.GetFactionFromTeamType(teamType);
            string     factionName  = (faction == null) ? "UNKNOWN" : faction.Name;
            int        factionRep   = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetRawReputation(faction.FactionValue);
            int        mrbRating    = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetRawReputation(FactionEnumeration.GetMercenaryReviewBoardFactionValue());
            int        mrbLevel     = (MissionControl.Instance.IsSkirmish()) ? 0 : UnityGameInstance.Instance.Game.Simulation.GetCurrentMRBLevel();
            bool       useElites    = MissionControl.Instance.ShouldUseElites(faction, teamType);

            Config.Lance  activeAdditionalLance = Main.Settings.ActiveAdditionalLances.GetActiveAdditionalLanceByTeamType(teamType);
            List <string> lancePoolKeys         = Main.Settings.ActiveAdditionalLances.GetLancePoolKeys(teamType, biome, contractType, factionName, factionRep, mrbLevel, mrbRating);

            int    index            = UnityEngine.Random.Range(0, lancePoolKeys.Count);
            string selectedLanceKey = lancePoolKeys[index];

            if (useElites)
            {
                selectedLanceKey = $"{selectedLanceKey}{activeAdditionalLance.EliteLances.Suffix}";
            }

            Main.LogDebug($"[SelectAppropriateLanceOverride] Lance pool keys valid for '{teamType.Capitalise()}', '{biome}', '{contractType}', '{faction}' are '{string.Join(", ", lancePoolKeys.ToArray())}'");

            if (DataManager.Instance.DoesLanceOverrideExist(selectedLanceKey))
            {
                Main.Logger.Log($"[SelectAppropriateLanceOverride] Selected lance key '{selectedLanceKey}'");
                return(DataManager.Instance.GetLanceOverride(selectedLanceKey));
            }
            else
            {
                if (useElites)
                {
                    selectedLanceKey = selectedLanceKey.Replace(activeAdditionalLance.EliteLances.Suffix, "");
                    if (DataManager.Instance.DoesLanceOverrideExist(selectedLanceKey))
                    {
                        Main.Logger.LogError($"[SelectAppropriateLanceOverride] Cannot find 'ELITE' variant of '{selectedLanceKey}' so using original version with a +4 difficulty adjustment.");
                        MLanceOverride lanceOverride = DataManager.Instance.GetLanceOverride(selectedLanceKey);
                        lanceOverride.lanceDifficultyAdjustment = Mathf.Clamp(lanceOverride.lanceDifficultyAdjustment + 4, 1, 10);
                        return(lanceOverride);
                    }
                }

                Main.Logger.LogError($"[SelectAppropriateLanceOverride] MLanceOverride of '{selectedLanceKey}' not found. Defaulting to 'Generic_Light_Battle_Lance'");
                return(DataManager.Instance.GetLanceOverride("Generic_Light_Battle_Lance"));
            }
        }
Exemple #3
0
        private void IncreaseLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride)
        {
            List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
            int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString());

            Main.LogDebug($"[IncreaseLanceMembers] Faction '{teamOverride.faction}' lance size is '{factionLanceSize}");

            foreach (LanceOverride lanceOverride in lanceOverrides)
            {
                Main.LogDebug($"[IncreaseLanceMembers] [{teamOverride.faction}] Checking lance '{lanceOverride.name}'...");

                // GUARD: If an AdditionalLance lance config has been set to 'supportAutofill' false, then don't autofill
                if (lanceOverride is MLanceOverride)
                {
                    MLanceOverride mLanceOverride = (MLanceOverride)lanceOverride;
                    if (!mLanceOverride.SupportAutofill)
                    {
                        Main.LogDebug($"[IncreaseLanceMembers] LanceOverride '{mLanceOverride.GUID}' has 'supportAutofill' explicitly set to 'false' in MC lance '{mLanceOverride.LanceKey}'. Will not autofill.");
                        continue;
                    }
                }

                int  numberOfUnitsInLance   = lanceOverride.unitSpawnPointOverrideList.Count;
                bool isLanceTagged          = lanceOverride.lanceDefId == "Tagged" || lanceOverride.lanceDefId == "UseLance";
                bool AreAnyLanceUnitsTagged = AreAnyLanceMembersTagged(lanceOverride);

                // If tagged, then a lance is selected from the 'data/lance' folder. If we need to increase size we do it later for this usecase.
                // If not, we want to add a new lance member if the vanilla lance size isn't large enough
                //  - If the lance members are 'tagged', then we'll copy any of the tagged units as a base
                //  - If the lance members are 'manual', then do nothing and let the later code handle this usecase
                if (numberOfUnitsInLance < factionLanceSize)
                {
                    if (!isLanceTagged && AreAnyLanceUnitsTagged)
                    {
                        Main.LogDebug($"[IncreaseLanceMembers] [{teamOverride.faction}] Override manual lance '{lanceOverride.name}' size is '{numberOfUnitsInLance}' but '{factionLanceSize}' is required. Adding more units to lance.");
                        lanceOverride.unitSpawnPointOverrideList.Add(lanceOverride.GetAnyTaggedLanceMember().DeepCopy());
                    }
                    else if (!isLanceTagged && !AreAnyLanceUnitsTagged)
                    {
                        Main.Logger.LogWarning($"[AddExtraLanceMembers] [{teamOverride.faction}] The contract '{contractOverride.ID}' for the team '{teamOverride.teamName}' has a manual lance and manual unit setup but it does not specify the right number of lance members. When manually setting lances they should match the Mission Control ExtendedLance lance member count. For this lance you should probably have exactly '{factionLanceSize}' but only '{numberOfUnitsInLance}' are set.");
                    }
                }
            }
        }
Exemple #4
0
        public MLanceOverride GetLanceOverride(string key)
        {
            IDataItemStore <string, LanceDef> lanceDefs = UnityGameInstance.BattleTechGame.DataManager.LanceDefs;

            if (LanceOverrides.ContainsKey(key))
            {
                Main.Logger.Log($"[GetLanceOverride] Found a lance override for '{key}'");
                return(LanceOverrides[key].Copy());
            }

            LanceDef lanceDef = null;

            lanceDefs.TryGet(key, out lanceDef);
            if (lanceDef != null)
            {
                MLanceOverride lanceOverride = new MLanceOverride(lanceDef);
                LanceOverrides.Add(lanceOverride.lanceDefId, lanceOverride);
                Main.Logger.Log($"[GetLanceOverride] Found a lance def for '{key}', creating and caching a lance override for it. Using defaults of 'adjustedDifficulty' of '0' and no 'spawnEffectTags'");
                return(lanceOverride.Copy());
            }
            else
            {
                Main.Logger.Log($"[GetLanceOverride] No loaded LanceDef was found for '{key}'. Attempting to load the LanceDef.");
                lanceDef = BattleTechResourceLoader.LoadDefFromId <LanceDef>(key, BattleTechResourceType.LanceDef);
                DataManager.Instance.RequestResourcesAndProcess(BattleTechResourceType.LanceDef, key);

                if (lanceDef != null)
                {
                    MLanceOverride lanceOverride = new MLanceOverride(lanceDef);
                    LanceOverrides.Add(lanceOverride.lanceDefId, lanceOverride);
                    Main.Logger.Log($"[GetLanceOverride] Load succeeded. Found a lance def for '{key}', creating and caching a lance override for it. Using defaults of 'adjustedDifficulty' of '0' and no 'spawnEffectTags'");
                    return(lanceOverride.Copy());
                }
            }

            Main.Logger.LogError($"[GetLanceOverride] No MC Lance or LanceDef found with key '{key}'. This is a case sensitive search.'");
            return(null);
        }
Exemple #5
0
        public MLanceOverride GetLanceOverride(string key)
        {
            IDataItemStore <string, LanceDef> lanceDefs = UnityGameInstance.BattleTechGame.DataManager.LanceDefs;

            if (LanceOverrides.ContainsKey(key))
            {
                Main.Logger.Log($"[GetLanceOverride] Found a lance override for '{key}'");
                return(LanceOverrides[key]);
            }

            LanceDef lanceDef = null;

            lanceDefs.TryGet(key, out lanceDef);
            if (lanceDef != null)
            {
                MLanceOverride lanceOverride = new MLanceOverride(lanceDef);
                LanceOverrides.Add(lanceOverride.lanceDefId, lanceOverride);
                Main.Logger.Log($"[GetLanceOverride] Found a lance def for '{key}', creating and caching a lance override for it. Using defaults of 'adjustedDifficulty - 0' and no 'spawnEffectTags'");
                return(lanceOverride);
            }

            return(null);
        }
 public AddLanceToTargetTeam(string lanceGuid, List <string> unitGuids, MLanceOverride manuallySpecifiedLance = null)
 {
     this.lanceGuid = lanceGuid;
     this.unitGuids = unitGuids;
     this.manuallySpecifiedLance = manuallySpecifiedLance;
 }
Exemple #7
0
        private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride)
        {
            List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
            int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString());

            foreach (LanceOverride lanceOverride in lanceOverrides)
            {
                bool isManualLance        = lanceOverride.lanceDefId == "Manual";
                int  numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count;

                if (lanceOverride.IsATurretLance())
                {
                    Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected a turret lance Ignoring for Extended Lances.");
                    continue;
                }

                if (isManualLance && numberOfUnitsInLance <= 0)
                {
                    Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected a lance that is set to manual but no units were manually specified. This is a bad contract json setup. Fix it! Ignoring for Extended Lances");
                    continue;
                }

                ApplyDifficultyMod(teamOverride, lanceOverride);

                if ((numberOfUnitsInLance < factionLanceSize) && numberOfUnitsInLance > 0)
                {
                    // This is usually from a 'tagged' lance being selected which has less lance members than the faction lance size
                    if (Main.Settings.ExtendedLances.Autofill)
                    {
                        Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Populated lance '{lanceOverride.name}' has fewer units than the faction requires. Autofilling the missing units");

                        // GUARD: If an AdditionalLance lance config has been set to 'supportAutoFill' false, then don't autofill
                        if (lanceOverride is MLanceOverride)
                        {
                            MLanceOverride mLanceOverride = (MLanceOverride)lanceOverride;
                            if (!mLanceOverride.SupportAutofill)
                            {
                                Main.LogDebug($"[AddExtraLanceSpawnPoints] Lance Override '{mLanceOverride.GUID}' has 'autofill' explicitly turned off in MC lance '{mLanceOverride.LanceKey}'");
                                continue;
                            }
                        }

                        AddNewLanceMembers(contractOverride, teamOverride, lanceOverride, numberOfUnitsInLance, factionLanceSize);
                    }
                    else
                    {
                        Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Populated lance '{lanceOverride.name}' has fewer units than the faction requires. Allowing as a valid setup as 'Autofill' is false");
                    }
                }

                LanceSpawnerGameLogic lanceSpawner = lanceSpawners.Find(spawner => spawner.GUID == lanceOverride.lanceSpawner.EncounterObjectGuid);
                if (lanceSpawner != null)
                {
                    List <GameObject> unitSpawnPoints = lanceSpawner.gameObject.FindAllContains("UnitSpawnPoint");
                    numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count;

                    if (numberOfUnitsInLance > unitSpawnPoints.Count)
                    {
                        Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected lance '{lanceOverride.name}' has more units than lance spawn points. Creating new lance spawns to accommodate.");
                        string     spawnerName     = lanceSpawner.gameObject.name;
                        GameObject orientationUnit = unitSpawnPoints[0].gameObject;
                        string     orientationKey  = $"{spawnerName}.{orientationUnit.name}";
                        encounterRules.ObjectLookup[orientationKey] = orientationUnit;

                        for (int i = unitSpawnPoints.Count; i < numberOfUnitsInLance; i++)
                        {
                            Vector3 randomLanceSpawn = unitSpawnPoints.GetRandom().transform.localPosition;
                            Vector3 spawnPositon     = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100);
                            spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid();

                            // Ensure spawn position isn't on another unit spawn. Give up if one isn't possible.
                            int failSafe = 0;
                            while (spawnPositon.IsTooCloseToAnotherSpawn())
                            {
                                spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100);
                                spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid();
                                if (failSafe > 20)
                                {
                                    break;
                                }
                                failSafe++;
                            }

                            Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Creating lance '{lanceOverride.name}' spawn point 'UnitSpawnPoint{i + 1}'");
                            UnitSpawnPointGameLogic unitSpawnGameLogic = LanceSpawnerFactory.CreateUnitSpawnPoint(lanceSpawner.gameObject, $"UnitSpawnPoint{i + 1}", spawnPositon, lanceOverride.unitSpawnPointOverrideList[i].unitSpawnPoint.EncounterObjectGuid);

                            string spawnKey = $"{spawnerName}.{unitSpawnGameLogic.gameObject.name}";
                            encounterRules.ObjectLookup[spawnKey] = unitSpawnGameLogic.gameObject;
                            spawnKeys.Add(new string[] { spawnKey, orientationKey });
                        }
                    }
                }
                else
                {
                    Main.Logger.LogWarning($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Spawner is null for {lanceOverride.lanceSpawner.EncounterObjectGuid}. This is probably data from a restarted contract that hasn't been cleared up. It can be safely ignored.");
                }
            }
        }
        protected void BuildAdditionalLances(string enemyOrientationTargetKey, SpawnLogic.LookDirection enemyLookDirection, float mustBeBeyondDistanceOfTarget, float mustBeWithinDistanceOfTarget,
                                             string allyOrientationKey, SpawnLogic.LookDirection allyLookDirection, float mustBeBeyondDistance, float mustBeWithinDistance)
        {
            Main.Logger.Log($"[{this.GetType().Name}] Building additional lance rules");

            int numberOfAdditionalEnemyLances = 0;

            if (MissionControl.Instance.AreAdditionalLancesAllowed("enemy"))
            {
                List <string> manuallySpecifiedLances = new List <string>();
                bool          isPrimaryObjective      = MissionControl.Instance.CurrentContractType.In(Main.Settings.AdditionalLanceSettings.IsPrimaryObjectiveIn.ToArray());
                bool          displayToUser           = !Main.Settings.AdditionalLanceSettings.HideObjective;
                bool          excludeFromAutocomplete = MissionControl.Instance.CurrentContractType.In(Main.Settings.AdditionalLanceSettings.ExcludeFromAutocomplete.ToArray());

                Main.Logger.Log($"[{this.GetType().Name}] Excluding Additional Lance from contract type's autocomplete? {excludeFromAutocomplete}");

                if (Main.Settings.AdditionalLanceSettings.AlwaysDisplayHiddenObjectiveIfPrimary)
                {
                    displayToUser = (isPrimaryObjective) ? true : displayToUser;
                }

                Main.Logger.Log($"[{this.GetType().Name}] Additional Lances will be primary objectives? {isPrimaryObjective}");
                FactionDef faction = MissionControl.Instance.GetFactionFromTeamType("enemy");

                numberOfAdditionalEnemyLances = Main.Settings.ActiveAdditionalLances.Enemy.SelectNumberOfAdditionalLances(faction, "enemy");
                if (Main.Settings.DebugMode && (Main.Settings.Debug.AdditionalLancesEnemyLanceCount > -1))
                {
                    numberOfAdditionalEnemyLances = Main.Settings.Debug.AdditionalLancesEnemyLanceCount;
                }

                // Allow contract-specific settings overrides to force their respective setting
                if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.AdditionalLances_EnemyLanceCountOverride))
                {
                    numberOfAdditionalEnemyLances = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.AdditionalLances_EnemyLanceCountOverride);
                    Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lance count will be '{numberOfAdditionalEnemyLances}'.");
                }

                if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.AdditionalLances_EnemyLancesOverride))
                {
                    manuallySpecifiedLances = Main.Settings.ActiveContractSettings.GetList <string>(ContractSettingsOverrides.AdditionalLances_EnemyLancesOverride);
                    Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lances will be '{string.Join(",", manuallySpecifiedLances)}'.");
                }

                bool showObjectiveOnLanceDetected = Main.Settings.AdditionalLanceSettings.ShowObjectiveOnLanceDetected;
                int  objectivePriority            = -10;

                for (int i = 1; i <= numberOfAdditionalEnemyLances; i++)
                {
                    if (MissionControl.Instance.CurrentContractType == "ArenaSkirmish")
                    {
                        new AddPlayer2LanceWithDestroyObjectiveBatch(this, enemyOrientationTargetKey, enemyLookDirection, mustBeBeyondDistanceOfTarget, mustBeWithinDistanceOfTarget,
                                                                     $"Destroy Enemy Support Lance {i}", objectivePriority--, isPrimaryObjective, displayToUser, showObjectiveOnLanceDetected, excludeFromAutocomplete);
                    }
                    else
                    {
                        if (manuallySpecifiedLances.Count >= i)
                        {
                            string         lanceKey      = manuallySpecifiedLances[i - 1];
                            MLanceOverride lanceOverride = DataManager.Instance.GetLanceOverride(lanceKey);
                            Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Resolved Enemy lance will be '{lanceOverride.LanceKey}'.");
                            new AddTargetLanceWithDestroyObjectiveBatch(this, enemyOrientationTargetKey, enemyLookDirection, mustBeBeyondDistanceOfTarget, mustBeWithinDistanceOfTarget,
                                                                        $"Destroy {{TEAM_TAR.FactionDef.Demonym}} Support Lance {i}", objectivePriority--, isPrimaryObjective, displayToUser, showObjectiveOnLanceDetected, excludeFromAutocomplete, lanceOverride);
                        }
                        else
                        {
                            new AddTargetLanceWithDestroyObjectiveBatch(this, enemyOrientationTargetKey, enemyLookDirection, mustBeBeyondDistanceOfTarget, mustBeWithinDistanceOfTarget,
                                                                        $"Destroy {{TEAM_TAR.FactionDef.Demonym}} Support Lance {i}", objectivePriority--, isPrimaryObjective, displayToUser, showObjectiveOnLanceDetected, excludeFromAutocomplete);
                        }
                    }
                }
            }

            if (MissionControl.Instance.AreAdditionalLancesAllowed("allies"))
            {
                List <string> manuallySpecifiedLances = new List <string>();
                FactionDef    faction = MissionControl.Instance.GetFactionFromTeamType("allies");

                int numberOfAdditionalAllyLances = Main.Settings.ActiveAdditionalLances.Allies.SelectNumberOfAdditionalLances(faction, "allies");

                // Allow contract-specific settings overrides to force their respective setting
                if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.AdditionalLances_AllyLanceCountOverride))
                {
                    numberOfAdditionalAllyLances = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.AdditionalLances_AllyLanceCountOverride);
                    Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lance count will be '{numberOfAdditionalAllyLances}'.");
                }
                else if (Main.Settings.AdditionalLanceSettings.MatchAllyLanceCountToEnemy)
                {
                    Main.Logger.LogDebug($"[{this.GetType().Name}] 'MatchAllyLanceCountToEnemy' is on. Ally lance count will be {numberOfAdditionalEnemyLances}");
                    numberOfAdditionalAllyLances = numberOfAdditionalEnemyLances;
                }

                if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.AdditionalLances_AllyLancesOverride))
                {
                    manuallySpecifiedLances = Main.Settings.ActiveContractSettings.GetList <string>(ContractSettingsOverrides.AdditionalLances_AllyLancesOverride);
                    Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lances provided are '{string.Join(",", manuallySpecifiedLances)}'.");
                }

                for (int i = 1; i <= numberOfAdditionalAllyLances; i++)
                {
                    if (manuallySpecifiedLances.Count >= i)
                    {
                        string         lanceKey      = manuallySpecifiedLances[i - 1];
                        MLanceOverride lanceOverride = DataManager.Instance.GetLanceOverride(lanceKey);
                        Main.Logger.Log($"[{this.GetType().Name}] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Resolved Ally lance will be '{lanceOverride.LanceKey}'.");
                        new AddEmployerLanceBatch(this, allyOrientationKey, allyLookDirection, mustBeBeyondDistance, mustBeWithinDistance, lanceOverride);
                    }
                    else
                    {
                        new AddEmployerLanceBatch(this, allyOrientationKey, allyLookDirection, mustBeBeyondDistance, mustBeWithinDistance);
                    }
                }
            }
        }
Exemple #9
0
        public AddEmployerLanceBatch(EncounterRules encounterRules, string orientationTargetKey,
                                     SpawnLogic.LookDirection lookDirection, float minDistance, float maxDistance, MLanceOverride manuallySpecifiedLance = null)
        {
            int           numberOfUnitsInLance = 4;
            string        lanceGuid            = Guid.NewGuid().ToString();
            List <string> unitGuids            = encounterRules.GenerateGuids(numberOfUnitsInLance);
            string        employerTeamGuid     = EncounterRules.EMPLOYER_TEAM_ID;
            string        spawnerName          = $"Lance_Ally_SupportingForce_{lanceGuid}";

            encounterRules.EncounterLogic.Add(new AddLanceToAllyTeam(lanceGuid, unitGuids, manuallySpecifiedLance));
            encounterRules.EncounterLogic.Add(new AddLanceSpawnChunk(employerTeamGuid, lanceGuid, unitGuids, spawnerName,
                                                                     "Spawns a non-objective related ally supporting lance"));
            encounterRules.EncounterLogic.Add(new SpawnLanceMembersAroundTarget(encounterRules, spawnerName, orientationTargetKey,
                                                                                lookDirection, minDistance, maxDistance));

            if (Main.Settings.AdditionalLanceSettings.UseDialogue && !MissionControl.Instance.ContractStats.ContainsKey(ContractStats.DIALOGUE_ADDITIONAL_LANCE_ALLY_START))
            {
                MissionControl.Instance.ContractStats.Add(ContractStats.DIALOGUE_ADDITIONAL_LANCE_ALLY_START, true);
                encounterRules.EncounterLogic.Add(new AddDialogueChunk(
                                                      ChunkLogic.DIALOGUE_ADDITIONAL_LANCE_ALLY_START_GUID,
                                                      "AdditionalLanceAllyStart",
                                                      "Start Conversation For Additional Lance Ally",
                                                      lanceGuid
                                                      // "DialogBucketDef_Universal_KillConfirmed"
                                                      ));
                encounterRules.EncounterLogic.Add(new DialogTrigger(MessageCenterMessageType.OnEncounterIntroComplete, ChunkLogic.DIALOGUE_ADDITIONAL_LANCE_ALLY_START_GUID));
            }

            encounterRules.ObjectReferenceQueue.Add(spawnerName);
        }
        private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride)
        {
            List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
            List <string>        lancesToDelete = new List <string>();

            for (int i = 0; i < lanceOverrides.Count; i++)
            {
                LanceOverride lanceOverride = lanceOverrides[i];
                bool          isManualLance = lanceOverride.lanceDefId == "Manual";

                if (lanceOverride.IsATurretLance())
                {
                    Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints] Detected a turret lance. Skipping.");
                    continue;
                }

                // At this point the number of units in a lance should be the expected amount.
                // The unitSpawnPointOverrides will be up to the EL limit set. They will be either:
                //  - Empty, Null, MechDef_None, Vehicle_None, Turret_None (Because they were a non-inheriting unit, manually entered as such or the LanceDef didn't have enough units to fill up the UnitOverride slots)
                //  - Filled resolved units (Because they were resolved by the LanceOverride LanceDef, or manually entered into the Contract Override)
                //  - 'Tagged', 'UseLance' or 'Manual' slots (Because they were not filled up by the LanceOverride LanceDef selection or Autofilled in Pass 1)
                int numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count;

                if (CheckForLanceSkips(teamOverride, lanceOverride))
                {
                    Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints] Detected a skip for this Lance. Skipping.");
                    continue;
                }

                LanceSpawnerGameLogic lanceSpawner = lanceSpawners.Find(spawner => spawner.GUID == lanceOverride.lanceSpawner.EncounterObjectGuid);
                if (lanceSpawner != null)
                {
                    AddSpawnPoints(lanceSpawner, teamOverride, lanceOverride, numberOfUnitsInLance);
                }
                else
                {
                    Main.Logger.LogWarning($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Spawner is null for {lanceOverride.lanceSpawner.EncounterObjectGuid}. This is probably data from a restarted contract that hasn't been cleared up. It can be safely ignored.");
                    lancesToDelete.Add(lanceOverride.lanceSpawner.EncounterObjectGuid);
                }


                if (Main.Settings.ExtendedLances.IsAutofillAllowed(contractOverride))
                {
                    // GUARD: If an AdditionalLance lance config has been set to 'supportAutoFill' false, then don't autofill
                    if (lanceOverride is MLanceOverride)
                    {
                        MLanceOverride mLanceOverride = (MLanceOverride)lanceOverride;
                        if (!mLanceOverride.SupportAutofill)
                        {
                            Main.LogDebug($"[AddExtraLanceSpawnPoints] Lance Override '{lanceOverride.name} - {mLanceOverride.GUID}' has 'autofill' explicitly turned off in MC lance '{mLanceOverride.LanceKey}'");
                            continue;
                        }
                    }

                    bool lanceOverrideForced = this.state.GetBool($"LANCE_OVERRIDE_FORCED_{lanceOverride.GUID}");
                    bool lanceDefForced      = this.state.GetBool($"LANCE_DEF_FORCED_{lanceOverride.GUID}");
                    if (lanceOverrideForced || lanceDefForced)
                    {
                        Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected that lance '{lanceOverride.name} - {lanceOverride.GUID}' was forced using a LanceOverride or LanceDef EL enforcement. Skipping autofill.");
                        continue;
                    }

                    List <GameObject> unitSpawnPoints = lanceSpawner.gameObject.FindAllContains("UnitSpawnPoint");

                    if (unitSpawnPoints.Count <= 0)
                    {
                        Main.Logger.LogError($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Lance '{lanceOverride.name} - {lanceOverride.GUID}' has no UnitSpawnPoints. A Lance must have at least one unit spawn point to be valid");
                    }

                    List <string> unitSpawnPointGameLogicGUIDs = (List <string>)unitSpawnPoints.Select(unitSpawnPointGO => unitSpawnPointGO.GetComponent <UnitSpawnPointGameLogic>().GUID).ToList();

                    // Only replace unresolved unit overrides if autofill is on
                    int        originalLanceOverrideSize = this.state.GetInt($"LANCE_ORIGINAL_UNIT_OVERRIDE_COUNT_{lanceOverride.GUID}");
                    List <int> unresolvedIndexes         = lanceOverride.GetUnresolvedUnitIndexes(originalLanceOverrideSize);
                    Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected '{unresolvedIndexes.Count}' unresolved unit spawn overrides. Will resolve them before building spawn points.");
                    if (unresolvedIndexes.Count > 0)
                    {
                        LanceDef loadedLanceDef = null;

                        if (!isManualLance)
                        {
                            loadedLanceDef = (LanceDef)AccessTools.Field(typeof(LanceOverride), "loadedLanceDef").GetValue(lanceOverride);
                            Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Loaded LanceDef is '{loadedLanceDef.Description.Id}'");
                        }

                        ReplaceUnresolvedUnitOverride(unitSpawnPointGameLogicGUIDs, teamOverride, lanceOverride, loadedLanceDef, unresolvedIndexes);
                    }

                    // Fix any unmatching UnitSpawnPointOverrideGUIDs-to-UnitSpawnPointGameLogicGUIDs
                    FixMisMatchedGUIDs(unitSpawnPointGameLogicGUIDs, teamOverride, lanceOverride);
                }
            }

            for (int i = (lanceOverrides.Count - 1); i >= 0; i--)
            {
                LanceOverride lanceOverride = lanceOverrides[i];

                foreach (string lanceToDeleteByGuid in lancesToDelete)
                {
                    if (lanceOverride.lanceSpawner.EncounterObjectGuid == lanceToDeleteByGuid)
                    {
                        Main.Logger.LogWarning($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Removing old lance data from contract. Deleting lance '{lanceToDeleteByGuid}'");
                        lanceOverrides.Remove(lanceOverride);
                    }
                }
            }
        }
Exemple #11
0
        public AddTargetLanceWithDestroyObjectiveBatch(EncounterRules encounterRules, string orientationTargetKey,
                                                       SpawnLogic.LookDirection lookDirection, float mustBeBeyondDistance, float mustBeWithinDistance, string objectiveName, int priority,
                                                       bool isPrimaryObjective, bool displayToUser, bool showObjectiveOnLanceDetected, bool excludeFromAutocomplete, MLanceOverride manuallySpecifiedLance = null)
        {
            int           numberOfUnitsInLance  = 4;
            string        lanceGuid             = Guid.NewGuid().ToString();
            string        contractObjectiveGuid = Guid.NewGuid().ToString();
            string        objectiveGuid         = Guid.NewGuid().ToString();
            List <string> unitGuids             = encounterRules.GenerateGuids(numberOfUnitsInLance);
            string        targetTeamGuid        = EncounterRules.TARGET_TEAM_ID;
            string        spawnerName           = $"Lance_Enemy_OpposingForce_{lanceGuid}";

            encounterRules.EncounterLogic.Add(new AddLanceToTargetTeam(lanceGuid, unitGuids, manuallySpecifiedLance));
            encounterRules.EncounterLogic.Add(new AddDestroyWholeUnitChunk(encounterRules, targetTeamGuid, lanceGuid, unitGuids,
                                                                           spawnerName, objectiveGuid, objectiveName, priority, isPrimaryObjective, displayToUser));
            if (!excludeFromAutocomplete)
            {
                encounterRules.EncounterLogic.Add(new AddObjectiveToAutocompleteTrigger(objectiveGuid));
            }
            encounterRules.EncounterLogic.Add(new SpawnLanceMembersAroundTarget(encounterRules, spawnerName, orientationTargetKey,
                                                                                SpawnLogic.LookDirection.AWAY_FROM_TARGET, mustBeBeyondDistance, mustBeWithinDistance));

            if (showObjectiveOnLanceDetected)
            {
                encounterRules.EncounterLogic.Add(new ShowObjectiveTrigger(MessageCenterMessageType.OnLanceDetected, lanceGuid, objectiveGuid, false));
            }

            encounterRules.ObjectReferenceQueue.Add(spawnerName);
        }