private bool CheckForLanceDefSkips(LanceDef loadedLanceDef, TeamOverride teamOverride, string lanceGUID)
        {
            Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [{teamOverride.faction}] Checking loaded LanceDef '{loadedLanceDef.Description.Id}' for Lance Override '{lanceGUID}'...");

            if (Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAny().Count > 0 && loadedLanceDef.LanceTags.ContainsAny(Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAny()))
            {
                Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [{teamOverride.faction}] LanceDef contains a tag set in 'SkipWhenTaggedWithAny'. Skipping '{loadedLanceDef.Description.Id}'");
                lancesToSkip.Add(lanceGUID);
                return(true);
            }

            if (Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAll().Count > 0 && loadedLanceDef.LanceTags.ContainsAll(Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAll()))
            {
                Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [{teamOverride.faction}] Lance contains a tag set in 'SkipWhenTaggedWithAll'. Skipping '{loadedLanceDef.Description.Id}'");
                lancesToSkip.Add(lanceGUID);
                return(true);
            }

            if (loadedLanceDef.IsATurretLance())
            {
                Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [{teamOverride.faction}] LanceDef is a turret lance. Skipping '{loadedLanceDef.Description.Id}'");
                lancesToSkip.Add(lanceGUID);
                return(true);
            }

            return(false);
        }
        // Clone of DialogueContent::ApplyCastDef
        private static void ApplyCastDef(DialogueContent dialogueContent)
        {
            Contract contract = SharedState.Combat.ActiveContract;

            if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_Employer)
            {
                TeamOverride teamOverride = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamEmployer) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride.teamLeaderCastDefId;
            }
            else if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_EmployersAlly)
            {
                TeamOverride teamOverride2 = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamEmployersAlly) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride2.teamLeaderCastDefId;
            }
            else if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_Target)
            {
                TeamOverride teamOverride3 = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamTarget) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride3.teamLeaderCastDefId;
            }
            else if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_TargetsAlly)
            {
                TeamOverride teamOverride4 = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamTargetsAlly) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride4.teamLeaderCastDefId;
            }
            else if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_Neutral)
            {
                TeamOverride teamOverride5 = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamNeutralToAll) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride5.teamLeaderCastDefId;
            }
            else if (dialogueContent.selectedCastDefId == CastDef.castDef_TeamLeader_Hostile)
            {
                TeamOverride teamOverride6 = contract.GameContext.GetObject(GameContextObjectTagEnum.TeamHostileToAll) as TeamOverride;
                dialogueContent.selectedCastDefId = teamOverride6.teamLeaderCastDefId;
            }
        }
