private void CheckMenuOpen()
        {
            if (LockPauseModule.GetInputLockState() == InputLockType.All)
            {
                return;
            }

            bool menuToggled = UnityEngine.Input.GetKeyDown(KeyCode.Escape) || MappedInput.GetButtonDown(Input.DefaultControls.OpenMenu);

            if (menuToggled)
            {
                //if we're locked out, let the menu be closed but not opened
                if (!AllowMenu)
                {
                    if (IsOpen)
                    {
                        Close();
                    }
                }
                else
                {
                    //otherwise, flip state
                    Toggle();
                }
            }
        }
Exemple #2
0
        private void HandleView()
        {
            if (!(GameParams.DefaultPlayerView == PlayerViewType.PreferFirst || GameParams.DefaultPlayerView == PlayerViewType.PreferThird))
            {
                return;
            }

            if (MappedInput.GetButtonDown(DefaultControls.ChangeView))
            {
                //slow and stupid but it'll work for now

                GameObject tpCamera = CameraRoot.Find("Main Camera").gameObject;
                GameObject fpCamera = CameraRoot.Find("ViewBobNode").FindDeepChild("FP Camera").gameObject;

                if (tpCamera.activeSelf)
                {
                    fpCamera.SetActive(true);
                    tpCamera.SetActive(false);
                    SetModelVisibility(ModelVisibility.Invisible);
                    PushViewChangeMessage(PlayerViewType.ForceFirst);
                }
                else
                {
                    fpCamera.SetActive(false);
                    tpCamera.SetActive(true);
                    SetModelVisibility(ModelVisibility.Visible);
                    PushViewChangeMessage(PlayerViewType.ForceThird);
                }
            }
        }
Exemple #3
0
        void Update()
        {
            if (Triggered)
            {
                return;
            }

            bool inputPressed = false;

            if (UseKeyInput)
            {
                inputPressed = UnityEngine.Input.GetKeyDown(InputCode);
            }
            else
            {
                inputPressed = MappedInput.GetButtonDown(InputCode);
            }

            if (inputPressed)
            {
                ActionInvokerData d = new ActionInvokerData {
                    Activator = WorldUtils.GetPlayerController()
                };                                                                                             //TODO utility functions
                Special.Invoke(d);

                if (!Repeatable)
                {
                    Triggered = true;
                    SaveState();
                }
            }
        }
 public bool GetButtonDown(string button)
 {
     if (PlayerNumber > 1)
     {
         return(MappedInput.GetButtonDown($"{button}P{PlayerNumber}"));
     }
     return(MappedInput.GetButtonDown(button));
 }
Exemple #5
0
        /// <summary>
        /// Waits a specified number of seconds in real time, can be skipped with skip button
        /// </summary>
        /// <remarks>Can only be used from the main thread</remarks>
        public static async Task DelayRealtime(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime)
            {
                if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                {
                    break;
                }

                await Task.Yield();
            }

            await Task.Yield();
        }
Exemple #6
0
        /// <summary>
        /// Waits for specified time (in real time), can be skipped with skip button
        /// </summary>
        public static IEnumerator WaitForSecondsRealtime(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.unscaledDeltaTime)
            {
                if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                {
                    break;
                }

                yield return(null);
            }

            yield return(null); //necessary for debouncing
        }
Exemple #7
0
        /// <summary>
        /// Waits a specified number of seconds in scaled (game) time, can be skipped with skip button
        /// </summary>
        /// <remarks>Can only be used from the main thread</remarks>
        public static async Task DelayScaled(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.deltaTime)
            {
                if (!LockPauseModule.IsInputLocked())
                {
                    if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                    {
                        break;
                    }
                }

                await Task.Yield();
            }

            await Task.Yield();
        }
