public static LanceSpawnerGameLogic CreateLanceSpawner(GameObject parent, string name, string guid, string teamDefinitionGuid, bool spawnUnitsOnActivation,
                                                               SpawnUnitMethodType spawnMethod, List <string> unitGuids)
        {
            GameObject lanceSpawnerGo = new GameObject(name);

            lanceSpawnerGo.transform.parent        = parent.transform;
            lanceSpawnerGo.transform.localPosition = new Vector3(-674, 300, -280);

            LanceSpawnerGameLogic lanceSpawnerGameLogic = lanceSpawnerGo.AddComponent <LanceSpawnerGameLogic>();

            lanceSpawnerGameLogic.encounterObjectGuid    = guid;
            lanceSpawnerGameLogic.teamDefinitionGuid     = teamDefinitionGuid;
            lanceSpawnerGameLogic.spawnMethod            = spawnMethod;
            lanceSpawnerGameLogic.spawnUnitsOnActivation = spawnUnitsOnActivation;

            float x = 0;
            float z = 0;

            for (int i = 0; i < unitGuids.Count; i++)
            {
                CreateUnitSpawnPoint(lanceSpawnerGo, $"UnitSpawnPoint{i + 1}", new Vector3(x, 0, z), unitGuids[i]);
                x += 24;
                z += 24;
            }

            lanceSpawnerGo.AddComponent <SnapToTerrain>();

            return(lanceSpawnerGameLogic);
        }