示例#3
0
        private bool CheckForLanceOverrideSkips(TeamOverride teamOverride, LanceOverride lanceOverride)
        {
            Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Checking lance '{lanceOverride.name}'...");
            if (Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAny().Count > 0 && lanceOverride.lanceTagSet.ContainsAny(Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAny()))
            {
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Lance contains a tag set in 'SkipWhenTaggedWithAny'. Skipping '{lanceOverride.name}'");
                lancesToSkip.Add(lanceOverride.GUID);
                return(true);
            }

            if (Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAll().Count > 0 && lanceOverride.lanceTagSet.ContainsAll(Main.Settings.ExtendedLances.GetSkipWhenTaggedWithAll()))
            {
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Lance contains a tag set in 'SkipWhenTaggedWithAll'. Skipping '{lanceOverride.name}'");
                lancesToSkip.Add(lanceOverride.GUID);
                return(true);
            }

            if (Main.Settings.ExtendedLances.GetSkipWhenExcludeTagsContain().Count > 0 && lanceOverride.lanceExcludedTagSet.ContainsAny(Main.Settings.ExtendedLances.GetSkipWhenExcludeTagsContain()))
            {
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Lance contains an exclude tag set in 'GetSkipWhenExcludeTagsContain'. Skipping '{lanceOverride.name}'");
                lancesToSkip.Add(lanceOverride.GUID);
                return(true);
            }

            return(false);
        }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddExtraLanceMembers] Adding extra lance units to lance");
            ContractOverride contractOverride = ((ContractOverridePayload)payload).ContractOverride;

            TeamOverride targetTeamOverride   = contractOverride.targetTeam;
            TeamOverride employerTeamOverride = contractOverride.employerTeam;

            if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride))
            {
                int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride);
                Main.Logger.Log($"[AddExtraLanceMembers] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lance size will be '{lanceSizeOverride}'.");
                IncreaseLanceMembers(contractOverride, targetTeamOverride, lanceSizeOverride);
            }
            else
            {
                IncreaseLanceMembers(contractOverride, targetTeamOverride);
            }

            if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride))
            {
                int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride);
                Main.Logger.Log($"[AddExtraLanceMembers] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lance size will be '{lanceSizeOverride}'.");
                IncreaseLanceMembers(contractOverride, employerTeamOverride, lanceSizeOverride);
            }
            else
            {
                IncreaseLanceMembers(contractOverride, employerTeamOverride);
            }
        }
        public static bool Prefix(LanceOverride __instance, Contract contract, LanceDef lanceDef)
        {
            if (contract != null)
            {
                if (LanceOverride_RunMadLibs.teamOverrides.ContainsKey(__instance.GetHashCode()))
                {
                    // Setup CurrentTeam before running the madlibs
                    TeamOverride teamOverride = LanceOverride_RunMadLibs.teamOverrides[__instance.GetHashCode()];
                    IRBT14MadlibsFix.Logger.Log($"LO:RMLOLD using teamOverride:[{teamOverride.GetHashCode()}] for lanceOverride:[{__instance?.GetHashCode()}]");
                    contract.GameContext.SetObject(GameContextObjectTagEnum.CurrentTeam, teamOverride);
                }
                else
                {
                    IRBT14MadlibsFix.Logger.Log($"LO:RMLOLD COULD NOT LOAD teamOverride using lanceOverride:[{__instance.GetHashCode()}]! MadLibs may break!");
                }

                contract.RunMadLib(lanceDef.LanceTags);

                foreach (LanceDef.Unit unit in lanceDef.LanceUnits)
                {
                    Traverse ensureTagSetsT = Traverse.Create(unit).Method("EnsureTagSets");
                    ensureTagSetsT.GetValue();

                    IRBT14MadlibsFix.Logger.Log($"LO:RMLOLD BEFORE madlibs lanceTagSet is:[{unit.unitTagSet}]");
                    contract.RunMadLib(unit.unitTagSet);
                    IRBT14MadlibsFix.Logger.Log($"LO:RMLOLD AFTER madlibs lanceTagSet is:[{unit.unitTagSet}]");

                    contract.RunMadLib(unit.excludedUnitTagSet);
                    contract.RunMadLib(unit.pilotTagSet);
                    contract.RunMadLib(unit.excludedPilotTagSet);
                }
            }

            return(false);
        }
示例#6
0
    public static TeamOverride GetTeamOverrideLanceBelongsTo(this ContractOverride contractOverride, string lanceGuid)
    {
        TeamOverride player1Team = contractOverride.player1Team;

        if (player1Team.IsLanceInTeam(lanceGuid))
        {
            return(player1Team);
        }

        TeamOverride targetTeam = contractOverride.targetTeam;

        if (targetTeam.IsLanceInTeam(lanceGuid))
        {
            return(targetTeam);
        }

        TeamOverride employerTeam = contractOverride.employerTeam;

        if (employerTeam.IsLanceInTeam(lanceGuid))
        {
            return(employerTeam);
        }

        TeamOverride employerAllyTeam = contractOverride.employersAllyTeam;

        if (employerAllyTeam.IsLanceInTeam(lanceGuid))
        {
            return(employerAllyTeam);
        }

        TeamOverride targetsAllyTeam = contractOverride.targetsAllyTeam;

        if (targetsAllyTeam.IsLanceInTeam(lanceGuid))
        {
            return(targetsAllyTeam);
        }

        TeamOverride neutralToAllTeam = contractOverride.neutralToAllTeam;

        if (neutralToAllTeam.IsLanceInTeam(lanceGuid))
        {
            return(neutralToAllTeam);
        }

        TeamOverride hostilToAllTeam = contractOverride.hostileToAllTeam;

        if (hostilToAllTeam.IsLanceInTeam(lanceGuid))
        {
            return(hostilToAllTeam);
        }

        TeamOverride player2Team = contractOverride.player2Team;

        if (player2Team.IsLanceInTeam(lanceGuid))
        {
            return(player2Team);
        }

        return(null);
    }