Exemple #8
0
        /// <summary>
        /// Waits for specified time, can be skipped with skip button
        /// </summary>
        public static IEnumerator WaitForSeconds(float time)
        {
            for (float elapsed = 0; elapsed < time; elapsed += Time.deltaTime)
            {
                if (!LockPauseModule.IsInputLocked())
                {
                    if (MappedInput.GetButtonDown(SkipButton) || MappedInput.GetButtonDown(AltSkipButton) || MappedInput.GetButtonDown(TerSkipButton))
                    {
                        break;
                    }
                }

                yield return(null);
            }

            yield return(null); //necessary for debouncing
        }
        private bool GetSkipKeyDown()
        {
            if (LockPauseModule.IsInputLocked())
            {
                return(false);
            }

            if (UseUnityInput && (UnityEngine.Input.GetButtonDown("Submit") || UnityEngine.Input.GetKeyDown(KeyCode.Space)))
            {
                return(true);
            }

            if (UseMappedInput && (MappedInput.GetButtonDown(DefaultControls.Confirm) || MappedInput.GetButtonDown(DefaultControls.Fire) || MappedInput.GetButtonDown(DefaultControls.Use)))
            {
                return(true);
            }

            return(false);
        }
Exemple #10
0
        private void CheckMenuOpen()
        {
            if (LockPauseModule.GetInputLockState() == InputLockType.All)
            {
                return;
            }

            bool menuToggled = UnityEngine.Input.GetKeyDown(KeyCode.Escape) || MappedInput.GetButtonDown(Input.DefaultControls.OpenMenu);

            if (menuToggled)
            {
                //if we're locked out, let the menu be closed but not opened
                if (!AllowMenu)
                {
                    if (MainPanel.activeSelf)
                    {
                        MainPanel.SetActive(false);

                        if (HandlePause)
                        {
                            DoUnpause();
                        }

                        foreach (Transform child in ContainerPanel.transform)
                        {
                            child.gameObject.SetActive(false);
                        }

                        ClearEphemeral();
                    }
                }
                else
                {
                    //otherwise, flip state
                    bool newState = !MainPanel.activeSelf;
                    MainPanel.SetActive(newState);

                    if (HandlePause)
                    {
                        if (newState)
                        {
                            DoPause();
                        }
                        else
                        {
                            DoUnpause();
                        }
                    }

                    if (newState && !string.IsNullOrEmpty(DefaultPanel))
                    {
                        OnClickSelectButton(DefaultPanel);
                    }

                    if (!newState)
                    {
                        foreach (Transform child in ContainerPanel.transform)
                        {
                            child.gameObject.SetActive(false);
                        }

                        ClearEphemeral();
                    }

                    if (newState)
                    {
                        //run scripts
                        ScriptingModule.CallHooked(ScriptHook.OnIGUIMenuOpen, this);
                    }
                }
            }
        }
        protected void HandleMovement()
        {
            var playerModel = GameState.Instance.PlayerRpgState;

            if (!GameState.Instance.PlayerFlags.Contains(PlayerFlags.Frozen) && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.TotallyFrozen))
            {
                //handle running
                float energyToRun = RpgValues.GetRunEnergyRate(playerModel);

                IsRunning = MappedInput.GetButton(DefaultControls.Sprint);

                if (RunWasBlocked && IsRunning)
                {
                    IsRunning = false;
                }
                else if (RunWasBlocked && !IsRunning)
                {
                    RunWasBlocked = false;
                }

                if (IsRunning && playerModel.Energy < energyToRun)
                {
                    IsRunning     = false;
                    RunWasBlocked = true;
                    QdmsMessageBus.Instance.PushBroadcast(new QdmsFlagMessage("RpgInsufficientEnergy"));
                }


                //TODO check against energy requirements

                //request an exit from ADS
                if (IsRunning && PlayerController.WeaponComponent != null)
                {
                    PlayerController.WeaponComponent.RequestADSExit();
                }

                //handle crouching
                if (MappedInput.GetButtonDown(DefaultControls.Crouch) && !IsRunning)
                {
                    IsCrouching     = !IsCrouching;
                    DidChangeCrouch = true;
                    SetCrouchState();
                }

                //uncrouch if we try to sprint
                if (IsRunning && IsCrouching)
                {
                    IsCrouching     = false;
                    DidChangeCrouch = true;
                    SetCrouchState();
                }

                if (IsGrounded)
                {
                    //normal x/y movement

                    var flatVelocity = new Vector3(Velocity.x, 0, Velocity.z);

                    Vector3 moveVector = Vector3.zero;

                    float maxAcceleration = IsCrouching ? MaxCrouchAcceleration : (IsRunning ? MaxSprintAcceleration : MaxWalkAcceleration);
                    if (Mathf.Abs(MappedInput.GetAxis(DefaultControls.MoveY)) > InputDeadzone)
                    {
                        moveVector += (transform.forward * MappedInput.GetAxis(DefaultControls.MoveY) * maxAcceleration * Time.deltaTime);
                        IsMoving    = true;
                    }

                    if (Mathf.Abs(MappedInput.GetAxis(DefaultControls.MoveX)) > InputDeadzone)
                    {
                        moveVector += (transform.right * MappedInput.GetAxis(DefaultControls.MoveX) * maxAcceleration * Time.deltaTime);
                        IsMoving    = true;
                    }

                    if (Mathf.Approximately(moveVector.magnitude, 0) && !IsOnSlope)
                    {
                        moveVector = -flatVelocity.normalized * Mathf.Min(MaxBrakeAcceleration * Time.deltaTime, flatVelocity.magnitude);
                    }

                    //clamp velocity to maxwalk/maxrun/etc
                    float maxSpeed = IsCrouching ? MaxCrouchSpeed * RpgValues.GetMoveSpeedMultiplier(playerModel) : (IsRunning ? MaxSprintSpeed * RpgValues.GetRunSpeedMultiplier(playerModel) : MaxWalkSpeed * RpgValues.GetMoveSpeedMultiplier(playerModel));
                    maxSpeed *= ConfigState.Instance.GetGameplayConfig().Difficulty.PlayerAgility;
                    var newFlatVelocity = new Vector3(Velocity.x, 0, Velocity.z) + new Vector3(moveVector.x, 0, moveVector.z);
                    if (newFlatVelocity.magnitude > maxSpeed)
                    {
                        newFlatVelocity = newFlatVelocity.normalized * maxSpeed; //this actually doesn't make a ton of physical sense but it does seem to work
                    }

                    Velocity = new Vector3(newFlatVelocity.x, Velocity.y, newFlatVelocity.z);

                    if (IsRunning)
                    {
                        playerModel.Energy -= energyToRun;
                    }
                }
                else
                {
                    //air move: component wise, clamped

                    //awkward bullshit to go from world to player space
                    Vector3 refVelocity    = Quaternion.AngleAxis(-transform.eulerAngles.y, Vector3.up) * Velocity;
                    Vector3 newAddVelocity = Vector3.zero;

                    float multiplier = ConfigState.Instance.GetGameplayConfig().Difficulty.PlayerAgility;
                    multiplier *= RpgValues.GetAirMoveMultiplier(playerModel);

                    float maxSpeedScaled = MaxAirSpeed * multiplier;

                    float moveZ = MappedInput.GetAxis(DefaultControls.MoveY) * MaxAirAcceleration * multiplier * Time.deltaTime;
                    if (Mathf.Abs(refVelocity.z) < maxSpeedScaled || Mathf.Sign(moveZ) != Mathf.Sign(refVelocity.z))
                    {
                        newAddVelocity += new Vector3(0, 0, moveZ);
                    }

                    float moveX = MappedInput.GetAxis(DefaultControls.MoveX) * MaxAirAcceleration * multiplier * Time.deltaTime;
                    if (Mathf.Abs(refVelocity.x) < maxSpeedScaled || Mathf.Sign(moveX) != Mathf.Sign(refVelocity.x))
                    {
                        newAddVelocity += new Vector3(moveX, 0, 0);
                    }

                    Velocity += Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * newAddVelocity;
                }

                if (IsGrounded && (AllowSlopeJumping || !IsOnSlope))
                {
                    //jumping
                    if (MappedInput.GetButtonDown(DefaultControls.Jump))
                    {
                        var   jumpVelocity  = JumpInstantaneousVelocity * RpgValues.GetJumpVelocityMultiplier(playerModel) * ConfigState.Instance.GetGameplayConfig().Difficulty.PlayerAgility;
                        float jumpEnergyUse = RpgValues.GetJumpEnergyUse(playerModel);

                        if (playerModel.Energy >= jumpEnergyUse)
                        {
                            playerModel.Energy -= jumpEnergyUse;
                            bool wasCrouched = IsCrouching;

                            //uncrouch if we were crouched
                            if (wasCrouched)
                            {
                                IsCrouching     = false;
                                DidChangeCrouch = true;
                                SetCrouchState();
                                jumpVelocity += JumpCrouchBoostVelocity;
                            }

                            Velocity += Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * jumpVelocity;
                            CharController.Move(Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * JumpInstantaneousDisplacement);
                            JumpSound.Ref()?.Play();
                            DidJump = true;
                        }
                        else
                        {
                            //failed to jump
                            QdmsMessageBus.Instance.PushBroadcast(new QdmsFlagMessage("RpgInsufficientEnergy"));
                        }
                    }
                }
            }

            //energy recovery
            if (!IsRunning && IsGrounded && !DidJump)
            {
                float energyGain = (IsMoving ? RpgValues.GetMovingEnergyRecoveryRate(playerModel) : RpgValues.GetIdleEnergyRecoveryRate(playerModel)) * Time.deltaTime;
                playerModel.Energy = Mathf.Min(playerModel.DerivedStats.MaxEnergy, playerModel.Energy + energyGain);
            }
        }
