Revert "Update ClientInputSender.cs"

This reverts commit 734cafed1c.
main
Hazim Bin Ijaz 4 weeks ago
parent 734cafed1c
commit c1f157103e

@ -18,7 +18,7 @@ namespace Unity.BossRoom.Gameplay.UserInput
[RequireComponent(typeof(ServerCharacter))] [RequireComponent(typeof(ServerCharacter))]
public class ClientInputSender : NetworkBehaviour public class ClientInputSender : NetworkBehaviour
{ {
const float k_MouseInputRaycastDistance = 1000f; const float k_MouseInputRaycastDistance = 100f;
//The movement input rate is capped at 40ms (or 25 fps). This provides a nice balance between responsiveness and //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. //upstream network conservation. This matters when holding down your mouse button to move.
@ -121,7 +121,6 @@ namespace Unity.BossRoom.Gameplay.UserInput
public AbilitySystem m_AbilitySystem; public AbilitySystem m_AbilitySystem;
ServerCharacter m_TargetServerCharacter; ServerCharacter m_TargetServerCharacter;
private bool IsSwapModeActive = false;
void Awake() void Awake()
{ {
@ -478,101 +477,103 @@ namespace Unity.BossRoom.Gameplay.UserInput
void Update() void Update()
{ {
// Toggle Swap Mode with E key
if (Input.GetKeyDown(KeyCode.E))
{
if (!m_AbilitySystem.IsAbilityModeActive() && m_ServerCharacter.IsOnAPlatform) // Prevent swap mode if ability mode is active
{
ToggleSwapMode();
}
else
{
Debug.Log("Cannot activate swap mode while ability mode is active.");
}
}
// Toggle Ability Mode with Q key
if (Input.GetKeyDown(KeyCode.Q)) if (Input.GetKeyDown(KeyCode.Q))
{ {
if (!IsSwapModeActive) // Prevent ability mode if swap mode is active if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability
{ {
if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey);
{
m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey);
}
else
{
Debug.Log("You must be the Crow to activate this ability.");
}
} }
else else
{ {
Debug.Log("Cannot activate ability mode while swap mode is active."); Debug.Log("You must be the Crow to activate this ability.");
} }
} }
if (m_AbilitySystem.IsAbilityModeActive()) return; if (m_AbilitySystem.IsAbilityModeActive()) return;
if (!IsSwapModeActive) // Prevent other inputs if swap mode is active if (Input.GetKeyDown(KeyCode.Alpha1) && CharacterClass.Skill1)
{ {
if (Input.GetMouseButtonDown(0)) RequestAction(actionState1.actionID, SkillTriggerStyle.Keyboard);
{
m_MoveRequest = true;
}
} }
if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) else if (Input.GetKeyUp(KeyCode.Alpha1) && CharacterClass.Skill1)
{ {
if (Input.GetMouseButtonDown(1)) RequestAction(actionState1.actionID, SkillTriggerStyle.KeyboardRelease);
{ }
RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick); if (Input.GetKeyDown(KeyCode.Alpha2) && CharacterClass.Skill2)
} {
if (IsSwapModeActive && Input.GetMouseButtonDown(0)) // Left-click to request swap RequestAction(actionState2.actionID, SkillTriggerStyle.Keyboard);
{ }
HandleSwapRequest(); else if (Input.GetKeyUp(KeyCode.Alpha2) && CharacterClass.Skill2)
} {
RequestAction(actionState2.actionID, SkillTriggerStyle.KeyboardRelease);
}
if (Input.GetKeyDown(KeyCode.Alpha3) && CharacterClass.Skill3)
{
RequestAction(actionState3.actionID, SkillTriggerStyle.Keyboard);
}
else if (Input.GetKeyUp(KeyCode.Alpha3) && CharacterClass.Skill3)
{
RequestAction(actionState3.actionID, SkillTriggerStyle.KeyboardRelease);
} }
}
/// <summary> if (Input.GetKeyDown(KeyCode.Alpha5))
/// Toggles swap mode on or off.
/// </summary>
private void ToggleSwapMode()
{
IsSwapModeActive = !IsSwapModeActive;
if (IsSwapModeActive)
{ {
Debug.Log("Swap mode activated. Click on a player to request a swap."); RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
else if (Input.GetKeyDown(KeyCode.Alpha6))
{ {
Debug.Log("Swap mode deactivated."); RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
}
if (Input.GetKeyDown(KeyCode.Alpha7))
{
RequestAction(GameDataSource.Instance.Emote3ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
}
if (Input.GetKeyDown(KeyCode.Alpha8))
{
RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
}
/// <summary> if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
/// Handles the swap request when in swap mode.
/// </summary>
private void HandleSwapRequest()
{
var ray = m_MainCamera.ScreenPointToRay(Input.mousePosition);
int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
if (hits > 0)
{ {
for (int i = 0; i < hits; i++) //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))
{ {
if (k_CachedHit[i].transform.TryGetComponent(out NetworkObject targetNetObj) && RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick);
targetNetObj != m_ServerCharacter.NetworkObject) }
if (Input.GetMouseButtonDown(0)) // Left-click to request swap
{
var ray = m_MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition);
int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
if (hits > 0)
{ {
// Check if the target is a valid ServerCharacter for (int i = 0; i < hits; i++)
if (targetNetObj.TryGetComponent(out ServerCharacter targetCharacter))
{ {
// Initiate the swap if (k_CachedHit[i].transform.TryGetComponent(out NetworkObject targetNetObj) &&
targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId); targetNetObj != m_ServerCharacter.NetworkObject)
Debug.Log($"Swap request sent to {targetCharacter.name}."); {
IsSwapModeActive = false; // Automatically deactivate swap mode after a successful request // Check if the target is a valid ServerCharacter
return; if (targetNetObj.TryGetComponent(out ServerCharacter targetCharacter))
{
// Initiate the swap
targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId);
Debug.Log($"Swap request sent to {targetCharacter.name}.");
isCharacterClicked = true;
break; // Exit the loop after initiating the swap
}
}
} }
} }
} }
if(!isCharacterClicked && Input.GetMouseButtonDown(0))
{
m_MoveRequest = true; // Set move request for holding left-click
}
} }
Debug.LogWarning("No valid target found for swapping.");
} }

Loading…
Cancel
Save