Пример #2
0
 private void SetDefaultDetectionRange(LanceSpawnerGameLogic spawnerGameLogic, int defaultDetectionRange)
 {
     UnitSpawnPointGameLogic[] unitSpawnPoints = spawnerGameLogic.unitSpawnPointGameLogicList;
     foreach (UnitSpawnPointGameLogic spawnPoint in unitSpawnPoints)
     {
         spawnPoint.defaultDetectionRange = defaultDetectionRange;
     }
 }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddDestroyWholeUnitChunk] Adding encounter structure");
            EncounterLayerData     encounterLayerData = MissionControl.Instance.EncounterLayerData;
            DestroyWholeLanceChunk destroyWholeChunk  = ChunkFactory.CreateDestroyWholeLanceChunk();

            destroyWholeChunk.encounterObjectGuid = System.Guid.NewGuid().ToString();

            this.objectiveLabel = MissionControl.Instance.CurrentContract.Interpolate(this.objectiveLabel).ToString();

            bool spawnOnActivation             = true;
            LanceSpawnerGameLogic lanceSpawner = LanceSpawnerFactory.CreateLanceSpawner(
                destroyWholeChunk.gameObject,
                spawnerName,
                lanceGuid,
                teamGuid,
                spawnOnActivation,
                SpawnUnitMethodType.InstantlyAtSpawnPoint,
                unitGuids
                );
            LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef(lanceSpawner);

            bool showProgress = true;
            DestroyLanceObjective objective = ObjectiveFactory.CreateDestroyLanceObjective(
                objectiveGuid,
                destroyWholeChunk.gameObject,
                lanceSpawnerRef,
                lanceGuid,
                objectiveLabel,
                showProgress,
                ProgressFormat.PERCENTAGE_COMPLETE,
                "The primary objective to destroy the enemy lance",
                priority,
                displayToUser,
                ObjectiveMark.AttackTarget,
                contractObjectiveGameLogicGuid,
                Main.Settings.ActiveAdditionalLances.GetRewards()
                );

            if (isPrimary)
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objective, true);
            }
            else
            {
                AccessTools.Field(typeof(ObjectiveGameLogic), "primary").SetValue(objective, false);
            }

            DestroyLanceObjectiveRef destroyLanceObjectiveRef = new DestroyLanceObjectiveRef();

            destroyLanceObjectiveRef.encounterObject = objective;

            destroyWholeChunk.lanceSpawner     = lanceSpawnerRef;
            destroyWholeChunk.destroyObjective = destroyLanceObjectiveRef;
        }
 private static bool HasLanceSpawnCompleted(LanceSpawnerGameLogic lanceSpawnerGameLogic)
 {
     UnitSpawnPointGameLogic[] unitSpawnPointGameLogicList = lanceSpawnerGameLogic.unitSpawnPointGameLogicList;
     for (int i = 0; i < unitSpawnPointGameLogicList.Length; i++)
     {
         if (unitSpawnPointGameLogicList[i].IsSpawning || unitSpawnPointGameLogicList[i].unitSpawnInProgress)
         {
             return(false);
         }
     }
     return(true);
 }
        public override void Trigger(MessageCenterMessage inMessage, string triggeringName)
        {
            Main.LogDebug($"[SetTeamByLanceSpawnerGuid] Setting Team '{Team}' with Spawner Guid '{LanceSpawnerGuid}'");
            LanceSpawnerGameLogic spawnerGameLogic = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <LanceSpawnerGameLogic>(LanceSpawnerGuid);
            Lance lance = spawnerGameLogic.GetLance();
            List <AbstractActor> lanceUnits = spawnerGameLogic.GetLance().GetLanceUnits();

            Main.LogDebug($"[SetTeamByLanceSpawnerGuid] Found '{lanceUnits.Count}' lance units");
            Team oldTeam = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(spawnerGameLogic.teamDefinitionGuid);
            Team newTeam = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(TeamUtils.GetTeamGuid(Team));

            spawnerGameLogic.teamDefinitionGuid = TeamUtils.GetTeamGuid(Team);
            spawnerGameLogic.encounterTags.Remove(oldTeam.Name);
            spawnerGameLogic.encounterTags.Add(newTeam.Name);

            oldTeam.lances.Remove(lance);
            newTeam.lances.Add(lance);

            foreach (AbstractActor actor in lanceUnits)
            {
                oldTeam.RemoveUnit(actor);
                actor.AddToTeam(newTeam);
                newTeam.AddUnit(actor);

                actor.EncounterTags.Remove(oldTeam.Name);
                actor.EncounterTags.Add(newTeam.Name);

                if (ApplyTags != null)
                {
                    actor.EncounterTags.AddRange(ApplyTags);
                }

                CombatHUDInWorldElementMgr inworldElementManager = GameObject.Find("uixPrfPanl_HUD(Clone)").GetComponent <CombatHUDInWorldElementMgr>();
                if (oldTeam.GUID == TeamUtils.NEUTRAL_TO_ALL_TEAM_ID)
                {
                    AccessTools.Method(typeof(CombatHUDInWorldElementMgr), "AddInWorldActorElements").Invoke(inworldElementManager, new object[] { actor });
                }
                else if (newTeam.GUID == TeamUtils.NEUTRAL_TO_ALL_TEAM_ID)
                {
                    AccessTools.Method(typeof(CombatHUDInWorldElementMgr), "RemoveInWorldUI").Invoke(inworldElementManager, new object[] { actor.GUID });
                }

                CombatantSwitchedTeams message = new CombatantSwitchedTeams(actor.GUID, newTeam.GUID);
                this.combat.MessageCenter.PublishMessage(message);

                LazySingletonBehavior <FogOfWarView> .Instance.FowSystem.Rebuild();
            }

            if (this.AlertLance)
            {
                lance.BroadcastAlert();
            }
        }
Пример #6
0
 private void SetSpawnPointRotations(LanceSpawnerGameLogic spawnerGameLogic)
 {
     UnitSpawnPointGameLogic[] unitSpawnPoints = spawnerGameLogic.unitSpawnPointGameLogicList;
     foreach (UnitSpawnPointGameLogic spawnPoint in unitSpawnPoints)
     {
         JObject rotation = spawnPointRotations.ContainsKey(spawnPoint.encounterObjectGuid) ? (JObject)spawnPointRotations[spawnPoint.encounterObjectGuid] : null;
         if (rotation != null)
         {
             SetRotation(spawnPoint.gameObject, rotation);
         }
     }
 }
