diff --git a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs
index ee8ad22..a0861e6 100644
--- a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs
+++ b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs
@@ -162,7 +162,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
//Hazim
[Rpc(SendTo.Everyone)]
- private void ShowSwapConfirmationPanelClientRpc(string name)
+ private void ShowSwapConfirmationPanelClientRpc(string inviterName)
{
if (NetworkManager.Singleton.LocalClientId == OwnerClientId)
{
@@ -171,7 +171,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
if (panel != null)
{
- uistate.swapConfirmationPanel.swapwithname.text = "Swap with " + name;
+ uistate.swapConfirmationPanel.swapwithname.text = "Swap with " + inviterName;
panel.ShowPanel(this); // Pass the current ServerCharacter reference
}
else
diff --git a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs
index 8a4d288..c8d6b0f 100644
--- a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs
+++ b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs
@@ -18,7 +18,7 @@ namespace Unity.BossRoom.Gameplay.UserInput
[RequireComponent(typeof(ServerCharacter))]
public class ClientInputSender : NetworkBehaviour
{
- const float k_MouseInputRaycastDistance = 100f;
+ const float k_MouseInputRaycastDistance = 1000f;
//The movement input rate is capped at 40ms (or 25 fps). This provides a nice balance between responsiveness and
//upstream network conservation. This matters when holding down your mouse button to move.
@@ -121,7 +121,8 @@ namespace Unity.BossRoom.Gameplay.UserInput
public AbilitySystem m_AbilitySystem;
ServerCharacter m_TargetServerCharacter;
-
+ private bool IsSwapModeActive = false;
+
void Awake()
{
m_MainCamera = Camera.main;
@@ -477,105 +478,103 @@ namespace Unity.BossRoom.Gameplay.UserInput
void Update()
{
-
- if (Input.GetKeyDown(KeyCode.Q))
+ // Toggle Swap Mode with E key
+ if (Input.GetKeyDown(KeyCode.E))
{
- if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability
+ if (!m_AbilitySystem.IsAbilityModeActive() && m_ServerCharacter.IsOnAPlatform) // Prevent swap mode if ability mode is active
{
- m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey);
+ ToggleSwapMode();
}
else
{
- Debug.Log("You must be the Crow to activate this ability.");
+ Debug.Log("Cannot activate swap mode while ability mode is active.");
}
}
-
- if (m_AbilitySystem.IsAbilityModeActive()) return;
- if (Input.GetKeyDown(KeyCode.Alpha1) && CharacterClass.Skill1)
- {
- RequestAction(actionState1.actionID, SkillTriggerStyle.Keyboard);
- }
- else if (Input.GetKeyUp(KeyCode.Alpha1) && CharacterClass.Skill1)
- {
- RequestAction(actionState1.actionID, SkillTriggerStyle.KeyboardRelease);
- }
- if (Input.GetKeyDown(KeyCode.Alpha2) && CharacterClass.Skill2)
- {
- RequestAction(actionState2.actionID, SkillTriggerStyle.Keyboard);
- }
- else if (Input.GetKeyUp(KeyCode.Alpha2) && CharacterClass.Skill2)
+ // Toggle Ability Mode with Q key
+ if (Input.GetKeyDown(KeyCode.Q))
{
- RequestAction(actionState2.actionID, SkillTriggerStyle.KeyboardRelease);
+ if (!IsSwapModeActive) // Prevent ability mode if swap mode is active
+ {
+ if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability
+ {
+ m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey);
+ }
+ else
+ {
+ 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.Alpha3) && CharacterClass.Skill3)
+ if (m_AbilitySystem.IsAbilityModeActive()) return;
+ if (!IsSwapModeActive) // Prevent other inputs if swap mode is active
{
- RequestAction(actionState3.actionID, SkillTriggerStyle.Keyboard);
+ if (Input.GetMouseButtonDown(0))
+ {
+ m_MoveRequest = true;
+ }
}
- else if (Input.GetKeyUp(KeyCode.Alpha3) && CharacterClass.Skill3)
+ if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
{
- RequestAction(actionState3.actionID, SkillTriggerStyle.KeyboardRelease);
+ if (Input.GetMouseButtonDown(1))
+ {
+ RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick);
+ }
+ if (IsSwapModeActive && Input.GetMouseButtonDown(0)) // Left-click to request swap
+ {
+ HandleSwapRequest();
+ }
}
+ }
- if (Input.GetKeyDown(KeyCode.Alpha5))
- {
- RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
- }
- if (Input.GetKeyDown(KeyCode.Alpha6))
- {
- RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
- }
- if (Input.GetKeyDown(KeyCode.Alpha7))
+ ///
+ /// Toggles swap mode on or off.
+ ///
+ private void ToggleSwapMode()
+ {
+ IsSwapModeActive = !IsSwapModeActive;
+ if (IsSwapModeActive)
{
- RequestAction(GameDataSource.Instance.Emote3ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
+ Debug.Log("Swap mode activated. Click on a player to request a swap.");
}
- if (Input.GetKeyDown(KeyCode.Alpha8))
+ else
{
- RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
+ Debug.Log("Swap mode deactivated.");
}
-
- if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
+ }
+
+ ///
+ /// Handles the swap request when in swap mode.
+ ///
+ private void HandleSwapRequest()
+ {
+ var ray = m_MainCamera.ScreenPointToRay(Input.mousePosition);
+ int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
+ if (hits > 0)
{
- //IsPointerOverGameObject() is a simple way to determine if the mouse is over a UI element. If it is, we don't perform mouse input logic,
- //to model the button "blocking" mouse clicks from falling through and interacting with the world.
- bool isCharacterClicked = false;
- if (Input.GetMouseButtonDown(1))
- {
- RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick);
- }
-
- if (Input.GetMouseButtonDown(0)) // Left-click to request swap
+ for (int i = 0; i < hits; i++)
{
- var ray = m_MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition);
- int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
- if (hits > 0)
+ if (k_CachedHit[i].transform.TryGetComponent(out NetworkObject targetNetObj) &&
+ targetNetObj != m_ServerCharacter.NetworkObject)
{
- for (int i = 0; i < hits; i++)
+ // Check if the target is a valid ServerCharacter
+ if (targetNetObj.TryGetComponent(out ServerCharacter targetCharacter))
{
- if (k_CachedHit[i].transform.TryGetComponent(out NetworkObject targetNetObj) &&
- targetNetObj != m_ServerCharacter.NetworkObject)
- {
- // Check if the target is a valid ServerCharacter
- if (targetNetObj.TryGetComponent(out ServerCharacter targetCharacter))
- {
- // Initiate the swap
- targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId,m_ServerCharacter.uIStateDisplayHandler.m_UIState.playerName);
- Debug.Log($"Swap request sent to {targetCharacter.name}.");
- isCharacterClicked = true;
- break; // Exit the loop after initiating the swap
- }
- }
+ // Initiate the swap
+ targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId,m_ServerCharacter.uIStateDisplayHandler.m_UIState.playerName);
+ Debug.Log($"Swap request sent to {targetCharacter.name}.");
+ IsSwapModeActive = false; // Automatically deactivate swap mode after a successful request
+ return;
}
}
}
-
-
- if(!isCharacterClicked && Input.GetMouseButtonDown(0))
- {
- m_MoveRequest = true; // Set move request for holding left-click
- }
}
+ Debug.LogWarning("No valid target found for swapping.");
}
-
+
void UpdateAction1()
{