示例#7
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);
                    }
                }
            }
        }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddExtraLanceMembers] Adding extra lance units to lance");
            ContractOverride contractOverride = ((ContractOverridePayload)payload).ContractOverride;

            TeamOverride targetTeamOverride   = contractOverride.targetTeam;
            TeamOverride employerTeamOverride = contractOverride.employerTeam;

            IncreaseLanceMembers(contractOverride, targetTeamOverride);
            IncreaseLanceMembers(contractOverride, employerTeamOverride);
        }
        private void ApplyDifficultyMod(TeamOverride teamOverride, LanceOverride lanceOverride)
        {
            int previousAjustedDifficulty        = lanceOverride.lanceDifficultyAdjustment;
            int updatedLanceDifficultyAdjustment = Main.Settings.ExtendedLances.GetFactionLanceDifficulty(teamOverride.faction, lanceOverride);

            if (previousAjustedDifficulty != updatedLanceDifficultyAdjustment)
            {
                Main.Logger.Log($"[AddExtraLanceMembers.ApplyDifficultyMod] [Faction:{teamOverride.faction}] Changing lance '{lanceOverride.name}' adjusted difficulty from '{lanceOverride.lanceDifficultyAdjustment}' to '{updatedLanceDifficultyAdjustment}'");
                lanceOverride.lanceDifficultyAdjustment = updatedLanceDifficultyAdjustment;
            }
        }
示例#10
0
        private void AutofillWithEmptyUnitOverrideSlots(TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLanceOverride, int intendedLanceSize)
        {
            UnitSpawnPointOverride emptyUnitSpawnPointOverride = new UnitSpawnPointOverride();

            emptyUnitSpawnPointOverride.unitDefId = UnitSpawnPointOverride.UseLance;

            for (int i = numberOfUnitsInLanceOverride; i < intendedLanceSize; i++)
            {
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Non-autofill mode. No autofill, turret lance or no units to copy. Expanding lance size for position {i + 1} with a placeholder empty unit override.");
                lanceOverride.unitSpawnPointOverrideList.Add(emptyUnitSpawnPointOverride.DeepCopy());
            }
        }
示例#11
0
    public static bool IsLanceInTeam(this TeamOverride teamOverride, string guid)
    {
        List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;

        foreach (LanceOverride lanceOverride in lanceOverrides)
        {
            if (lanceOverride.GUID == guid)
            {
                return(true);
            }
        }

        return(false);
    }
示例#12
0
 private void PrepareIncreaseLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride, string FactionLanceSizeOverrideKey, string type)
 {
     if (Main.Settings.ActiveContractSettings.Has(FactionLanceSizeOverrideKey))
     {
         int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(FactionLanceSizeOverrideKey);
         Main.Logger.Log($"[AddExtraLanceMembers] [{type} - {teamOverride.faction}] Preparing to increase lance members using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Team '{type}' lance size will be '{lanceSizeOverride}', unless later overridden.");
         IncreaseLanceMembers(contractOverride, teamOverride, lanceSizeOverride);
     }
     else
     {
         Main.Logger.Log($"[AddExtraLanceMembers] [{type} - {teamOverride.faction}] Preparing to increase lance members for contract '{MissionControl.Instance.CurrentContract.Name}'.");
         IncreaseLanceMembers(contractOverride, teamOverride);
     }
 }
        private void AddSpawnPoints(LanceSpawnerGameLogic lanceSpawner, TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLance)
        {
            List <GameObject> unitSpawnPoints = lanceSpawner.gameObject.FindAllContains("UnitSpawnPoint");

            numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count;

            if (unitSpawnPoints.Count <= 0)
            {
                Main.Logger.Log($"[AddSpawnPoints] Spawner '{lanceSpawner.name}' has '0' unit spawns containing the word 'UnitSpawnPoint'. A lance must have at least one valid spawn point. Skipping last '{lanceOverride.name}'");
                return;
            }

            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 j = unitSpawnPoints.Count; j < numberOfUnitsInLance; j++)
                {
                    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{j + 1}'");
                    UnitSpawnPointGameLogic unitSpawnGameLogic = LanceSpawnerFactory.CreateUnitSpawnPoint(lanceSpawner.gameObject, $"UnitSpawnPoint{j + 1}", spawnPositon, lanceOverride.unitSpawnPointOverrideList[j].unitSpawnPoint.EncounterObjectGuid);
                    unitSpawnPoints.Add(unitSpawnGameLogic.gameObject);

                    string spawnKey = $"{spawnerName}.{unitSpawnGameLogic.gameObject.name}";
                    encounterRules.ObjectLookup[spawnKey] = unitSpawnGameLogic.gameObject;
                    spawnKeys.Add(new string[] { spawnKey, orientationKey });
                }
            }
        }
