Fixed revisit platform score spamming logic

dev-hazimBeforeMerge
Hazim Bin Ijaz 3 weeks ago
parent 8f0a623ed5
commit 0f36b90290

@ -144,6 +144,8 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
public ulong? PendingSwapRequest { get; set; } public ulong? PendingSwapRequest { get; set; }
public int? TargetPlatformId { get; private set; } = null; public int? TargetPlatformId { get; private set; } = null;
public int? CurrentPlatformId { get; private set; } = null;
public int? PreviousPlatformId { get; private set; } = null;
public bool IsOnAPlatform { get; private set; } = false; public bool IsOnAPlatform { get; private set; } = false;
public bool IsCrow { get; private set; } = false; public bool IsCrow { get; private set; } = false;
public bool IsSwapping { get; private set; } = false; public bool IsSwapping { get; private set; } = false;
@ -180,18 +182,6 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
{ {
Debug.LogError("SwapConfirmationPanel not found in the scene!"); Debug.LogError("SwapConfirmationPanel not found in the scene!");
} }
//// Show the confirmation panel for the specific player
//var panel = FindObjectOfType<SwapConfirmationPanel>();
//if (panel != null)
//{
// panel.ShowPanel(this); // Pass the current ServerCharacter reference
//}
//else
//{
// Debug.LogError("SwapConfirmationPanel not found in the scene!");
//}
} }
} }
@ -246,23 +236,24 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
TargetPlatformId = platformId != -1 ? platformId : (int?)null; // Update the value for all clients TargetPlatformId = platformId != -1 ? platformId : (int?)null; // Update the value for all clients
} }
public void OnArrivalOnPlatform() public void OnArrivalOnPlatform(int platformId)
{ {
ClearTargetPlatform(); ClearTargetPlatform();
SetOnPlatform(true); // Automatically syncs to all clients SetOnPlatform(true, platformId); // Automatically syncs to all clients
} }
public void OnLeavingPlatform() public void OnLeavingPlatform(int platformId)
{ {
SetOnPlatform(false); // Automatically syncs to all clients
SetOnPlatform(false, platformId); // Automatically syncs to all clients
} }
public void SetOnPlatform(bool status) public void SetOnPlatform(bool status, int platformId)
{ {
if (IsServer) if (IsServer)
{ {
IsOnAPlatform = status; // Update on the server IsOnAPlatform = status; // Update on the server
UpdatePlatformStatusClientRpc(status); // Notify all clients UpdatePlatformStatusClientRpc(status, platformId); // Notify all clients
} }
else else
{ {
@ -271,10 +262,19 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
} }
[ClientRpc] [ClientRpc]
private void UpdatePlatformStatusClientRpc(bool status) private void UpdatePlatformStatusClientRpc(bool status, int platformId)
{ {
IsOnAPlatform = status; // Update the value for all clients IsOnAPlatform = status; // Update the value for all clients
IsSwapping = false; IsSwapping = false;
if (status)
{
CurrentPlatformId = platformId;
}
else
{
PreviousPlatformId = platformId;
CurrentPlatformId = null;
}
} }

@ -44,13 +44,29 @@ namespace Unity.Multiplayer.Samples.BossRoom
return; return;
} }
bool giveScore = player.PreviousPlatformId != PlatformID;
// Check if the player who occupied this platform had this platform as their target platform
if (giveScore)
{
if (player.TargetPlatformId.HasValue && player.TargetPlatformId.Value == PlatformID)
{
// Successful swap
ScoreManager.Instance.AddPlayerScore(player.OwnerClientId, 10);
Debug.Log($"Player {player.OwnerClientId} successfully swapped to Platform {PlatformID}. Awarded 10 score.");
}
else
{
ScoreManager.Instance.AddPlayerScore(player.OwnerClientId, 20);
Debug.Log($"Crow Player {player.OwnerClientId} successfully stole Platform {PlatformID}. Awarded 20 score.");
}
}
IsOccupied = true; IsOccupied = true;
OccupierId.Value = player.OwnerClientId; OccupierId.Value = player.OwnerClientId;
player.SetOnPlatform(true); player.OnArrivalOnPlatform(PlatformID);
Debug.Log($"Platform {PlatformID} is now occupied by Player {player.OwnerClientId}."); Debug.Log($"Platform {PlatformID} is now occupied by Player {player.OwnerClientId}.");
} }
public void Vacate(ServerCharacter player) public void Vacate(ServerCharacter player)
{ {
if (!IsServer) if (!IsServer)
@ -67,7 +83,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
IsOccupied = false; IsOccupied = false;
OccupierId.Value = 0; OccupierId.Value = 0;
player.SetOnPlatform(false); player.OnLeavingPlatform(PlatformID);
Debug.Log($"Platform {PlatformID} is now vacated."); Debug.Log($"Platform {PlatformID} is now vacated.");
} }
@ -81,7 +97,6 @@ namespace Unity.Multiplayer.Samples.BossRoom
if (!IsOccupied) if (!IsOccupied)
{ {
Occupy(player); Occupy(player);
player.OnArrivalOnPlatform();
} }
else else
{ {
@ -102,7 +117,6 @@ namespace Unity.Multiplayer.Samples.BossRoom
if (other.TryGetComponent<ServerCharacter>(out var player) && OccupierId.Value == player.OwnerClientId) if (other.TryGetComponent<ServerCharacter>(out var player) && OccupierId.Value == player.OwnerClientId)
{ {
Vacate(player); Vacate(player);
player.OnLeavingPlatform();
} }
} }
} }

@ -57,6 +57,36 @@ public class ScoreManager : NetworkBehaviour
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score."); Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
} }
} }
public void AddPlayerScore(ulong ownerClientId, int newScore)
{
if (playerScores.ContainsKey(ownerClientId))
{
playerScores[ownerClientId] += newScore;
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {playerScores[ownerClientId]}.");
UpdatePlayerScoreClientRpc(ownerClientId, playerScores[ownerClientId]);
}
else
{
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
}
}
public void SubtractPlayerScore(ulong ownerClientId, int scoreToSubtract)
{
if (playerScores.ContainsKey(ownerClientId))
{
int value = Mathf.Max(0, playerScores[ownerClientId] - scoreToSubtract);
playerScores[ownerClientId] = value;
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {playerScores[ownerClientId]}.");
UpdatePlayerScoreClientRpc(ownerClientId, playerScores[ownerClientId]);
}
else
{
Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score.");
}
}
public int GetPlayerScore(ulong ownerClientId) public int GetPlayerScore(ulong ownerClientId)
{ {

Loading…
Cancel
Save