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 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 });
                }
            }
        }
Exemple #3
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());
            }
        }
        public override void Run(RunPayload payload)
        {
            Main.Logger.Log($"[AddCustomPlayerLanceSpawnChunk] Adding encounter structure");
            EncounterLayerData        encounterLayerData = MissionControl.Instance.EncounterLayerData;
            EmptyCustomChunkGameLogic emptyCustomChunk   = ChunkFactory.CreateEmptyCustomChunk("Chunk_Lance");

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

            // Auto select Player or Employer based on the lance configurator
            if (teamGuid == null)
            {
                SpawnableUnit[] lanceUnits = MissionControl.Instance.CurrentContract.Lances.GetLanceUnits(EncounterRules.PLAYER_TEAM_ID);
                if (lanceUnits.Length > 4)
                {
                    teamGuid = EncounterRules.PLAYER_TEAM_ID;
                }
                else
                {
                    teamGuid = EncounterRules.EMPLOYER_TEAM_ID;
                }
            }

            // Guard: Don't do anything if there are no employer units and employer mode is on
            SpawnableUnit[] employerLanceUnits = MissionControl.Instance.CurrentContract.Lances.GetLanceUnits(EncounterRules.EMPLOYER_TEAM_ID);
            Main.Logger.Log($"[AddCustomPlayerLanceExtraSpawnPoints] '{employerLanceUnits.Length}' employer lance units are being sent to Mission Control by Bigger Drops.");
            if (employerLanceUnits.Length <= 0)
            {
                return;
            }

            bool spawnOnActivation = true;
            CustomPlayerLanceSpawnerGameLogic lanceSpawner = LanceSpawnerFactory.CreateCustomPlayerLanceSpawner(
                emptyCustomChunk.gameObject,
                spawnerName,
                lanceGuid,
                teamGuid,
                spawnOnActivation,
                SpawnUnitMethodType.ViaLeopardDropship,
                unitGuids
                );

            lanceSpawner.transform.position = Vector3.zero;
        }
Exemple #5
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;
        }
Exemple #6
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());
        }
Exemple #7
0
        private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride)
        {
            List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
            int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString());

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

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

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

                ApplyDifficultyMod(teamOverride, lanceOverride);

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

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

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

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

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

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

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

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

                            string spawnKey = $"{spawnerName}.{unitSpawnGameLogic.gameObject.name}";
                            encounterRules.ObjectLookup[spawnKey] = unitSpawnGameLogic.gameObject;
                            spawnKeys.Add(new string[] { spawnKey, orientationKey });
                        }
                    }
                }
                else
                {
                    Main.Logger.LogWarning($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Spawner is null for {lanceOverride.lanceSpawner.EncounterObjectGuid}. This is probably data from a restarted contract that hasn't been cleared up. It can be safely ignored.");
                }
            }
        }
Exemple #8
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;
            }
        }
        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);
            }
        }