Пример #7
0
 private void SetSpawnPointPositions(LanceSpawnerGameLogic spawnerGameLogic)
 {
     UnitSpawnPointGameLogic[] unitSpawnPoints = spawnerGameLogic.unitSpawnPointGameLogicList;
     foreach (UnitSpawnPointGameLogic spawnPoint in unitSpawnPoints)
     {
         JObject position = spawnPointPositions.ContainsKey(spawnPoint.encounterObjectGuid) ? (JObject)spawnPointPositions[spawnPoint.encounterObjectGuid] : null;
         if (position != null)
         {
             SetPosition(spawnPoint.gameObject, position, this.preciseSpawnPoints);
         }
     }
 }
Пример #8
0
 private void SetMountOnPositions(LanceSpawnerGameLogic spawnerGameLogic, JObject mountOnTargets)
 {
     UnitSpawnPointGameLogic[] unitSpawnPoints = spawnerGameLogic.unitSpawnPointGameLogicList;
     foreach (UnitSpawnPointGameLogic spawnPoint in unitSpawnPoints)
     {
         string targetPath = mountOnTargets.ContainsKey(spawnPoint.encounterObjectGuid) ? mountOnTargets[spawnPoint.encounterObjectGuid].ToString() : null;
         if (targetPath != null)
         {
             SetMountOnPosition(spawnPoint.gameObject, targetPath);
         }
     }
 }
Пример #9
0
        public static Lance CreateAmbushLance(Team team)
        {
            Lance  lance     = new Lance(team, new BattleTech.Framework.LanceSpawnerRef[] { });
            Guid   g         = Guid.NewGuid();
            string lanceGuid = LanceSpawnerGameLogic.GetLanceGuid(g.ToString());

            lance.lanceGuid = lanceGuid;
            ModState.Combat.ItemRegistry.AddItem(lance);
            team.lances.Add(lance);

            return(lance);
        }
Пример #10
0
        public override void Trigger(MessageCenterMessage inMessage, string triggeringName)
        {
            Main.LogDebug("[DestroyBuildingsAtLanceSpawnsResult] Setting state...");

            LanceSpawnerGameLogic lanceSpawnerGameLogic = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <LanceSpawnerGameLogic>(LanceSpawnerGuid);

            UnitSpawnPointGameLogic[] unitSpawns = lanceSpawnerGameLogic.GetComponentsInChildren <UnitSpawnPointGameLogic>();

            List <BuildingRepresentation> buildingsInMap = GameObjextExtensions.GetBuildingsInMap();

            Main.LogDebug($"[TagUnitsInRegionResult] Collected '{buildingsInMap.Count}' buildings to check.");

            DestroyBuildingsUnderLanceSpawns(unitSpawns, buildingsInMap.ToArray(), Radius);
        }
        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 });
                }
            }
        }
        static void Prefix(LanceSpawnerGameLogic __instance)
        {
            // Main.LogDebug($"[LanceSpawnerGameLogicOnUnitSpawnCompletePatch] Patching Prefix");
            if (HasLanceSpawnCompleted(__instance))
            {
                LanceSpawnedMessage lanceSpawnedMessage = new LanceSpawnedMessage(__instance.encounterObjectGuid, __instance.LanceGuid);
                EncounterLayerParent.EnqueueLoadAwareMessage(lanceSpawnedMessage);

                /*
                 * // From the unit spawn message - might need a similar one for lance spawning to interrupt
                 * if (this.triggerInterruptPhaseOnSpawn) {
                 * abstractActor.IsInterruptActor = true;
                 * base.Combat.StackManager.InsertInterruptPhase(team.GUID, unitSpawnedMessage.messageIndex);
                 * }
                 */
            }
        }