示例#14
0
        private void AddNewLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLance, int factionLanceSize)
        {
            for (int i = numberOfUnitsInLance; i < factionLanceSize; i++)
            {
                UnitSpawnPointOverride originalUnitSpawnPointOverride = lanceOverride.GetAnyTaggedLanceMember();
                if (originalUnitSpawnPointOverride == null)
                {
                    originalUnitSpawnPointOverride = lanceOverride.unitSpawnPointOverrideList[0];
                }
                UnitSpawnPointOverride unitSpawnPointOverride = originalUnitSpawnPointOverride.DeepCopy();
                TagSet companyTags = new TagSet(UnityGameInstance.BattleTechGame.Simulation.CompanyTags);

                unitSpawnPointOverride.GenerateUnit(MetadataDatabase.Instance, UnityGameInstance.Instance.Game.DataManager, lanceOverride.selectedLanceDifficulty, lanceOverride.name, null, i, DataManager.Instance.GetSimGameCurrentDate(), companyTags);
                lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnPointOverride);
            }
        }
        private bool CheckForLanceSkips(TeamOverride teamOverride, LanceOverride lanceOverride)
        {
            if (lancesToSkip.Contains(lanceOverride.GUID))
            {
                Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected a lance to skip. Skipping.");
                return(true);
            }

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

            return(false);
        }
示例#16
0
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddExtraLanceSpawnPoints] Adding lance spawn points to match contract override data");
            Contract           contract           = MissionControl.Instance.CurrentContract;
            EncounterLayerData encounterLayerData = MissionControl.Instance.EncounterLayerData;
            ContractOverride   contractOverride   = contract.Override;

            lanceSpawners = new List <LanceSpawnerGameLogic>(encounterLayerData.gameObject.GetComponentsInChildren <LanceSpawnerGameLogic>());

            TeamOverride targetTeamOverride   = contractOverride.targetTeam;
            TeamOverride employerTeamOverride = contractOverride.employerTeam;

            IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride);
            IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride);

            state.Set("ExtraLanceSpawnKeys", spawnKeys);
        }
        private void FixMisMatchedGUIDs(List <string> unitSpawnPointGameLogicGUIDs, TeamOverride teamOverride, LanceOverride lanceOverride)
        {
            // Get all UnitSpawnPointGameLogic GUIDs
            List <string>  availableUnitSpawnPointGameLogicGUIDsList = new List <string>(unitSpawnPointGameLogicGUIDs);
            Stack <string> availableUnitSpawnPointGameLogicGUIDsStack;

            // Ensure no duplicates exist. If so, modder error in their set up.
            if (unitSpawnPointGameLogicGUIDs.Distinct().ToList().Count != unitSpawnPointGameLogicGUIDs.Count())
            {
                Main.Logger.LogError($"[AddExtraLanceSpawnPoints.FixMisMatchedGUIDs] [Faction:{teamOverride.faction}] The lance '{lanceOverride.GUID}' has duplicate UnitSpawnPointOverride GUIDs. This is incorrect and will cause some units not to spawn! This is not a problem with MC. Please fix this in the contract override data!");
            }

            // Remove any available UnitSpawnPointGameLogicGUIDs that are correctly set in the UnitSpawnPointOverrides
            // The remaining GUIDs are from unassigned UnitSpawnPointGameLogics and they can be assigned below
            foreach (UnitSpawnPointOverride unitSpawnPointOverride in lanceOverride.unitSpawnPointOverrideList)
            {
                if (availableUnitSpawnPointGameLogicGUIDsList.Contains(unitSpawnPointOverride.GUID))
                {
                    availableUnitSpawnPointGameLogicGUIDsList.Remove(unitSpawnPointOverride.GUID);
                }
            }

            Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints.FixMisMatchedGUIDs] [Faction:{teamOverride.faction}] AvailableUnitSpawnPointGameLogicGUIDs will contain Game Logic GUID: '{string.Join(", ", unitSpawnPointGameLogicGUIDs)}'");
            availableUnitSpawnPointGameLogicGUIDsStack = new Stack <string>(availableUnitSpawnPointGameLogicGUIDsList);

            for (int i = 0; i < lanceOverride.unitSpawnPointOverrideList.Count; i++)
            {
                UnitSpawnPointOverride unitSpawnPointOverride = lanceOverride.unitSpawnPointOverrideList[i];
                string unitSpawnPointOverrideGUID             = unitSpawnPointOverride.GUID;

                if (!unitSpawnPointGameLogicGUIDs.Contains(unitSpawnPointOverrideGUID))
                {
                    if (availableUnitSpawnPointGameLogicGUIDsStack.Count > 0)
                    {
                        string guid = availableUnitSpawnPointGameLogicGUIDsStack.Pop();
                        Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints.FixMisMatchedGUIDs] [Faction:{teamOverride.faction}] [Unit{i + 1}] GUID '{unitSpawnPointOverride.unitSpawnPoint.EncounterObjectGuid}' does not exist for a UnitSpawnerGameLogic object. Reassigning with GUID '{guid}'");
                        unitSpawnPointOverride.unitSpawnPoint.EncounterObjectGuid = guid; // If force resolving - then ensure GUIDs for spawner unit spawns are maintained
                    }
                    else
                    {
                        Main.Logger.LogError($"[AddExtraLanceSpawnPoints.FixMisMatchedGUIDs] [Faction:{teamOverride.faction}] [Unit{i + 1}] No available spare unit spawner guids to assign to unit override. This should never happen!");
                    }
                }
            }
        }
        private bool CheckForLanceOverrideSkips(LanceOverride lanceOverride, TeamOverride teamOverride, string lanceGUID)
        {
            Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [{teamOverride.faction}] Checking first pass skips in second pass...");

            if (lancesToSkip.Contains(lanceOverride.GUID))
            {
                Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] [Faction:{teamOverride.faction}] Detected a lance to skip. Skipping.");
                return(true);
            }

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

            return(false);
        }
