Esempio n. 1
0
        private IEnumerator SetupPage()
        {
            yield return(null);

            yield return(null);                 // TODO: Double yield return null to ensure this goes after Multiple Bombs? Big oof. Collaborate with the MB team.

            // TODO: Maybe at this point just permanently erase it from the mission binder and store it in the property thing instead?
            Mission currentMission = (Mission)page.GetType().BaseType.GetField("currentMission", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(page);

            ExtendedMissionDetails extendedMissionDetails = ExtendedMissionDetails.ReadMission(currentMission);

            if (extendedMissionDetails.ExtendedSettings.Count == 0)
            {
                Debug.LogFormat("[Extended Mission Settings] Found no settings for {0}", currentMission.DisplayNameTerm);
                yield break;
            }

            foreach (string k in extendedMissionDetails.ExtendedSettings.Keys)
            {
                Debug.LogFormat("[Extended Mission Settings] Found setting for {0}: {1} of size {2}", currentMission.DisplayNameTerm, k, extendedMissionDetails.ExtendedSettings[k].Count);
            }
            bool      canStart      = UpdateMissionDetailInformation(currentMission, currentMission.DescriptionTerm, page, extendedMissionDetails);
            FieldInfo canStartField = typeof(MissionDetailPage).GetField("canStartMission", BindingFlags.Instance | BindingFlags.NonPublic);

            canStartField.SetValue(page, canStart);
        }
Esempio n. 2
0
        private IEnumerator SetupGameplay()
        {
            CurrentMissionDetails = null;
            Mission       mission       = null;
            ComponentPool componentPool = null;

            if (GameplayState.MissionToLoad != ModMission.CUSTOM_MISSION_ID && GameplayState.MissionToLoad != FreeplayMissionGenerator.FREEPLAY_MISSION_ID)
            {
                mission = MissionManager.Instance.GetMission(GameplayState.MissionToLoad);
                Debug.Log("Extended Mission Settings doing the thing");
                CurrentMissionDetails = ExtendedMissionDetails.ReadMission(mission, true, out componentPool);
            }
            else
            {
                yield break;
            }
            Debug.Log("[Extended Mission Settings] Done.");
            yield return(null);

            if (GameplayState.MissionToLoad != ModMission.CUSTOM_MISSION_ID && GameplayState.MissionToLoad != FreeplayMissionGenerator.FREEPLAY_MISSION_ID)
            {
                mission.GeneratorSetting.ComponentPools.Add(componentPool);
            }
        }
Esempio n. 3
0
        public static bool UpdateMissionDetailInformation(Mission mission, string descriptionTerm, MissionDetailPage page, ExtendedMissionDetails details)
        {
            // TODO: Cooperation with the other binder readers (multiple bombs, factory mode) is probably necessary.
            // There'll be race conditions. If they check first and then this, this should work, but
            // if this checks first and then they, they'll likely throw EM in the missing mod types pool again.
            // TODO: Submit a PR there to account for the new boy in town. Although I'm not entirely sure what takes care of
            // 'Factory Mode' mod type. I couldn't find anything about it in Factory Mode's code. A better system may be possible.
            List <string> missingModTypes         = new List <string>();
            int           maxModuleCount          = Math.Max(11, ModManager.Instance.GetMaximumModules());
            int           maxFrontFaceModuleCount = Math.Max(5, ModManager.Instance.GetMaximumModulesFrontFace());

            int notModulesCount = 0;
            //int partialPools = 0;

            bool canStart     = false;
            bool notSupported = false;

            TextMeshPro description     = page.TextDescription;
            string      moduleCountText = page.TextModuleCount.text;

            moduleCountText = moduleCountText.Split(' ')[0];

            foreach (ComponentPool pool in details.GeneratorSetting.ComponentPools)
            {
                int counter = 0;
                foreach (string modType in pool.ModTypes)
                {
                    if (modType == "Factory Mode")
                    {
                        notSupported = true;                            // TODO: Fix this together with the Multiple Bombs team.
                        if (!FindMultipleBombs() || counter > 0)
                        {
                            missingModTypes.Add(modType);
                        }
                        else
                        {
                            notModulesCount++;
                        }
                        break;
                    }
                    if (modType.StartsWith("Multiple Bombs"))
                    {
                        notSupported = true;                            // TODO: Fix this together with the Multiple Bombs team, as right now this overrides multiple bombs doing a missing component error if one of the modules is missing.
                        // Multiple Bombs tosses the entire component pool and only checks index 0. We will do the same.
                        if (!FindMultipleBombs() || counter > 0)
                        {
                            missingModTypes.Add(modType);
                        }
                        else
                        {
                            notModulesCount++;
                        }
                        break;
                    }
                    if (!ModManager.Instance.HasBombComponent(modType))
                    {
                        missingModTypes.Add(modType);
                    }
                    counter++;
                }
            }


            int totalComponentPools = details.GeneratorSetting.ComponentPools.Count;

            if (notSupported)
            {
                // todo: Support multiple bombs.
                page.TextDescription.text = "Using both Extended Mission Settings & Multiple Bombs/Factory Mode is not supported at this time.";
                canStart = false;
            }
            else if (description.text.StartsWith("A room that can support more bombs is required."))
            {
                // multiple bombs already looked at this and determined we need a different room, so the mission can't start regardless. Don't bother.
                canStart = false;
            }
            else if (missingModTypes.Count > 0)
            {
                canStart = false;
                Localization.SetTerm("BombBinder/error_missingModules", description.gameObject);
                Localization.SetParameter("MISSING_MODULES_LIST", string.Join("\n", missingModTypes.ToArray()), description.gameObject);
            }
            else if (totalComponentPools - notModulesCount > maxModuleCount)
            {
                canStart = false;
                Localization.SetTerm("BombBinder/error_needABiggerBomb", description.gameObject);
                Localization.SetParameter("MAX_MODULE_COUNT", maxModuleCount.ToString(), description.gameObject);
            }
            else if (mission.GeneratorSetting.FrontFaceOnly && totalComponentPools - notModulesCount > maxFrontFaceModuleCount)
            {
                canStart = false;
                Localization.SetTerm("BombBinder/error_needABiggerBomb", description.gameObject);
                Localization.SetParameter("MAX_MODULE_COUNT", maxModuleCount.ToString(), description.gameObject);
            }
            else if (details.InvalidJson)
            {
                canStart = false;
                page.TextDescription.text = "An error occured reading the extended mission settings for this mission.";
            }
            else
            {
                canStart = true;
                Localization.SetTerm(descriptionTerm, description.gameObject);
            }

            int totalTotalComponentPools = mission.GeneratorSetting.ComponentPools.Count;
            int writtenModuleCount       = -1;
            int selfCount = totalTotalComponentPools - totalComponentPools;

            if (!int.TryParse(moduleCountText, out writtenModuleCount))
            {
                writtenModuleCount = totalTotalComponentPools;
            }
            if (writtenModuleCount > totalTotalComponentPools)
            {
                // Multiple Bombs established we have more modules due to multiple bombs.
                Localization.SetTerm("BombBinder/txtModuleCount", page.TextModuleCount.gameObject);
                Localization.SetParameter("MODULE_COUNT", (writtenModuleCount - selfCount).ToString(), page.TextModuleCount.gameObject);
            }
            else
            {
                Localization.SetTerm("BombBinder/txtModuleCount", page.TextModuleCount.gameObject);
                Localization.SetParameter("MODULE_COUNT", (totalComponentPools - notModulesCount).ToString(), page.TextModuleCount.gameObject);
            }
            return(canStart);
        }
Esempio n. 4
0
        public static ExtendedMissionDetails ReadMission(Mission mission, bool removeComponentPools, out ComponentPool componentPool)
        {
            // todo: NESTING HELL. Fix
            componentPool = new ComponentPool();
            ExtendedMissionDetails missionDetails = new ExtendedMissionDetails();

            if (mission.GeneratorSetting != null)
            {
                GeneratorSetting generatorSetting = UnityEngine.Object.Instantiate(mission).GeneratorSetting;
                if (generatorSetting.ComponentPools != null)
                {
                    for (int i = generatorSetting.ComponentPools.Count - 1; i >= 0; i--)
                    {
                        ComponentPool pool = generatorSetting.ComponentPools[i];
                        if (pool.ModTypes != null && pool.ModTypes.Count > 0)
                        {
                            for (int j = pool.ModTypes.Count - 1; j >= 0; j--)
                            {
                                string modType = pool.ModTypes[j];
                                if (modType.StartsWith("Extended Settings"))
                                {
                                    int bracketIndex = modType.IndexOf('{');
                                    if (bracketIndex == -1)
                                    {
                                        Debug.LogFormat("[Extended Mission Settings] Encountered missing Json in mission {0}", mission);
                                        missionDetails.InvalidJson = true;
                                        continue;
                                    }
                                    string settings;
                                    settings = modType.Substring(bracketIndex).Trim();
                                    JObject o1;
                                    try {
                                        o1 = JObject.Parse(settings);
                                    }
                                    catch (Exception e) {
                                        Debug.LogFormat("[Extended Mission Settings] Encountered invalid Json in mission {0}: {1}", mission, settings);
                                        Debug.Log(e.Message);
                                        missionDetails.InvalidJson = true;
                                        continue;
                                    }
                                    foreach (var o in o1.Properties())
                                    {
                                        if (o.Value.Type == JTokenType.String || o.Value.Type == JTokenType.Integer)
                                        {
                                            DictionaryAdd(missionDetails.ExtendedSettings, o.Name.ToString(), o.Value.ToString());
                                        }
                                        else if (o.Value.Type == JTokenType.Array)
                                        {
                                            foreach (var p in o.Value)
                                            {
                                                DictionaryAdd(missionDetails.ExtendedSettings, o.Name.ToString(), p.ToString());
                                            }
                                        }
                                    }
                                    generatorSetting.ComponentPools[i].ModTypes.RemoveAt(j);
                                    if (removeComponentPools)
                                    {
                                        if (componentPool.ModTypes == null)
                                        {
                                            componentPool.ModTypes = new List <string>();
                                        }
                                        componentPool.ModTypes.Add(mission.GeneratorSetting.ComponentPools[i].ModTypes[j]);
                                        mission.GeneratorSetting.ComponentPools[i].ModTypes.RemoveAt(j);
                                    }
                                }
                            }
                            if (pool.ModTypes.Count == 0)
                            {
                                generatorSetting.ComponentPools.RemoveAt(i);
                                if (removeComponentPools)
                                {
                                    mission.GeneratorSetting.ComponentPools.RemoveAt(i);
                                }
                            }
                        }
                    }
                }
                missionDetails.GeneratorSetting = generatorSetting;
            }
            return(missionDetails);
        }