コード例 #1
0
        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 });
                }
            }
        }
コード例 #2
0
        private void IncreaseLanceSpawnPoints(GameObject playerSpawnGo)
        {
            SpawnableUnit[]   lanceUnits      = MissionControl.Instance.CurrentContract.Lances.GetLanceUnits(EncounterRules.PLAYER_TEAM_ID);
            List <GameObject> unitSpawnPoints = playerSpawnGo.FindAllContains("SpawnPoint");

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

                Main.Logger.Log($"[AddCustomPlayerLanceExtraSpawnPoints] Creating lance 'Player Lance' spawn point 'UnitSpawnPoint{i + 1}'");
                LanceSpawnerFactory.CreateUnitSpawnPoint(playerSpawnGo, $"UnitSpawnPoint{i + 1}", spawnPositon, Guid.NewGuid().ToString());
            }
        }
コード例 #3
0
        private void CreateSpawn(int spawnNumber, GameObject playerSpawnGo, List <GameObject> unitSpawnPoints)
        {
            Vector3 randomLanceSpawn = unitSpawnPoints.GetRandom().transform.localPosition;
            Vector3 spawnPositon     = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100);

            spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid();

            int failSafe = 0;

            while (spawnPositon.IsTooCloseToAnotherSpawn())
            {
                spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100);
                spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid();
                if (failSafe > 20)
                {
                    break;
                }
                failSafe++;
            }

            Main.Logger.Log($"[AddCustomPlayerLanceExtraSpawnPoints] Creating lance 'Player Lance' spawn point 'UnitSpawnPoint{spawnNumber}'");
            LanceSpawnerFactory.CreateUnitSpawnPoint(playerSpawnGo, $"UnitSpawnPoint{spawnNumber}", spawnPositon, Guid.NewGuid().ToString());
        }
コード例 #4
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.");
                }
            }
        }