示例#19
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.");
                    }
                }
            }
        }
示例#20
0
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddLanceToPlayerTeam] Adding lance to player lance");
            ContractOverride contractOverride   = ((ContractOverridePayload)payload).ContractOverride;
            TeamOverride     teamOverride       = contractOverride.player1Team;
            TeamOverride     targetTeamOverride = contractOverride.targetTeam;

            List <LanceOverride> lanceOverrideList = targetTeamOverride.lanceOverrideList;

            if (lanceOverrideList.Count > 0)
            {
                LanceOverride lanceOverride = lanceOverrideList[0].Copy();

                lanceOverride.name = "Lance_Player_Reinforcements";
                lanceOverride.lanceTagSet.Add("lance_type_mech");

                if (unitGuids.Count > 4)
                {
                    for (int i = 4; i < unitGuids.Count; i++)
                    {
                        UnitSpawnPointOverride unitSpawnOverride = lanceOverride.unitSpawnPointOverrideList[0].Copy();
                        lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnOverride);
                    }
                }

                for (int i = 0; i < lanceOverride.unitSpawnPointOverrideList.Count; i++)
                {
                    string            unitGuid     = unitGuids[i];
                    UnitSpawnPointRef unitSpawnRef = new UnitSpawnPointRef();
                    unitSpawnRef.EncounterObjectGuid = unitGuid;
                    lanceOverride.unitSpawnPointOverrideList[i].unitSpawnPoint = unitSpawnRef;
                }

                LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();
                lanceSpawnerRef.EncounterObjectGuid = lanceGuid;
                lanceOverride.lanceSpawner          = lanceSpawnerRef;

                teamOverride.lanceOverrideList.Add(lanceOverride);
            }
            else
            {
                Main.Logger.LogError("[AddLanceToPlayerTeam] Team Override has no lances available to copy. TODO: Generate new lance from stored JSON data");
            }
        }
        private void SwapTeamFactions()
        {
            Contract     contract           = MissionControl.Instance.CurrentContract;
            FactionValue faction1           = contract.GetTeamFaction(team1Guid);
            FactionValue faction2           = contract.GetTeamFaction(team2Guid);
            int          originalFaction1Id = faction1.ID;
            int          originalFaction2Id = faction2.ID;

            Main.LogDebug($"[SwapTeamFactionGameLogic.SwapTeamFactions]) Swapping factions '{team1Guid}:{faction1.Name}' with '{team2Guid}:{faction2.Name}'");
            TeamOverride employer = contract.Override.employerTeam;
            TeamOverride target   = contract.Override.targetTeam;

            contract.Override.employerTeam = target;
            contract.Override.targetTeam   = employer;

            MissionControl.Instance.CurrentContract.SetTeamFaction(team1Guid, originalFaction2Id);
            MissionControl.Instance.CurrentContract.SetTeamFaction(team2Guid, originalFaction1Id);

            contract.Override.RunMadLibs(UnityGameInstance.BattleTechGame.DataManager);
        }
        private bool IsTeamAllowedExtendedLances(ContractOverride contractOverride, TeamOverride teamOverride)
        {
            if ((contractOverride.targetsAllyTeam == teamOverride) && !Main.Settings.ExtendedLances.EnableForTargetAlly)
            {
                return(false);
            }
            if ((contractOverride.employersAllyTeam == teamOverride) && !Main.Settings.ExtendedLances.EnableForEmployerAlly)
            {
                return(false);
            }
            if ((contractOverride.hostileToAllTeam == teamOverride) && !Main.Settings.ExtendedLances.EnableForHostileToAll)
            {
                return(false);
            }
            if ((contractOverride.neutralToAllTeam == teamOverride) && !Main.Settings.ExtendedLances.EnableForNeutralToAll)
            {
                return(false);
            }

            return(true);
        }
        public static bool Prefix(TeamOverride __instance, Contract contract, DataManager dataManager,
                                  ref Contract ___contract, ref DataManager ___dataManager, ref string ___teamLeaderCastDefId, ref List <LanceOverride> ___lanceOverrideList, ref Faction ___faction)
        {
            ___contract    = contract;
            ___dataManager = dataManager;

            if (___teamLeaderCastDefId == CastDef.castDef_TeamLeader_Current)
            {
                ___teamLeaderCastDefId = CastDef.GetCombatCastDefIdFromFaction(___faction, contract.BattleTechGame.DataManager);
            }

            for (int i = 0; i < ___lanceOverrideList.Count; ++i)
            {
                LanceOverride lanceOverride = ___lanceOverrideList[i];
                lanceOverrides[lanceOverride.GetHashCode()] = __instance;
                IRBT14MadlibsFix.Logger.Log($"TO:RML setting teamOverride:[{__instance.GetHashCode()}] for lanceOverride:[{lanceOverride.GetHashCode()}]");
                lanceOverride.RunMadLibs(contract);
            }

            return(false);
        }
        public static bool Prefix(LanceOverride __instance, Contract contract,
                                  ref TagSet ___lanceTagSet, ref TagSet ___lanceExcludedTagSet, ref List <UnitSpawnPointOverride> ___unitSpawnPointOverrideList)
        {
            TeamOverride teamOverride = TeamOverride_RunMadLibs.lanceOverrides[__instance.GetHashCode()];

            IRBT14MadlibsFix.Logger.Log($"LO:RML using teamOverride:[{teamOverride.GetHashCode()}] for lanceOverride:[{__instance?.GetHashCode()}]");
            LanceOverride_RunMadLibs.teamOverrides[__instance.GetHashCode()] = teamOverride;
            contract.GameContext.SetObject(GameContextObjectTagEnum.CurrentTeam, teamOverride);

            IRBT14MadlibsFix.Logger.Log($"LO:RML BEFORE madlibs lanceTagSet is:[{___lanceTagSet}]");
            contract.RunMadLib(___lanceTagSet);
            IRBT14MadlibsFix.Logger.Log($"LO:RML AFTER madlibs lanceTagSet is:[{___lanceTagSet}]");
            contract.RunMadLib(___lanceExcludedTagSet);

            for (int i = 0; i < ___unitSpawnPointOverrideList.Count; ++i)
            {
                ___unitSpawnPointOverrideList[i].RunMadLib(contract);
            }

            return(false);
        }
