/// <summary>Handles debugging features</summary>
        private void Update()
        {
            // retrieve the directors
            {
                if (_inputDir) // prevent user from submitting bug reports.
                {
                    var bugReportUI = _inputDir.bugReportPrefab.GetComponentInChildren<BugReportUI>();
                    bugReportUI.submitButton.interactable = false;
                    bugReportUI.summaryField.interactable = false;
                    bugReportUI.descField.interactable = false;

                    bugReportUI.summaryField.text = "Debug Menu Mod installed - Reporting Issues is deactivated";
                    bugReportUI.descField.text = "Notice: While this debug menu mod is active, you will not be able to report bugs. " +
                                                 "This mod is not supported by Monomi Park and never will be.";
                }
            }
        
            // retrieve object and component references
            if (!_player) _player = GameObject.Find("SimplePlayer");
            if (!_fpController)
            {
                _fpController = _player?.GetComponent<vp_FPController>();
                if (_noclip)
                    StartNoclip();
            }
            if (!_camera) _camera = GameObject.Find("FPSCamera");
            if (!_hudUi) _hudUi = GameObject.Find("HudUI");
        
            // the debug menu shouldn't function if the game is frozen
            if (Time.timeScale <= 0f) return;
        
            // toggle the debug menu
            if (Input.GetKeyDown(KeyCode.F9))
            {
                _debug = !_debug;
            
                // if the debug menu was on previously,
                // turn off any cheats that may be on.
                if (!_debug)
                {
                    _noclip = false;
                    _infiniteEnergy = false;
                    _infiniteHealth = false;
                
                    // make hud visible
                    _hudUi?.SetActive(true);
                }
            }

            // debug mode is off, nothing more to do here
            if (!_debug)
                return;

            // decrement time of day
            if (Input.GetKeyDown(KeyCode.LeftBracket))
            {
                _timeDir?.AdjustTimeOfDay(-0.0416666679f);
            
                // check for negative time
                if (_timeDir?.WorldTime() <= 0f)
                    _timeDir?.SetWorldTime(0f);
            }

            // increment time of day
            else if (Input.GetKeyDown(KeyCode.RightBracket))
                _timeDir?.AdjustTimeOfDay(0.0416666679f);

            // toggle help menu
            if (Input.GetKeyDown(KeyCode.F10))
                _showHelp = !_showHelp;

            // add 1000 credits
            if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus))
                _playerState?.AddCurrency(1000);
        
            // subtract 1000 credits
            else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
                _playerState?.AddCurrency(-1000);

            // toggle heads-up display
            if (Input.GetKeyDown(KeyCode.F6))
                _hudUi?.SetActive(!_hudUi.activeSelf);

            // reset player progress
            if (Input.GetKeyDown(KeyCode.F12))
            {
                Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Reset");
                _pediaDir?.DebugClearUnlocked();
                _tutorialDir?.DebugClearCompleted();
                _achieveDir?.DebugClearAwarded();
                _progressDir?.DebugClearProgress();
            }
        
            // unlock all progress
            else if (Input.GetKeyDown(KeyCode.F11))
            {
                Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Unlocked");
                _pediaDir?.DebugAllUnlocked();
                _tutorialDir?.DebugAllCompleted();
                _progressDir?.DebugUnlockProgress();
            }

            // unlock all upgrades
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                Console.WriteLine("DEBUG: All Personal Upgrades");
                _playerState?.DebugGiveAllUpgrades();
                _playerState?.SetHealth(_playerState.GetMaxHealth());
                _playerState?.SetEnergy(_playerState.GetMaxEnergy());
            
                // add 5 keys
                for (var i = 0; i < 5; i++)
                    _playerState?.AddKey();
            }

            // fill inventory with random items and ammo
            if (Input.GetKeyDown(KeyCode.Alpha9) && _playerState)
            {
                Console.WriteLine("DEBUG: Fill Ammo");
                _playerState?.Ammo?.DebugFillRandomAmmo();
            }

            // toggle infinite energy
            if (Input.GetKeyDown(KeyCode.Alpha6))
                _infiniteEnergy = !_infiniteEnergy;
        
            // toggle infinite health
            if (Input.GetKeyDown(KeyCode.Alpha7))
                _infiniteHealth = !_infiniteHealth;
        
            // clear inventory
            if (Input.GetKeyDown(KeyCode.K))
                _playerState?.Ammo?.Clear();
        
            // refill inventory
            if (Input.GetKeyDown(KeyCode.L) && _playerState)
                _playerState?.Ammo?.DebugRefillAmmo();
        
            // toggle noclip
            if (Input.GetKeyDown(KeyCode.N) && _player)
            {
                if (!_noclip)
                    StartNoclip();
                else
                    StopNoclip();
            }

            // force the game to save
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                Console.WriteLine("DEBUG: Forcing save now");
                _autoSave?.SaveAllNow();
            }

            // handle noclip, if it's enabled
            if (_noclip && _camera && _fpController)
            {
                // calculate speed, will be multiplied by two if run is held
                var speed = 20f * (SRInput.Actions.run.State ? 2f : 1f);
            
                // add movement
                _noclipPos += _camera.transform.forward * SRInput.Actions.vertical.RawValue * speed * Time.deltaTime;
                _noclipPos += _camera.transform.right * SRInput.Actions.horizontal.RawValue * speed * Time.deltaTime;

                // stop all movement on the controller and reposition it
                _fpController?.Stop();
                _fpController?.SetPosition(_noclipPos);
            }

            if (_infiniteEnergy && _playerState) // infinite energy's on, set our energy to max
                _playerState.SetEnergy(_playerState.GetMaxEnergy());
        
            if (_infiniteHealth && _playerState) // god mode's on, set our health to max
                _playerState.SetHealth(_playerState.GetMaxHealth());
        }