Exemple #12
0
        private void HandleInteraction()
        {
            //get thing, probe and display tooltip, check use

            bool haveTarget = false;

            int layerMask = LayerMask.GetMask("Default", "ActorHitbox", "Actor");

            Debug.DrawRay(CameraRoot.position, CameraRoot.transform.forward * MaxProbeDist);

            //raycast all, go through the hits ignoring hits to self
            RaycastHit[] hits = Physics.RaycastAll(CameraRoot.transform.position, CameraRoot.transform.forward, MaxProbeDist * 2, layerMask, QueryTriggerInteraction.Collide);
            if (hits != null && hits.Length > 0)
            {
                //GameObject nearestObject = null;
                InteractableComponent nearestInteractable = null;
                float nearestDist = float.MaxValue;
                foreach (RaycastHit hit in hits)
                {
                    //skip if it's further than nearestDist (occluded) or flatdist is further than MaxProbeDist (too far away)
                    if (hit.distance > nearestDist)
                    {
                        continue;
                    }

                    float fDist = VectorUtils.GetFlatVectorToTarget(transform.position, hit.point).magnitude;
                    if (fDist > MaxProbeDist)
                    {
                        continue;
                    }

                    //nearestObject = hit.collider.gameObject;

                    //if there's a PlayerController attached, we've hit ourselves
                    if (hit.collider.GetComponent <PlayerController>() != null)
                    {
                        continue;
                    }

                    //TODO pull a similar trick to see if we're pointing at an Actor?

                    //get the interactable component and hitbox component; if it doesn't have either then it's an obstacle
                    InteractableComponent ic  = hit.collider.GetComponent <InteractableComponent>();
                    IHitboxComponent      ahc = hit.collider.GetComponent <IHitboxComponent>();
                    if (ic == null && ahc == null)
                    {
                        //we null out our hit first since it's occluded by this one
                        nearestInteractable = null;
                        nearestDist         = hit.distance;
                        continue;
                    }

                    //it's just us lol
                    if (ahc != null && ahc.ParentController is PlayerController)
                    {
                        continue;
                    }

                    //we have an interactablecomponent and we're not occluded
                    if (ic != null)
                    {
                        nearestInteractable = ic;
                        nearestDist         = hit.distance;
                        continue;
                    }

                    //if it doesn't meet any of those criteria then it's an occluder
                    nearestInteractable = null;
                    nearestDist         = hit.distance;
                }

                //if(nearestObject != null)
                //    Debug.Log("Nearest: " + nearestObject.name);

                if (nearestInteractable != null && nearestInteractable.enabled)
                {
                    //Debug.Log("Detected: " + nearestInteractable.Tooltip);

                    //HUDScript.SetTargetMessage(nearestInteractable.Tooltip);
                    nearestInteractable.OnLook(this.gameObject);
                    if (!string.IsNullOrEmpty(nearestInteractable.Tooltip))
                    {
                        MessageInterface.PushToBus(new QdmsKeyValueMessage("PlayerHasTarget", "Target", nearestInteractable.Tooltip));
                        HadTargetLastFrame = true;
                        haveTarget         = true;
                    }

                    //actual use
                    if (MappedInput.GetButtonDown(DefaultControls.Use) && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoInteract))
                    {
                        nearestInteractable.OnActivate(this.gameObject);
                    }
                }
            }

            if (!haveTarget && HadTargetLastFrame)
            {
                MessageInterface.PushToBus(new QdmsFlagMessage("PlayerClearTarget")); //should probably not do this constantly
            }

            HadTargetLastFrame = haveTarget;
        }
        private void HandlePlayerRespawn()
        {
            if (GameEnding) //can't respawn if game is over
            {
                return;
            }

            //countdown dying players
            int deadPlayers = 0;

            foreach (var dpKvp in DyingPlayers)
            {
                if (dpKvp.Value.TimeLeft > 0)
                {
                    dpKvp.Value.TimeLeft -= Time.deltaTime;
                }
                else
                {
                    deadPlayers++;
                }
            }

            //handle ALL players dead
            if (deadPlayers == Players.Length)
            {
                GameEnding       = true;
                EndGameCoroutine = StartCoroutine(CoEndGame());
            }

            //scan for dead players
            foreach (var player in Players)
            {
                if (player.PlayerIsDead && !DyingPlayers.ContainsKey(player))
                {
                    var countdownGO         = Instantiate(CoreUtils.LoadResource <GameObject>("UI/RespawnCountdown"), CoreUtils.GetUIRoot());
                    var countdownController = countdownGO.GetComponent <CountdownController>();
                    countdownController.SetupCountdown(RespawnTimeout);
                    DyingPlayers.Add(player, new DyingPlayer()
                    {
                        TimeLeft = RespawnTimeout, CountdownController = countdownController
                    });
                }
            }

            //resurrect dead players if requested
            //note that we'll never actually destroy the player objects so we can simply resurrect them
            //note that this is set up for two players instead of n players

            if (MappedInput.GetButtonDown("Start") && MetaState.Instance.Player1Credits >= 1 && Players.Length >= 1 && Players[0] != null && DyingPlayers.ContainsKey(Players[0]) && DyingPlayers[Players[0]].TimeLeft > 0)
            {
                var dp = DyingPlayers[Players[0]];
                DyingPlayers.Remove(Players[0]);
                Destroy(dp.CountdownController.gameObject);
                Players[0].Resurrect();
                Players[0].SetSpawnInvulnerability(SpawnInvulnerability);
                Players[0].Bombs = SpawnBombs;
                MetaState.Instance.Player1Credits--;
            }

            /*
             * if (MappedInput.GetButtonDown("StartP2") && MetaState.Instance.Player2Credits >= 1 && Players.Length >= 2 && Players[1] != null && DyingPlayers.ContainsKey(Players[1]) && DyingPlayers[Players[1]].TimeLeft > 0)
             * {
             *  var dp = DyingPlayers[Players[1]];
             *  DyingPlayers.Remove(Players[1]);
             *  Destroy(dp.CountdownController.gameObject);
             *  Players[1].Resurrect();
             *  Players[1].SetSpawnInvulnerability(SpawnInvulnerability);
             *  Players[1].Bombs = SpawnBombs;
             *  MetaState.Instance.Player2Credits--;
             * }
             */
        }