示例#25
0
        private void AutofillWithTaggedOrFirstUnitOverrideSlots(TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLanceOverride, int intendedLanceSize)
        {
            for (int i = numberOfUnitsInLanceOverride; i < intendedLanceSize; i++)
            {
                UnitSpawnPointOverride originalUnitSpawnPointOverride = lanceOverride.GetAnyTaggedLanceMember();

                if (originalUnitSpawnPointOverride == null)
                {
                    originalUnitSpawnPointOverride = lanceOverride.GetUnitToCopy();
                    Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Autofill mode. Adding unit {i + 1} by duplicating an existing unit.");
                }
                else
                {
                    Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Autofill mode. Adding unit {i + 1} by duplicating a 'Tagged' or 'Use Lance' lance member.");
                }

                UnitSpawnPointOverride unitSpawnPointOverride = originalUnitSpawnPointOverride.DeepCopy();
                unitSpawnPointOverride.customUnitName = "";
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Using unit with old GUID '{originalUnitSpawnPointOverride.GUID}' and new GUID '{unitSpawnPointOverride.GUID}' unitDefId '{unitSpawnPointOverride.unitDefId}' as a base");

                lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnPointOverride);
            }
        }
示例#26
0
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddLanceToAllyTeam] Adding lance to ally lance");
            ContractOverride contractOverride   = ((ContractOverridePayload)payload).ContractOverride;
            TeamOverride     teamOverride       = contractOverride.employerTeam;
            TeamOverride     targetTeamOverride = contractOverride.targetTeam;

            LanceOverride lanceOverride = SelectAppropriateLanceOverride("allies").Copy();

            lanceOverride.name = $"Lance_Ally_Force_{lanceGuid}";

            if (unitGuids.Count > 4)
            {
                for (int i = 4; i < unitGuids.Count; i++)
                {
                    UnitSpawnPointOverride unitSpawnOverride = lanceOverride.unitSpawnPointOverrideList[0].Copy();
                    lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnOverride);
                }
            }

            for (int i = 0; i < lanceOverride.unitSpawnPointOverrideList.Count; i++)
            {
                string            unitGuid     = unitGuids[i];
                UnitSpawnPointRef unitSpawnRef = new UnitSpawnPointRef();
                unitSpawnRef.EncounterObjectGuid = unitGuid;
                lanceOverride.unitSpawnPointOverrideList[i].unitSpawnPoint = unitSpawnRef;
            }

            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();

            lanceSpawnerRef.EncounterObjectGuid = lanceGuid;
            lanceOverride.lanceSpawner          = lanceSpawnerRef;

            lanceOverride.RunMadLibs(contractOverride.contract, teamOverride);

            teamOverride.lanceOverrideList.Add(lanceOverride);
        }