Пример #13
0
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddLanceSpawnChunk] Adding encounter structure");
            EncounterLayerData        encounterLayerData = MissionControl.Instance.EncounterLayerData;
            EmptyCustomChunkGameLogic emptyCustomChunk   = ChunkFactory.CreateEmptyCustomChunk("Chunk_Lance");

            emptyCustomChunk.encounterObjectGuid = System.Guid.NewGuid().ToString();
            emptyCustomChunk.notes = debugDescription;

            bool spawnOnActivation             = true;
            LanceSpawnerGameLogic lanceSpawner = LanceSpawnerFactory.CreateLanceSpawner(
                emptyCustomChunk.gameObject,
                spawnerName,
                lanceGuid,
                teamGuid,
                spawnOnActivation,
                SpawnUnitMethodType.InstantlyAtSpawnPoint,
                unitGuids
                );

            lanceSpawner.transform.position = Vector3.zero;
        }
Пример #14
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.");
                }
            }
        }
Пример #15
0
 // throw away the return of GetPilotIndex because the method is just adding the missing mechs
 public static void Postfix(LanceSpawnerGameLogic __instance)
 {
     LogDebug("Lance spawn - building pilot index");
     __instance.Combat.AllMechs.ForEach(x => GetActorIndex(x));
 }
Пример #16
0
        public override void Build()
        {
            SpawnUnitMethodType spawnMethodType = SpawnUnitMethodType.ViaLeopardDropship;

            switch (spawnType)
            {
            case "Leopard": spawnMethodType = SpawnUnitMethodType.ViaLeopardDropship; break;

            case "DropPod": spawnMethodType = SpawnUnitMethodType.DropPod; break;

            case "Instant": spawnMethodType = SpawnUnitMethodType.InstantlyAtSpawnPoint; break;

            default: Main.LogDebug($"[SpawnBuilder.{contractTypeBuilder.ContractTypeKey}] No support for spawnType '{spawnType}'. Check for spelling mistakes."); break;
            }

            string teamId = EncounterRules.PLAYER_TEAM_ID;

            switch (team)
            {
            case "Player1": {
                teamId = EncounterRules.PLAYER_TEAM_ID;
                PlayerLanceSpawnerGameLogic playerLanceSpawnerGameLogic = LanceSpawnerFactory.CreatePlayerLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids, true);
                if (position != null)
                {
                    SetPosition(playerLanceSpawnerGameLogic.gameObject, position);
                }
                if (rotation != null)
                {
                    SetRotation(playerLanceSpawnerGameLogic.gameObject, rotation);
                }
                break;
            }

            case "Target": {
                teamId = EncounterRules.TARGET_TEAM_ID;
                LanceSpawnerGameLogic lanceSpawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                if (position != null)
                {
                    SetPosition(lanceSpawnerGameLogic.gameObject, position);
                }
                if (rotation != null)
                {
                    SetRotation(lanceSpawnerGameLogic.gameObject, rotation);
                }
                break;
            }

            case "TargetAlly": {
                teamId = EncounterRules.TARGETS_ALLY_TEAM_ID;
                LanceSpawnerGameLogic lanceSpawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                if (position != null)
                {
                    SetPosition(lanceSpawnerGameLogic.gameObject, position);
                }
                if (rotation != null)
                {
                    SetRotation(lanceSpawnerGameLogic.gameObject, rotation);
                }
                break;
            }

            case "Employer": {
                teamId = EncounterRules.EMPLOYER_TEAM_ID;
                LanceSpawnerGameLogic lanceSpawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                if (position != null)
                {
                    SetPosition(lanceSpawnerGameLogic.gameObject, position);
                }
                if (rotation != null)
                {
                    SetRotation(lanceSpawnerGameLogic.gameObject, rotation);
                }
                break;
            }

            default: Main.LogDebug($"[SpawnBuilder.{contractTypeBuilder.ContractTypeKey}] No support for team '{team}'. Check for spelling mistakes."); break;
            }
        }
        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);
                    }
                }
            }
        }
