From 001cfa86513d26e66a73c1f1b3a5f459e340858b Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Thu, 9 Jan 2025 18:37:16 +0500 Subject: [PATCH] Shifted movement keybinds and prioritized movement over other actions --- Assets/Scripts/Gameplay/AbilitySystem.cs | 2 +- .../Gameplay/UserInput/ClientInputSender.cs | 116 +++++++++++------- 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs b/Assets/Scripts/Gameplay/AbilitySystem.cs index 805dfb7..9929c84 100644 --- a/Assets/Scripts/Gameplay/AbilitySystem.cs +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs @@ -175,7 +175,7 @@ public class AbilitySystem : NetworkBehaviour Debug.Log($"Ability {ability.abilityName} activated! Click to use."); } - private void DeactivateAbilityMode() + public void DeactivateAbilityMode() { isAbilityActive = false; activeAbility = null; diff --git a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs index 12d5ebc..6e4e843 100644 --- a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs +++ b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs @@ -480,10 +480,17 @@ namespace Unity.BossRoom.Gameplay.UserInput } void Update() + { + HandleSwapInput(); + HandleAbilityInput(); + HandleMovementInput(); + } + + private void HandleSwapInput() { if (Input.GetKeyDown(KeyCode.Q)) { - if (!m_AbilitySystem.IsAbilityModeActive() && m_ServerCharacter.IsOnAPlatform && !m_ServerCharacter.IsCrow) // Prevent swap mode if ability mode is active + if (CanActivateSwapMode()) { ToggleSwapMode(); } @@ -492,59 +499,60 @@ namespace Unity.BossRoom.Gameplay.UserInput m_UIMessageFeed.DisplayMessage("Not on a platform or not a player"); Debug.Log("Cannot activate swap mode while ability mode is active."); } - } //Swap - if (Input.GetKeyDown(KeyCode.E)) //Dash'N'Crash + } + } + + private bool CanActivateSwapMode() + { + return !m_AbilitySystem.IsAbilityModeActive() && m_ServerCharacter.IsOnAPlatform && !m_ServerCharacter.IsCrow; + } + + private void HandleAbilityInput() + { + if (Input.GetKeyDown(KeyCode.E)) // Dash'N'Crash { - if (!IsSwapModeActive) // Prevent ability mode if swap mode is active - { - if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability - { - m_UIMessageFeed.DisplayMessage("Activated Ability mode"); - m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.DashNCrashAbilityKey); - } - else - { - m_UIMessageFeed.DisplayMessage("Abilities are only for crow"); - Debug.Log("You must be the Crow to activate this ability."); - } - } - else - { - Debug.Log("Cannot activate ability mode while swap mode is active."); - } - } - if (Input.GetKeyDown(KeyCode.R)) //Freeze Throw + ActivateAbilityIfAllowed(GameDataSource.Instance.DashNCrashAbilityKey, "Abilities are only for crow"); + } + if (Input.GetKeyDown(KeyCode.R)) // Freeze Throw { - if (!IsSwapModeActive) // Prevent ability mode if swap mode is active - { - m_UIMessageFeed.DisplayMessage("Activated Ability mode"); - m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.FreezeThrowAbilityKey); - } - else - { - Debug.Log("Cannot activate ability mode while swap mode is active."); - } + ActivateAbilityIfAllowed(GameDataSource.Instance.FreezeThrowAbilityKey); } - if (Input.GetKeyDown(KeyCode.F)) //Vector Wall + if (Input.GetKeyDown(KeyCode.F)) // Vector Wall { - if (!IsSwapModeActive) // Prevent ability mode if swap mode is active - { - m_UIMessageFeed.DisplayMessage("Activated Ability mode"); - m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.VectorWallAbilityKey); - } - else - { - Debug.Log("Cannot activate ability mode while swap mode is active."); - } + ActivateAbilityIfAllowed(GameDataSource.Instance.VectorWallAbilityKey); + } + } + + private void ActivateAbilityIfAllowed(string abilityKey, string errorMessage = null) + { + if (IsSwapModeActive) + { + Debug.Log("Cannot activate ability mode while swap mode is active."); + return; } - if (m_AbilitySystem.IsAbilityModeActive()) return; - if (!IsSwapModeActive) // Prevent other inputs if swap mode is active + + if (abilityKey == GameDataSource.Instance.DashNCrashAbilityKey && !m_ServerCharacter.IsCrow) { - if (Input.GetMouseButtonDown(1)) + if (errorMessage != null) { - m_MoveRequest = true; + m_UIMessageFeed.DisplayMessage(errorMessage); } + Debug.Log("You must be the Crow to activate this ability."); + return; + } + + m_UIMessageFeed.DisplayMessage("Activated Ability mode"); + m_AbilitySystem.ActivateAbilityByKey(abilityKey); + } + + private void HandleMovementInput() + { + if (Input.GetMouseButtonDown(1)) // Right-click for movement + { + CancelActiveModes(); + m_MoveRequest = true; // Accept movement request } + if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) { if (IsSwapModeActive && Input.GetMouseButtonDown(0)) // Left-click to request swap @@ -554,6 +562,24 @@ namespace Unity.BossRoom.Gameplay.UserInput } } + private void CancelActiveModes() + { + if (m_AbilitySystem.IsAbilityModeActive()) + { + m_UIMessageFeed.DisplayMessage("Ability mode canceled."); + m_AbilitySystem.DeactivateAbilityMode(); + Debug.Log("Ability mode deactivated due to move request."); + } + + if (IsSwapModeActive) + { + m_UIMessageFeed.DisplayMessage("Swap mode canceled."); + ToggleSwapMode(); + Debug.Log("Swap mode deactivated due to move request."); + } + } + + /// /// Toggles swap mode on or off. ///