示例#27
0
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddExtraLanceSpawnPoints] Adding lance spawn points to match contract override data");
            Contract           contract           = MissionControl.Instance.CurrentContract;
            EncounterLayerData encounterLayerData = MissionControl.Instance.EncounterLayerData;
            ContractOverride   contractOverride   = contract.Override;

            lancesToSkip  = (List <string>)state.GetObject("LancesToSkip");
            lanceSpawners = new List <LanceSpawnerGameLogic>(encounterLayerData.gameObject.GetComponentsInChildren <LanceSpawnerGameLogic>());

            TeamOverride targetTeamOverride   = contractOverride.targetTeam;
            TeamOverride employerTeamOverride = contractOverride.employerTeam;

            if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride))
            {
                int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride);
                Main.Logger.Log($"[AddExtraLanceSpawnPoints] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lance size will be '{lanceSizeOverride}'.");
                IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride, lanceSizeOverride);
            }
            else
            {
                IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride);
            }

            if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride))
            {
                int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride);
                Main.Logger.Log($"[AddExtraLanceSpawnPoints] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lance size will be '{lanceSizeOverride}'.");
                IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride, lanceSizeOverride);
            }
            else
            {
                IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride);
            }

            state.Set("ExtraLanceSpawnKeys", spawnKeys);
        }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddLanceToTargetTeam] Adding lance to target lance");
            ContractOverride contractOverride = ((ContractOverridePayload)payload).ContractOverride;
            TeamOverride     teamOverride     = contractOverride.targetTeam;

            LanceOverride lanceOverride = (manuallySpecifiedLance == null) ? SelectAppropriateLanceOverride("enemy").Copy() : manuallySpecifiedLance.Copy();

            lanceOverride.name = $"Lance_Enemy_OpposingForce_{lanceGuid}";

            if (unitGuids.Count > 4)
            {
                for (int i = 4; i < unitGuids.Count; i++)
                {
                    UnitSpawnPointOverride unitSpawnOverride = lanceOverride.unitSpawnPointOverrideList[0].Copy();
                    lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnOverride);
                }
            }

            for (int i = 0; i < lanceOverride.unitSpawnPointOverrideList.Count; i++)
            {
                string            unitGuid     = unitGuids[i];
                UnitSpawnPointRef unitSpawnRef = new UnitSpawnPointRef();
                unitSpawnRef.EncounterObjectGuid = unitGuid;
                lanceOverride.unitSpawnPointOverrideList[i].unitSpawnPoint = unitSpawnRef;
            }

            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();

            lanceSpawnerRef.EncounterObjectGuid = lanceGuid;
            lanceOverride.lanceSpawner          = lanceSpawnerRef;

            lanceOverride.RunMadLibs(contractOverride.contract, teamOverride);

            teamOverride.lanceOverrideList.Add(lanceOverride);
        }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddExtraLanceMembersIndividualSecondPass] Running second pass after LanceDef has resolved, if required");
            ContractOverride contractOverride = ((ContractAndLanceOverridePayload)payload).ContractOverride;
            LanceOverride    lanceOverride    = ((ContractAndLanceOverridePayload)payload).LanceOverride;
            bool             isManualLance    = lanceOverride.lanceDefId == "Manual";
            int currentLanceSize = lanceOverride.unitSpawnPointOverrideList.Count;

            TeamOverride teamOverride = contractOverride.GetTeamOverrideLanceBelongsTo(lanceOverride.GUID);

            Main.Logger.Log($"[AddExtraLanceMembersIndividualSecondPass] Team Override for lance '{lanceOverride.name} - {lanceOverride.GUID}' is: {teamOverride.teamName}");

            // GUARD: Don't process factions that aren't allowed
            if (!IsTeamAllowedExtendedLances(contractOverride, teamOverride))
            {
                Main.Logger.Log($"[AddExtraLanceMembersIndividualSecondPass] Ignoring lance '{lanceOverride.name} - {lanceOverride.GUID}' is: {teamOverride.teamName}. Team is not allowed to be extended.");
                return;
            }

            lancesToSkip = (List <string>)state.GetObject("LancesToSkip");

            // Check first pass LanceOverride skips and check LanceDef skips in this second pass, if one exists, and check tags for skipping or override
            if (!isManualLance)
            {
                LanceDef loadedLanceDef = (LanceDef)AccessTools.Field(typeof(LanceOverride), "loadedLanceDef").GetValue(lanceOverride);
                Main.Logger.Log($"[AddExtraLanceMembersIndividualSecondPass] Loaded LanceDef is '{loadedLanceDef.Description.Id}'");

                bool skip = CheckForLanceOverrideSkips(lanceOverride, teamOverride, lanceOverride.GUID);
                if (!skip)
                {
                    skip = CheckForLanceDefSkips(loadedLanceDef, teamOverride, lanceOverride.GUID);
                }

                if (skip)
                {
                    return;
                }


                Main.Logger.Log($"[AddExtraLanceMembersIndividualSecondPass] No Skips Detected. Processing second pass.");

                // Check for LanceDef tags to force LanceDef to override the EL lance unit count
                if (IsLanceDefForced(loadedLanceDef))
                {
                    this.state.Set($"LANCE_DEF_FORCED_{lanceOverride.GUID}", true);

                    int newLanceSize = loadedLanceDef.LanceUnits.Length;
                    Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] Force overriding lance def '{lanceOverride.name}' from faction size of '{currentLanceSize}' to '{newLanceSize}'");

                    if (newLanceSize < currentLanceSize)
                    {
                        // Remove UnitOverrides. Last to First. This is because the override in the LanceDef has fewer units that the EL faction size, or forced Contract Override size
                        for (int i = currentLanceSize - 1; i >= newLanceSize; i--)
                        {
                            Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] Removing UnitOverride '{i + 1}' from LanceOverride");
                            lanceOverride.unitSpawnPointOverrideList.RemoveAt(i);
                        }
                    }
                    else if (newLanceSize > currentLanceSize)
                    {
                        // Add UnitOverrides. This is because the override in the LanceDef has more units that the EL faction size, or forced Contract Override size
                        // This allows the LanceOverride to allocated the correct LanceDef units to the right UnitOverride slots
                        UnitSpawnPointOverride emptyUnitSpawnPointOverride = new UnitSpawnPointOverride();
                        emptyUnitSpawnPointOverride.unitDefId = UnitSpawnPointOverride.UseLance;

                        for (int i = currentLanceSize; i < newLanceSize; i++)
                        {
                            Main.LogDebug($"[AddExtraLanceMembersIndividualSecondPass] Adding UnitOverride '{i + 1}' to LanceOverride");
                            lanceOverride.unitSpawnPointOverrideList.Add(emptyUnitSpawnPointOverride.DeepCopy());
                        }
                    }
                }
            }
        }
示例#30
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.");
                }
            }
        }