Пример #2
0
    /// <summary>Handles debugging features</summary>
    private void Update()
    {
        // the debug menu shouldn't function if the game is frozen
        if (Time.timeScale <= 0f)
        {
            return;
        }

        // toggle the debug menu
        if (Input.GetKeyDown(KeyCode.F9))
        {
            _debug = !_debug;

            // if the debug menu was on previously,
            // turn off any cheats that may be on.
            if (!_debug)
            {
                _noclip         = false;
                _infiniteEnergy = false;
                _infiniteHealth = false;

                // make hud visible
                _hudUi.SetActive(true);
            }
        }

        // debug mode is off, nothing more to do here
        if (!_debug)
        {
            return;
        }

        // retrieve object and component references
        if (_player == null)
        {
            _player = GameObject.Find("SimplePlayer");
        }
        if (_fpController == null)
        {
            _fpController = _player?.GetComponent <vp_FPController>();
        }
        if (_camera == null)
        {
            _camera = GameObject.Find("FPSCamera");
        }
        if (_hudUi == null)
        {
            _hudUi = GameObject.Find("HudUI");
        }

        // decrement time of day
        if (Input.GetKeyDown(KeyCode.LeftBracket))
        {
            _timeDir.AdjustTimeOfDay(-0.0416666679f);

            // check for negative time
            if (_timeDir.WorldTime() <= 0f)
            {
                _timeDir.SetWorldTime(0f);
            }
        }

        // increment time of day
        else if (Input.GetKeyDown(KeyCode.RightBracket))
        {
            _timeDir.AdjustTimeOfDay(0.0416666679f);
        }

        // toggle help menu
        if (Input.GetKeyDown(KeyCode.F10))
        {
            _showHelp = !_showHelp;
        }

        // add 1000 credits
        if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            _playerState.AddCurrency(1000);
        }

        // subtract 1000 credits
        else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            _playerState.AddCurrency(-1000);
        }

        // toggle heads-up display
        if (Input.GetKeyDown(KeyCode.F6))
        {
            _hudUi.SetActive(!_hudUi.activeSelf);
        }

        // reset player progress
        if (Input.GetKeyDown(KeyCode.F12))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Reset");
            _pediaDir.DebugClearUnlocked();
            _tutorialDir.DebugClearCompleted();
            _achieveDir.DebugClearAwarded();
            _progressDir.DebugClearProgress();
        }

        // unlock all progress
        else if (Input.GetKeyDown(KeyCode.F11))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Unlocked");
            _pediaDir.DebugAllUnlocked();
            _tutorialDir.DebugAllCompleted();
            _achieveDir.DebugAllAwarded();
            _progressDir.DebugUnlockProgress();
        }

        // unlock all upgrades
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            Console.WriteLine("DEBUG: All Personal Upgrades");
            _playerState.DebugGiveAllUpgrades();
            _playerState.SetHealth(_playerState.GetMaxHealth());
            _playerState.SetEnergy(_playerState.GetMaxEnergy());

            // add 5 keys
            for (var i = 0; i < 5; i++)
            {
                _playerState.AddKey();
            }
        }

        // fill inventory with random items and ammo
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            Console.WriteLine("DEBUG: Fill Ammo");
            _playerState.Ammo.DebugFillRandomAmmo(_playerState.GetMaxAmmo());
        }

        // toggle infinite energy
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            _infiniteEnergy = !_infiniteEnergy;
        }

        // toggle infinite health
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            _infiniteHealth = !_infiniteHealth;
        }

        // clear inventory
        if (Input.GetKeyDown(KeyCode.M))
        {
            _playerState.Ammo.Clear();
        }

        // toggle noclip
        if (Input.GetKeyDown(KeyCode.N) && _player)
        {
            _noclip    = !_noclip;
            _noclipPos = _player.transform.position;
        }

        // force the game to save
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            Console.WriteLine("DEBUG: Forcing save now");
            _autoSave.SaveAllNow();
        }

        // handle noclip, if it's enabled
        if (_noclip && _camera && _fpController)
        {
            // calculate speed, will be multiplied by two if run is held
            var speed = 20f * (SRInput.Actions.run.State ? 2f : 1f);

            // add movement
            _noclipPos += _camera.transform.forward * SRInput.Actions.vertical.RawValue * speed * Time.deltaTime;
            _noclipPos += _camera.transform.right * SRInput.Actions.horizontal.RawValue * speed * Time.deltaTime;

            // stop all movement on the controller and reposition it
            _fpController.Stop();
            _fpController.SetPosition(_noclipPos);
        }

        if (_infiniteEnergy) // infinite energy's on, set our energy to max
        {
            _playerState.SetEnergy(_playerState.GetMaxEnergy());
        }

        if (_infiniteHealth) // god mode's on, set our health to max
        {
            _playerState.SetHealth(_playerState.GetMaxHealth());
        }
    }
            static void Prefix()
            {
                if (Levels.IsLevel(Levels.WORLD) && SRInput.Instance.GetInputMode() == SRInput.InputMode.DEFAULT)
                {
                    DateTime     currentTime  = DateTime.UtcNow;
                    SceneContext sceneContext = SRSingleton <SceneContext> .Instance;
                    Transform    playerLoc    = SceneContext.Instance.Player.transform;
                    PlayerState  playerState  = SceneContext.Instance.PlayerState;
                    RewardData   reward;
                    if (rewardsQueue.TryDequeue(out reward))
                    {
                        switch (reward.action)
                        {
                        case "sound":
                            break;

                        case "inventory_bomb":
                            Ammo ammo = playerState.Ammo;
                            foreach (Slot s in (Slot[])Traverse.Create(ammo).Property("Slots").GetValue())
                            {
                                if (s == null)
                                {
                                    continue;
                                }
                                for (int i = 0; i < s.count; i++)
                                {
                                    spawnObject(s.id, playerLoc);
                                }
                            }
                            ammo.Clear();
                            break;

                        case "meteor_shower":
                            break;

                        case "downgrade_plot":
                            int duration;
                            int.TryParse(reward.args[0], out duration);
                            int numPlots;
                            int.TryParse(reward.args[1], out numPlots);
                            bool removeAllWalls;
                            bool.TryParse(reward.args[2], out removeAllWalls);
                            delayedDowngrades.Add(new DelayedDowngrade(numPlots, duration, removeAllWalls));
                            break;

                        case "spawn_object":
                            int objectID;
                            int.TryParse(reward.args[0], out objectID);
                            int ammount;
                            int.TryParse(reward.args[1], out ammount);
                            if (Enum.IsDefined(typeof(Identifiable.Id), objectID))
                            {
                                Identifiable.Id obj = (Identifiable.Id)objectID;
                                for (int i = 0; i < ammount; i++)
                                {
                                    spawnObject(obj, playerLoc);
                                }
                            }
                            else
                            {
                                Debug.LogError("Could not spawn in object with the ID of " + objectID + ". INVALID ID!");
                            }
                            break;

                        case "push_player":
                            float pushMin = 0.1f;
                            float.TryParse(reward.args[0], out pushMin);
                            float pushMax = 0.3f;
                            float.TryParse(reward.args[1], out pushMax);
                            if (push)
                            {
                                pushData.left += 8;
                            }
                            else
                            {
                                push     = true;
                                pushData = new PushData(pushMin, pushMax, currentTime, 250);
                            }
                            break;

                        case "adjust_money":
                            int amountToAdjust;
                            int.TryParse(reward.args[0], out amountToAdjust);
                            if (amountToAdjust < 0)
                            {
                                if (playerState.GetCurrency() < amountToAdjust)
                                {
                                    amountToAdjust = playerState.GetCurrency();
                                }
                                playerState.SpendCurrency(amountToAdjust);
                            }
                            else
                            {
                                playerState.AddCurrency(amountToAdjust);
                            }
                            break;

                        case "shoot_gun":
                            WeaponVacuum vacuum = sceneContext.Player.GetComponentInChildren <WeaponVacuum>();
                            Traverse.Create(vacuum).Method("Expel", new HashSet <GameObject>()).GetValue();
                            break;

                        case "day_night":
                            float hour = sceneContext.TimeDirector.CurrHour();
                            if (hour > 6 && hour < 18)
                            {
                                sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetHourAfter(0, 18f));
                            }
                            else
                            {
                                sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetNextDawn());
                            }
                            break;

                        case "stat_edit":
                            string type   = reward.args[0];
                            string action = reward.args[1];
                            int    amount;
                            int.TryParse(reward.args[2], out amount);
                            if (type.Equals("health"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetHealth(Math.Min(playerState.GetCurrHealth() + amount, playerState.GetMaxHealth()));
                                    break;

                                case "sub":
                                    playerState.SetHealth(Math.Max(playerState.GetCurrHealth() - amount, 1));
                                    break;

                                case "max":
                                    playerState.SetHealth(playerState.GetMaxHealth());
                                    break;

                                case "set":
                                    playerState.SetHealth(amount);
                                    break;
                                }
                            }
                            else if (type.Equals("energy"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetEnergy(Math.Min(playerState.GetCurrEnergy() + amount, playerState.GetMaxEnergy()));
                                    break;

                                case "sub":
                                    playerState.SetEnergy(Math.Max(playerState.GetCurrEnergy() - amount, 0));
                                    break;

                                case "max":
                                    playerState.SetEnergy(playerState.GetMaxEnergy());
                                    break;

                                case "set":
                                    playerState.SetEnergy(amount);
                                    break;
                                }
                            }
                            else if (type.Equals("rads"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetRad(playerState.GetCurrRad() + amount);
                                    break;

                                case "sub":
                                    playerState.SetRad(Math.Max(playerState.GetCurrRad() - amount, 0));
                                    break;

                                case "set":
                                    playerState.SetRad(amount);
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    for (int i = plotsEdited.Count - 1; i >= 0; i--)
                    {
                        UpgradeHolder plot = plotsEdited[i];
                        if ((currentTime - plot.Spawned).TotalMilliseconds > plot.Duration)
                        {
                            plotsEdited.RemoveAt(i);
                            plot.Reset();
                        }
                    }

                    if (push)
                    {
                        try
                        {
                            sceneContext.Player.transform.position += pushData.push;
                        }
                        catch
                        {
                            Debug.LogError("PLAYER (or related) IS NULL! Unable to push the player!");
                        }
                        if ((currentTime - pushData.startTime).TotalMilliseconds > pushData.duration)
                        {
                            pushData.left--;
                            if (pushData.left == 0)
                            {
                                push = false;
                            }
                            else
                            {
                                pushData.startTime = currentTime;
                                pushData.nextPush();
                            }
                        }
                    }

                    for (int i = delayedDowngrades.Count - 1; i >= 0; i--)
                    {
                        DelayedDowngrade dd = delayedDowngrades[i];

                        List <LandPlotModel> validplots = new List <LandPlotModel>();
                        //this.GetComponentInParent<Region>();
                        int corralPlots = 0;
                        foreach (LandPlotModel plot in sceneContext.GameModel.AllLandPlots().Values)
                        {
                            if (plot.typeId == LandPlot.Id.CORRAL)
                            {
                                corralPlots++;
                                if (Vector3.Distance(sceneContext.Player.transform.position, ((GameObject)Traverse.Create(plot).Field("gameObj").GetValue()).transform.position) < 100)
                                {
                                    validplots.Add(plot);
                                }
                            }
                        }

                        if (corralPlots != 0 && validplots.Count == 0)
                        {
                            continue;
                        }

                        delayedDowngrades.RemoveAt(i);

                        while (validplots.Count > 0 && dd.numPlots != 0)
                        {
                            LandPlotModel plotModel = validplots.ToArray()[UnityEngine.Random.Range(0, validplots.Count())];
                            validplots.Remove(plotModel);
                            dd.numPlots--;
                            LandPlot plot = ((GameObject)Traverse.Create(plotModel).Field("gameObj").GetValue()).GetComponentInChildren <LandPlot>();
                            HashSet <LandPlot.Upgrade> upgrades = new HashSet <LandPlot.Upgrade>();
                            foreach (PlotUpgrader component in plot.GetComponents <PlotUpgrader>())
                            {
                                if (component is AirNetUpgrader && plot.HasUpgrade(LandPlot.Upgrade.AIR_NET))
                                {
                                    upgrades.Add(LandPlot.Upgrade.AIR_NET);
                                    foreach (GameObject airNet in ((AirNetUpgrader)component).airNets)
                                    {
                                        airNet.SetActive(false);
                                    }
                                }
                                else if (component is SolarShieldUpgrader && plot.HasUpgrade(LandPlot.Upgrade.SOLAR_SHIELD))
                                {
                                    upgrades.Add(LandPlot.Upgrade.SOLAR_SHIELD);
                                    foreach (GameObject shield in ((SolarShieldUpgrader)component).shields)
                                    {
                                        shield.SetActive(false);
                                    }
                                }
                                else if (component is WallUpgrader && plot.HasUpgrade(LandPlot.Upgrade.WALLS))
                                {
                                    upgrades.Add(LandPlot.Upgrade.WALLS);
                                    ((WallUpgrader)component).standardWalls.SetActive(!dd.removeAllWalls);
                                    ((WallUpgrader)component).upgradeWalls.SetActive(false);
                                }
                                plotsEdited.Add(new UpgradeHolder(plot, upgrades, dd.duration * 1000));
                            }
                        }
                    }
                }
            }