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>());

            // Backwards compatibility between EL v1 and v2 for renaming of key
            string targetKey   = (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_TargetLanceSizeOverride)) ? ContractSettingsOverrides.ExtendedLances_TargetLanceSizeOverride : ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride;
            string employerKey = (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_EmployerLanceSizeOverride)) ? ContractSettingsOverrides.ExtendedLances_EmployerLanceSizeOverride : ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride;

            PrepareIncreaseLanceMembers(contractOverride, contractOverride.targetTeam, targetKey, "Target");
            PrepareIncreaseLanceMembers(contractOverride, contractOverride.employerTeam, employerKey, "Employer");

            if (Main.Settings.ExtendedLances.EnableForTargetAlly)
            {
                PrepareIncreaseLanceMembers(contractOverride, contractOverride.targetsAllyTeam, ContractSettingsOverrides.ExtendedLances_TargetAllyLanceSizeOverride, "TargetAlly");
            }
            else
            {
                Main.LogDebug($"[AddExtraLanceSpawnPoints] [{contractOverride.targetsAllyTeam}] TargetAlly is 'false' so will not increase lance members");
            }

            if (Main.Settings.ExtendedLances.EnableForEmployerAlly)
            {
                PrepareIncreaseLanceMembers(contractOverride, contractOverride.employersAllyTeam, ContractSettingsOverrides.ExtendedLances_EmployerAllyLanceSizeOverride, "EmployerAlly");
            }
            else
            {
                Main.LogDebug($"[AddExtraLanceSpawnPoints] [{contractOverride.employersAllyTeam}] EmployerAlly is 'false' so will not increase lance members");
            }

            if (Main.Settings.ExtendedLances.EnableForHostileToAll)
            {
                PrepareIncreaseLanceMembers(contractOverride, contractOverride.hostileToAllTeam, ContractSettingsOverrides.ExtendedLances_HostileToAllLanceSizeOverride, "HostileToAll");
            }
            else
            {
                Main.LogDebug($"[AddExtraLanceSpawnPoints] [{contractOverride.hostileToAllTeam}] HostileToAll is 'false' so will not increase lance members");
            }

            if (Main.Settings.ExtendedLances.EnableForNeutralToAll)
            {
                PrepareIncreaseLanceMembers(contractOverride, contractOverride.neutralToAllTeam, ContractSettingsOverrides.ExtendedLances_NeutralToAllLanceSizeOverride, "NeutralToAll");
            }
            else
            {
                Main.LogDebug($"[AddExtraLanceSpawnPoints] [{contractOverride.neutralToAllTeam}] NeutralToAll is 'false' so will not increase lance members");
            }

            state.Set("ExtraLanceSpawnKeys", spawnKeys);
        }
        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;

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

            state.Set("ExtraLanceSpawnKeys", spawnKeys);
        }
Ejemplo n.º 3
0
        // TODO: Check the object references properly for nulls like the other spawners
        protected override bool GetObjectReferences()
        {
            if (state != null)
            {
                List <string[]> extraLanceKeys = (List <string[]>)state.GetObject("ExtraLanceSpawnKeys");
                for (int i = 0; i < extraLanceKeys.Count; i++)
                {
                    string[] keys                 = extraLanceKeys[i];
                    string   objectKey            = keys[0];
                    string   orientationObjectKey = keys[1];

                    objectKeys.Add(objectKey);
                    orientationTargetKeys.Add(orientationObjectKey);
                    keyLookup[objectKey] = orientationObjectKey;
                }
            }

            for (int i = 0; i < objectKeys.Count; i++)
            {
                GameObject objectGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(objectKeys[i], out objectGoShell);
                objectGos.Add(objectGoShell);
            }

            for (int i = 0; i < orientationTargetKeys.Count; i++)
            {
                GameObject orientationTargetGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(orientationTargetKeys[i], out orientationTargetGoShell);
                orientationTargets[orientationTargetKeys[i]] = orientationTargetGoShell;
            }

            if (defaultOrientationTargetKey != "")
            {
                GameObject defaultOrientationTargetGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(defaultOrientationTargetKey, out defaultOrientationTargetGoShell);
                orientationTargets[defaultOrientationTargetKey] = defaultOrientationTargetGoShell;
            }

            return(true);
        }
Ejemplo n.º 4
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);
        }
        protected override bool GetObjectReferences()
        {
            if (state != null)
            {
                List <string[]> extraLanceKeys = (List <string[]>)state.GetObject("ExtraLanceSpawnKeys");
                for (int i = 0; i < extraLanceKeys.Count; i++)
                {
                    string[] keys = extraLanceKeys[i];

                    if (keys != null && keys.Length > 0)
                    {
                        if (keys.Length == 2)
                        {
                            string objectKey            = keys[0];
                            string orientationObjectKey = keys[1];

                            // Check if the key object and orientation object really exist
                            if (objectKey == null || objectKey == "")
                            {
                                Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] GameObject has a null or empty object key. This is unexpected.");
                                continue;
                            }

                            GameObject objectKeyGO = GameObject.Find(objectKey.Substring(objectKey.IndexOf(".") + 1));
                            if (objectKeyGO == null)
                            {
                                Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] GameObject with key '{objectKey}' was not found. This is unexpected.");
                                continue;
                            }

                            if (orientationObjectKey == null || orientationObjectKey == "")
                            {
                                Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] GameObject has a null or empty orientation object key. This is unexpected.");
                                continue;
                            }

                            GameObject orientationObjectKeyGO = GameObject.Find(orientationObjectKey.Substring(orientationObjectKey.IndexOf(".") + 1));
                            if (orientationObjectKeyGO == null)
                            {
                                Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] GameObject for orientation target with key '{orientationObjectKeyGO}' was not found. This is unexpected.");
                                continue;
                            }

                            objectKeys.Add(objectKey);
                            orientationTargetKeys.Add(orientationObjectKey);
                            keyLookup[objectKey] = orientationObjectKey;
                        }
                        else
                        {
                            Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] ExtraLanceSpawnKeys keyset does not provide exactly a key and orientation key.");
                        }
                    }
                    else
                    {
                        Main.Logger.LogWarning($"[SpawnObjectsAroundTarget] ExtraLanceSpawnKeys provides a first key set but the keyset is null or empty");
                    }
                }
            }

            for (int i = 0; i < objectKeys.Count; i++)
            {
                GameObject objectGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(objectKeys[i], out objectGoShell);
                objectGos.Add(objectGoShell);
            }

            for (int i = 0; i < orientationTargetKeys.Count; i++)
            {
                GameObject orientationTargetGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(orientationTargetKeys[i], out orientationTargetGoShell);
                orientationTargets[orientationTargetKeys[i]] = orientationTargetGoShell;
            }

            if (defaultOrientationTargetKey != "")
            {
                GameObject defaultOrientationTargetGoShell;
                this.EncounterRules.ObjectLookup.TryGetValue(defaultOrientationTargetKey, out defaultOrientationTargetGoShell);
                orientationTargets[defaultOrientationTargetKey] = defaultOrientationTargetGoShell;
            }

            return(true);
        }
        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());
                        }
                    }
                }
            }
        }