|
|
|
@ -25,27 +25,41 @@ public class ScoreManager : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
|
if (IsServer)
|
|
|
|
|
{
|
|
|
|
|
StartCrowPenaltyCoroutineServerRpc();
|
|
|
|
|
StartCrowPenaltyCoroutine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ServerRpc(RequireOwnership = false)]
|
|
|
|
|
public void InitializePlayerScoreServerRpc(ulong ownerClientId, string name)
|
|
|
|
|
public void InitializeAndSyncPlayerServerRpc(ulong ownerClientId, string playerName)
|
|
|
|
|
{
|
|
|
|
|
if (!playerScores.ContainsKey(ownerClientId))
|
|
|
|
|
{
|
|
|
|
|
playerScores[ownerClientId] = 200;
|
|
|
|
|
playerNames[ownerClientId] = name;
|
|
|
|
|
Debug.Log($"[ScoreManager] Player {ownerClientId} initialized with a starting score of 200 and name '{name}'.");
|
|
|
|
|
Scoreboard.instance.ScoreBoardItemInitializer(ownerClientId, playerScores[ownerClientId], name);
|
|
|
|
|
UpdatePlayerScoreClientRpc(ownerClientId, 200);
|
|
|
|
|
playerNames[ownerClientId] = playerName;
|
|
|
|
|
}
|
|
|
|
|
Debug.Log($"[ScoreManager] Player {ownerClientId} initialized with a starting score of {playerScores[ownerClientId]} and name '{playerName}'.");
|
|
|
|
|
SyncPlayerDataClientRpc(ownerClientId, playerName, playerScores[ownerClientId]);
|
|
|
|
|
}
|
|
|
|
|
[ClientRpc]
|
|
|
|
|
public void SyncPlayerDataClientRpc(ulong ownerClientId, string playerName, int score)
|
|
|
|
|
{
|
|
|
|
|
// Update local data
|
|
|
|
|
if (!playerScores.ContainsKey(ownerClientId))
|
|
|
|
|
{
|
|
|
|
|
playerScores[ownerClientId] = score;
|
|
|
|
|
playerNames[ownerClientId] = playerName;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"[ScoreManager] Player {ownerClientId} already initialized.");
|
|
|
|
|
playerScores[ownerClientId] = score;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[ScoreManager] Synced Player {ownerClientId} data: Name = {playerName}, Score = {score}");
|
|
|
|
|
|
|
|
|
|
// Update the scoreboard
|
|
|
|
|
Scoreboard.instance.InitializeScoreboardItem(ownerClientId, score, playerName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdatePlayerScore(ulong ownerClientId, int newScore)
|
|
|
|
|
{
|
|
|
|
|
if (playerScores.ContainsKey(ownerClientId))
|
|
|
|
@ -67,10 +81,11 @@ public class ScoreManager : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
|
string playerName = playerNames[ownerClientId];
|
|
|
|
|
Debug.Log($"[ScoreManager] Received score update for Player {ownerClientId} (Name: {playerName}): {newScore}");
|
|
|
|
|
Scoreboard.instance.ScoreBoardUpdater(playerName, newScore);
|
|
|
|
|
Scoreboard.instance.UpdateScoreboard(playerName, newScore);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Debug.LogWarning($"[ScoreManager] Player name not found for Player {ownerClientId}. Cannot update scoreboard.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -93,8 +108,7 @@ public class ScoreManager : NetworkBehaviour
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ServerRpc]
|
|
|
|
|
public void StartCrowPenaltyCoroutineServerRpc()
|
|
|
|
|
public void StartCrowPenaltyCoroutine()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(ApplyCrowPenaltyCoroutine());
|
|
|
|
|
}
|
|
|
|
|