Added some stuff

main
Hazim Bin Ijaz 4 weeks ago
parent 8056f00505
commit 18cbadde24

@ -162,7 +162,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
//Hazim //Hazim
[Rpc(SendTo.Everyone)] [Rpc(SendTo.Everyone)]
private void ShowSwapConfirmationPanelClientRpc(string name) private void ShowSwapConfirmationPanelClientRpc(string inviterName)
{ {
if (NetworkManager.Singleton.LocalClientId == OwnerClientId) if (NetworkManager.Singleton.LocalClientId == OwnerClientId)
{ {
@ -171,7 +171,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
if (panel != null) 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 panel.ShowPanel(this); // Pass the current ServerCharacter reference
} }
else else

@ -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 = 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 //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,6 +121,7 @@ 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()
{ {
@ -477,8 +478,22 @@ 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
{ {
@ -489,63 +504,54 @@ namespace Unity.BossRoom.Gameplay.UserInput
Debug.Log("You must be the Crow to activate this ability."); Debug.Log("You must be the Crow to activate this ability.");
} }
} }
else
if (m_AbilitySystem.IsAbilityModeActive()) return;
if (Input.GetKeyDown(KeyCode.Alpha1) && CharacterClass.Skill1)
{ {
RequestAction(actionState1.actionID, SkillTriggerStyle.Keyboard); Debug.Log("Cannot activate ability mode while swap mode is active.");
} }
else if (Input.GetKeyUp(KeyCode.Alpha1) && CharacterClass.Skill1)
{
RequestAction(actionState1.actionID, SkillTriggerStyle.KeyboardRelease);
} }
if (Input.GetKeyDown(KeyCode.Alpha2) && CharacterClass.Skill2) if (m_AbilitySystem.IsAbilityModeActive()) return;
if (!IsSwapModeActive) // Prevent other inputs if swap mode is active
{ {
RequestAction(actionState2.actionID, SkillTriggerStyle.Keyboard); if (Input.GetMouseButtonDown(0))
}
else if (Input.GetKeyUp(KeyCode.Alpha2) && CharacterClass.Skill2)
{ {
RequestAction(actionState2.actionID, SkillTriggerStyle.KeyboardRelease); m_MoveRequest = true;
} }
if (Input.GetKeyDown(KeyCode.Alpha3) && CharacterClass.Skill3)
{
RequestAction(actionState3.actionID, SkillTriggerStyle.Keyboard);
} }
else if (Input.GetKeyUp(KeyCode.Alpha3) && CharacterClass.Skill3) if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
{ {
RequestAction(actionState3.actionID, SkillTriggerStyle.KeyboardRelease); if (Input.GetMouseButtonDown(1))
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{ {
RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick);
} }
if (Input.GetKeyDown(KeyCode.Alpha6)) if (IsSwapModeActive && Input.GetMouseButtonDown(0)) // Left-click to request swap
{ {
RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); HandleSwapRequest();
} }
if (Input.GetKeyDown(KeyCode.Alpha7))
{
RequestAction(GameDataSource.Instance.Emote3ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (Input.GetKeyDown(KeyCode.Alpha8))
{
RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) /// <summary>
/// Toggles swap mode on or off.
/// </summary>
private void ToggleSwapMode()
{ {
//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, IsSwapModeActive = !IsSwapModeActive;
//to model the button "blocking" mouse clicks from falling through and interacting with the world. if (IsSwapModeActive)
bool isCharacterClicked = false;
if (Input.GetMouseButtonDown(1))
{ {
RequestAction(CharacterClass.Skill1.ActionID, SkillTriggerStyle.MouseClick); Debug.Log("Swap mode activated. Click on a player to request a swap.");
}
else
{
Debug.Log("Swap mode deactivated.");
}
} }
if (Input.GetMouseButtonDown(0)) // Left-click to request swap /// <summary>
/// Handles the swap request when in swap mode.
/// </summary>
private void HandleSwapRequest()
{ {
var ray = m_MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition); var ray = m_MainCamera.ScreenPointToRay(Input.mousePosition);
int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance); int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance);
if (hits > 0) if (hits > 0)
{ {
@ -560,20 +566,13 @@ namespace Unity.BossRoom.Gameplay.UserInput
// Initiate the swap // Initiate the swap
targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId,m_ServerCharacter.uIStateDisplayHandler.m_UIState.playerName); targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId,m_ServerCharacter.uIStateDisplayHandler.m_UIState.playerName);
Debug.Log($"Swap request sent to {targetCharacter.name}."); Debug.Log($"Swap request sent to {targetCharacter.name}.");
isCharacterClicked = true; IsSwapModeActive = false; // Automatically deactivate swap mode after a successful request
break; // Exit the loop after initiating the swap return;
}
}
}
} }
} }
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