Esempio n. 1
0
        public void StartGame()
        {
            ResetDraw();

            if (!sequenceGenerateRNG)
            {
                GenerateDeck();
            }

            ShuffleDeck();

            foreach (var player in players)
            {
                player.ResetPlayer();
            }

            gameBoard.ResetGameBoard();

            foreach (var player in players)
            {
                player.FillHand();
                player.NotifyEndTurn();
            }

            //TODO: select a first player at random
            players[GameRNG.Randi() % players.Count].NotifyStartTurn();
        }
Esempio n. 2
0
        public Card GetRandomCard()
        {
            int card = GameRNG.Randi() % CardsInHand;
            int c    = 0;

            for (int i = 0; i < currentHand.Length; ++i)
            {
                if (currentHand[i] == null)
                {
                    continue;
                }

                if (c == card)
                {
                    return(currentHand[c]);
                }
                c++;
            }
            return(null);
        }
Esempio n. 3
0
        void SetupDefaultSettings()
        {
            string globalSettingsFilename = Application.persistentDataPath + ModHooks.PathSeperator + GetType().Name + ".GlobalSettings.json";

            bool forceReloadGlobalSettings = false;

            if (GlobalSettings != null && GlobalSettings.SettingsVersion != EnemyRandomizerSettingsVars.GlobalSettingsVersion)
            {
                forceReloadGlobalSettings = true;
            }
            else
            {
                Log("Global settings version match!");
            }

            if (forceReloadGlobalSettings || !File.Exists(globalSettingsFilename))
            {
                if (forceReloadGlobalSettings)
                {
                    Log("Global settings are outdated! Reloading global settings");
                }
                else
                {
                    Log("Global settings file not found, generating new one... File was not found at: " + globalSettingsFilename);
                }

                GlobalSettings.Reset();

                GlobalSettings.SettingsVersion = EnemyRandomizerSettingsVars.GlobalSettingsVersion;

                ChaosRNG         = false;
                RoomRNG          = true;
                RandomizeGeo     = false;
                CustomEnemies    = false;
                GodmasterEnemies = false;
            }

            OptionsMenuSeed = GameRNG.Randi();

            SaveGlobalSettings();
        }
        void GenerateListOfModOptions()
        {
            List <string> modOptions = EnemyRandomizer.Instance.GlobalSettings.BoolValues.Select(x => x.Key).ToList();

            Dev.LogVarArray("modOptions", modOptions);

            modOptions.Insert(0, EnemyRandomizerSettingsVars.Seed);       //option 1
            modOptions.Insert(0, EnemyRandomizerSettingsVars.CustomSeed); //option 0
            modOptions.Add(EnemyRandomizerSettingsVars.CheatNoclip);      //last option

            try
            {
                if (modOptions.Count > 0)
                {
                    RandomizerMenu.modOptions = new Selectable[modOptions.Count];

                    for (int i = 0; i < modOptions.Count; i++)
                    {
                        GameObject menuItemParent = Object.Instantiate(menuTogglePrefab);

                        string optionName  = modOptions[i];
                        string optionLabel = "No Label";

                        Dev.Log("Setting up " + optionName);

                        //create input field for a custom seed -- TODO refactor this into a method to create an input field element easier
                        if (optionName == EnemyRandomizerSettingsVars.CustomSeed)
                        {
                            customSeedInput = menuItemParent.AddComponent <UnityEngine.UI.InputField>();
                            customSeedInput.textComponent = menuItemParent.transform.GetChild(1).GetComponent <Text>();

                            Text t = Object.Instantiate(customSeedInput.textComponent) as Text;
                            t.transform.SetParent(customSeedInput.transform);
                            customSeedInput.placeholder = t;
                            t.horizontalOverflow        = HorizontalWrapMode.Overflow;
                            t.text = "Click to type a custom seed";
                            t.transform.Translate(new Vector3(500f, 0f, 0f));

                            customSeedInput.caretColor  = Color.white;
                            customSeedInput.contentType = InputField.ContentType.IntegerNumber;
                            //customSeedInput.onValueChanged.AddListener( OnCustomSeed );
                            customSeedInput.onEndEdit.AddListener(OnCustomSeed);
                            customSeedInput.navigation     = Navigation.defaultNavigation;
                            customSeedInput.caretWidth     = 8;
                            customSeedInput.characterLimit = 11;

                            ColorBlock cb = new ColorBlock
                            {
                                highlightedColor = Color.yellow,
                                pressedColor     = Color.red,
                                disabledColor    = Color.black,
                                normalColor      = Color.white,
                                colorMultiplier  = 2f
                            };

                            customSeedInput.colors = cb;


                            RandomizerMenu.modOptions[i] = customSeedInput;

                            mainMenuOnlyItems.Add(customSeedInput.gameObject);

                            optionLabel = "Custom Seed";
                            //EnemyRandomizer.Instance.GlobalSettings.StringValues.TryGetValue( "CustomSeed", out optionLabel );
                        }
                        else
                        {
                            RandomizerFauxMenuOptionHorizontal menuItem = menuItemParent.AddComponent <RandomizerFauxMenuOptionHorizontal>();
                            menuItem.navigation = Navigation.defaultNavigation;
                            EnemyRandomizer.Instance.GlobalSettings.StringValues.TryGetValue(optionName, out optionLabel);

                            if (optionName == EnemyRandomizerSettingsVars.Seed)
                            {
                                randoSeedMenuItem = menuItem;
                                mainMenuOnlyItems.Add(menuItem.gameObject);
                                optionLabel = "Seed (Click for new)";
                            }

                            if (optionName == EnemyRandomizerSettingsVars.CheatNoclip)
                            {
                                optionLabel = EnemyRandomizerSettingsVars.CheatNoclip;
                            }

                            //Manages what should happen when the menu option changes (the user clicks and the mod is toggled On/Off)
                            menuItem.OnUpdate += optionIndex =>
                            {
                                if (optionName == EnemyRandomizerSettingsVars.Seed)
                                {
                                    int seed = GameRNG.Randi();
                                    EnemyRandomizer.Instance.OptionsMenuSeed = seed;

                                    menuItem.OptionList[0] = seed.ToString();
                                    if (customSeedInput != null)
                                    {
                                        customSeedInput.text = "";
                                    }
                                }
                                else
                                {
                                    if (optionIndex == 1)
                                    {
                                        if (EnemyRandomizer.Instance.GlobalSettings.BoolValues.ContainsKey(optionName))
                                        {
                                            EnemyRandomizer.Instance.GlobalSettings.BoolValues[optionName] = false;
                                        }

                                        if (optionName == EnemyRandomizerSettingsVars.RNGChaosMode)
                                        {
                                            EnemyRandomizer.Instance.ChaosRNG = false;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.RNGRoomMode)
                                        {
                                            EnemyRandomizer.Instance.RoomRNG = false;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.CheatNoclip)
                                        {
                                            Tools.SetNoclip(false);
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.RandomizeGeo)
                                        {
                                            EnemyRandomizer.Instance.RandomizeGeo = false;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.CustomEnemies)
                                        {
                                            EnemyRandomizer.Instance.CustomEnemies = false;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.GodmasterEnemies)
                                        {
                                            EnemyRandomizer.Instance.GodmasterEnemies = false;
                                        }
                                    }
                                    else
                                    {
                                        if (EnemyRandomizer.Instance.GlobalSettings.BoolValues.ContainsKey(optionName))
                                        {
                                            EnemyRandomizer.Instance.GlobalSettings.BoolValues[optionName] = true;
                                        }

                                        if (optionName == EnemyRandomizerSettingsVars.RNGChaosMode)
                                        {
                                            EnemyRandomizer.Instance.ChaosRNG = true;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.RNGRoomMode)
                                        {
                                            EnemyRandomizer.Instance.RoomRNG = true;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.CheatNoclip)
                                        {
                                            Tools.SetNoclip(true);
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.RandomizeGeo)
                                        {
                                            EnemyRandomizer.Instance.RandomizeGeo = true;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.CustomEnemies)
                                        {
                                            EnemyRandomizer.Instance.CustomEnemies = true;
                                        }
                                        if (optionName == EnemyRandomizerSettingsVars.GodmasterEnemies)
                                        {
                                            EnemyRandomizer.Instance.GodmasterEnemies = true;
                                        }
                                    }
                                }

                                EnemyRandomizer.Instance.SaveGlobalSettings();
                            };

                            menuItem.OptionText = menuItem.gameObject.transform.GetChild(1).GetComponent <Text>();
                            if (optionName == EnemyRandomizerSettingsVars.Seed)
                            {
                                menuItem.OptionList          = new[] { EnemyRandomizer.Instance.OptionsMenuSeed.ToString() };
                                menuItem.SelectedOptionIndex = 0;
                            }
                            else if (optionName == EnemyRandomizerSettingsVars.CheatNoclip)
                            {
                                menuItem.OptionList          = new[] { "On", "Off" };
                                menuItem.SelectedOptionIndex = Tools.NoClipState ? 0 : 1;
                            }
                            else
                            {
                                menuItem.OptionList          = new[] { "On", "Off" };
                                menuItem.SelectedOptionIndex = EnemyRandomizer.Instance.GlobalSettings.BoolValues[optionName] ? 0 : 1;
                            }

                            menuItem.LocalizeText = false;
                            menuItem.SheetTitle   = optionName;
                            menuItem.leftCursor   = menuItem.gameObject.FindGameObjectInChildren("CursorLeft").GetComponent <Animator>();
                            menuItem.rightCursor  = menuItem.gameObject.FindGameObjectInChildren("CursorRight").GetComponent <Animator>();
                            menuItem.cancelAction = CancelAction.DoNothing;

                            RandomizerMenu.modOptions[i] = menuItem;
                        }


                        Object.DestroyImmediate(menuItemParent.FindGameObjectInChildren("Label").GetComponent <AutoLocalizeTextUI>());
                        menuItemParent.FindGameObjectInChildren("Label").GetComponent <Text>().text = optionLabel;

                        menuItemParent.name = optionName;

                        RectTransform rt = menuItemParent.GetComponent <RectTransform>();

                        //rt.SetParent( scrollRect.transform );//TEST -- TODO: fix later
                        rt.SetParent(optionsMenuScreen.content.transform);
                        rt.localScale = new Vector3(2, 2, 2);

                        //rt.sizeDelta = new Vector2( 960, 120 );
                        rt.sizeDelta        = new Vector2(1200, 120);
                        rt.anchoredPosition = new Vector2(0, (766 / 2) - 90 - (150 * i));
                        rt.anchorMin        = new Vector2(0.5f, 1.0f);
                        rt.anchorMax        = new Vector2(0.5f, 1.0f);

                        //TEST -- TODO: fix later
                        //LayoutElement layout = RandomizerMenu.modOptions[ i ].gameObject.AddComponent<LayoutElement>();
                        //layout.preferredWidth = 1200;
                        //layout.preferredHeight = 120;
                    }

                    Navigation[] navs = new Navigation[RandomizerMenu.modOptions.Length];
                    for (int i = 0; i < RandomizerMenu.modOptions.Length; i++)
                    {
                        navs[i] = new Navigation
                        {
                            mode         = Navigation.Mode.Explicit,
                            selectOnUp   = i == 0 ? backButton : RandomizerMenu.modOptions[i - 1],
                            selectOnDown = i == RandomizerMenu.modOptions.Length - 1 ? backButton : RandomizerMenu.modOptions[i + 1]
                        };

                        RandomizerMenu.modOptions[i].navigation = navs[i];
                    }

                    optionsMenuScreen.defaultHighlight = RandomizerMenu.modOptions[1];
                    Navigation nav2 = backButton.navigation;
                    nav2.selectOnUp       = RandomizerMenu.modOptions[RandomizerMenu.modOptions.Length - 1];
                    nav2.selectOnDown     = RandomizerMenu.modOptions[1];
                    backButton.navigation = nav2;
                }
            }
            catch (Exception ex)
            {
                Dev.Log("Exception: " + ex.Message);
            }
        }