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,103 +478,101 @@ namespace Unity.BossRoom.Gameplay.UserInput
void Update() void Update()
{ {
// Toggle Swap Mode with E key
if (Input.GetKeyDown(KeyCode.Q)) 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 else
{ {
Debug.Log("You must be the Crow to activate this ability."); Debug.Log("Cannot activate swap mode while ability mode is active.");
} }
} }
// Toggle Ability Mode with Q key
if (m_AbilitySystem.IsAbilityModeActive()) return; if (Input.GetKeyDown(KeyCode.Q))
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)
{ {
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)) /// <summary>
{ /// Toggles swap mode on or off.
RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); /// </summary>
} private void ToggleSwapMode()
if (Input.GetKeyDown(KeyCode.Alpha6)) {
{ IsSwapModeActive = !IsSwapModeActive;
RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); if (IsSwapModeActive)
}
if (Input.GetKeyDown(KeyCode.Alpha7))
{ {
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) /// <summary>
/// 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)
{ {
//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, for (int i = 0; i < hits; i++)
//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 (k_CachedHit[i].transform.TryGetComponent(out NetworkObject targetNetObj) &&
} 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)
{ {
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) && // Initiate the swap
targetNetObj != m_ServerCharacter.NetworkObject) targetCharacter.NotifySwapRequestRpc(m_ServerCharacter.NetworkObjectId,m_ServerCharacter.uIStateDisplayHandler.m_UIState.playerName);
{ Debug.Log($"Swap request sent to {targetCharacter.name}.");
// Check if the target is a valid ServerCharacter IsSwapModeActive = false; // Automatically deactivate swap mode after a successful request
if (targetNetObj.TryGetComponent(out ServerCharacter targetCharacter)) return;
{
// 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
}
}
} }
} }
} }
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