Пример #18
0
        public override void Build()
        {
            SpawnUnitMethodType spawnMethodType = SpawnUnitMethodType.ViaLeopardDropship;

            switch (spawnType)
            {
            case "Leopard": spawnMethodType = SpawnUnitMethodType.ViaLeopardDropship; break;

            case "DropPod": spawnMethodType = SpawnUnitMethodType.DropPod; break;

            case "Instant": spawnMethodType = SpawnUnitMethodType.InstantlyAtSpawnPoint; break;

            default: Main.LogDebug($"[SpawnBuilder.{contractTypeBuilder.ContractTypeKey}] No support for spawnType '{spawnType}'. Check for spelling mistakes."); break;
            }

            LanceSpawnerGameLogic spawnerGameLogic = null;

            string teamId = TeamUtils.PLAYER_TEAM_ID;

            switch (team)
            {
            case "Player1": {
                teamId           = TeamUtils.PLAYER_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreatePlayerLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids, true);
                break;
            }

            case "Target": {
                teamId           = TeamUtils.TARGET_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                spawnerGameLogic.alertLanceOnSpawn = this.alertLanceOnSpawn;
                if (orders != null)
                {
                    spawnerGameLogic.aiOrderList.contentsBox = orders;
                }
                break;
            }

            case "TargetAlly": {
                teamId           = TeamUtils.TARGETS_ALLY_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                spawnerGameLogic.alertLanceOnSpawn = this.alertLanceOnSpawn;
                if (orders != null)
                {
                    spawnerGameLogic.aiOrderList.contentsBox = orders;
                }
                break;
            }

            case "Employer": {
                teamId           = TeamUtils.EMPLOYER_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                spawnerGameLogic.alertLanceOnSpawn = this.alertLanceOnSpawn;
                if (orders != null)
                {
                    spawnerGameLogic.aiOrderList.contentsBox = orders;
                }
                break;
            }

            case "NeutralToAll": {
                teamId           = TeamUtils.NEUTRAL_TO_ALL_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                spawnerGameLogic.alertLanceOnSpawn = this.alertLanceOnSpawn;
                if (orders != null)
                {
                    spawnerGameLogic.aiOrderList.contentsBox = orders;
                }
                break;
            }

            case "HostileToAll": {
                teamId           = TeamUtils.HOSTILE_TO_ALL_TEAM_ID;
                spawnerGameLogic = LanceSpawnerFactory.CreateLanceSpawner(parent, name, guid, teamId, true, spawnMethodType, spawnPointGuids);
                spawnerGameLogic.alertLanceOnSpawn = this.alertLanceOnSpawn;
                if (orders != null)
                {
                    spawnerGameLogic.aiOrderList.contentsBox = orders;
                }
                break;
            }

            default: Main.Logger.LogError($"[SpawnBuilder.{contractTypeBuilder.ContractTypeKey}] No support for team '{team}'. Check for spelling mistakes."); break;
            }

            if (this.position != null)
            {
                SetPosition(spawnerGameLogic.gameObject, this.position);
            }
            if (this.rotation != null)
            {
                SetRotation(spawnerGameLogic.gameObject, this.rotation);
            }
            if (this.mountOnTargets != null)
            {
                SetMountOnPositions(spawnerGameLogic, this.mountOnTargets);
            }
            if (this.spawnPointPositions != null)
            {
                SetSpawnPointPositions(spawnerGameLogic);
            }
            if (this.spawnPointRotations != null)
            {
                SetSpawnPointRotations(spawnerGameLogic);
            }
            if (this.defaultDetectionRange > 0)
            {
                SetDefaultDetectionRange(spawnerGameLogic, this.defaultDetectionRange);
            }
            if (this.tags != null)
            {
                spawnerGameLogic.encounterTags.AddRange(this.tags);
            }
        }
Пример #19
0
 // throw away the return of GetPilotIndex because the method is just adding the missing mechs
 public static void Postfix(LanceSpawnerGameLogic __instance) => __instance.Combat.AllMechs.ForEach(x => GetPilotIndex(x));