diff --git a/Assets/Prefabs/Character/PlayerAvatar.prefab b/Assets/Prefabs/Character/PlayerAvatar.prefab index 73093d1..0de7131 100644 --- a/Assets/Prefabs/Character/PlayerAvatar.prefab +++ b/Assets/Prefabs/Character/PlayerAvatar.prefab @@ -300,6 +300,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} insertIndex: -1 addedObject: {fileID: 7049454171559621213} + - targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} + insertIndex: -1 + addedObject: {fileID: 4321537148236331373} m_SourcePrefab: {fileID: 100100000, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} --- !u!114 &741733315856861890 stripped MonoBehaviour: @@ -369,6 +372,7 @@ MonoBehaviour: m_ServerCharacter: {fileID: 741733315856861890} m_PhysicsWrapper: {fileID: 6116655102486013040} m_AbilitySystem: {fileID: 7049454171559621213} + m_UIMessageFeed: {fileID: 0} --- !u!114 &4887850889182527394 MonoBehaviour: m_ObjectHideFlags: 0 @@ -747,6 +751,18 @@ MonoBehaviour: abilities: - {fileID: 11400000, guid: e4794e2f71f66a74486c797344695ce7, type: 2} currentAbilityIndicator: {fileID: 92142163933926358} +--- !u!114 &4321537148236331373 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6009713983291384756} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a73f85cd904406945a2192aaecb2c310, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!4 &6009713983291384766 stripped Transform: m_CorrespondingSourceObject: {fileID: 4600110157238723791, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} diff --git a/Assets/Scenes/BossRoom.unity b/Assets/Scenes/BossRoom.unity index c94596b..7796d5d 100644 --- a/Assets/Scenes/BossRoom.unity +++ b/Assets/Scenes/BossRoom.unity @@ -1232,6 +1232,72 @@ MonoBehaviour: ChildScenesToLoadConfig: - {fileID: 102900000, guid: a542218ba547130469444ba04f9bef35, type: 3} - {fileID: 102900000, guid: f77e38f2b72c5f649902d637b3a70b42, type: 3} +--- !u!1 &698889474 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 698889477} + - component: {fileID: 698889475} + - component: {fileID: 698889476} + m_Layer: 0 + m_Name: ScoreManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &698889475 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 698889474} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + GlobalObjectIdHash: 2391970879 + InScenePlacedSourceGlobalObjectIdHash: 0 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 0 + AutoObjectParentSync: 1 +--- !u!114 &698889476 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 698889474} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c42f66f946855da4b99f79c5bde1d545, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &698889477 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 698889474} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &791609700 PrefabInstance: m_ObjectHideFlags: 0 @@ -8597,11 +8663,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.w - value: 0.8529446 + value: 0.85294455 objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.x - value: 0.39434478 + value: 0.3943448 objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.y @@ -8609,7 +8675,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.z - value: -0.14352977 + value: -0.14352979 objectReference: {fileID: 0} - target: {fileID: 1676734516302391364, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_UpdateMethod @@ -8641,11 +8707,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.y - value: 0.30972984 + value: 0.3097298 objectReference: {fileID: 0} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.z - value: -0.1450697 + value: -0.14506969 objectReference: {fileID: 0} - target: {fileID: 1676734516724634599, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalPosition.z @@ -8758,15 +8824,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.x - value: 0.3943448 + value: 0.39434484 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.y - value: 0.31044644 + value: 0.3104465 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.z - value: -0.14352976 + value: -0.1435298 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -9235,6 +9301,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: confirmationPanel: {fileID: 125665959027215112} + swapwithname: {fileID: 0} --- !u!4 &1486746210 Transform: m_ObjectHideFlags: 0 @@ -10669,3 +10736,4 @@ SceneRoots: - {fileID: 1690610726} - {fileID: 1486746210} - {fileID: 396364068} + - {fileID: 698889477} diff --git a/Assets/Scripts/Gameplay/CrowManager.cs b/Assets/Scripts/Gameplay/CrowManager.cs index 6ea60dd..47963ba 100644 --- a/Assets/Scripts/Gameplay/CrowManager.cs +++ b/Assets/Scripts/Gameplay/CrowManager.cs @@ -111,6 +111,8 @@ public class CrowManager : NetworkBehaviour } } + + /// /// RPC to notify clients about the Crow change. /// @@ -181,4 +183,5 @@ public class CrowManager : NetworkBehaviour { return currentCrow; } + } diff --git a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs index d511081..137c445 100644 --- a/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs +++ b/Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs @@ -146,6 +146,8 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character public int? TargetPlatformId { get; private set; } = null; public bool IsOnAPlatform { get; private set; } = false; public bool IsCrow { get; private set; } = false; + public bool IsSwapping { get; private set; } = false; + public UIStateDisplayHandler uIStateDisplayHandler; @@ -272,6 +274,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character private void UpdatePlatformStatusClientRpc(bool status) { IsOnAPlatform = status; // Update the value for all clients + IsSwapping = false; } @@ -296,6 +299,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character var pltpos = PlatformManager.Instance.GetPlatformPosition(platform.PlatformID); pltpos.y = 0; Debug.Log($"Platform position: {pltpos}."); + IsSwapping = true; ServerSendCharacterInputRpc(pltpos); } diff --git a/Assets/Scripts/Gameplay/PlayerScoreComponent.cs b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs new file mode 100644 index 0000000..c14b021 --- /dev/null +++ b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs @@ -0,0 +1,34 @@ +using UnityEngine; +using Unity.Netcode; + +public class PlayerScoreComponent : NetworkBehaviour +{ + public int CurrentScore { get; private set; } + + public override void OnNetworkSpawn() + { + if (IsOwner && IsClient) + { + Debug.Log($"[PlayerScoreComponent] Requesting score initialization for Player {OwnerClientId}"); + ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId); + } + // For the server player (host), ensure the PlayerScoreComponent is registered properly + if (IsServer && OwnerClientId == NetworkManager.Singleton.LocalClientId) + { + ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId); + } + } + + public void UpdateScore(int newScore) + { + CurrentScore = newScore; + Debug.Log($"[PlayerScoreComponent] Player {OwnerClientId} score updated to {newScore}."); + UpdateScoreUI(); + } + + private void UpdateScoreUI() + { + // Update the player's score display in the UI. + Debug.Log($"[PlayerScoreComponent] Updated score UI for Player {OwnerClientId}: {CurrentScore}"); + } +} diff --git a/Assets/Scripts/Gameplay/PlayerScoreComponent.cs.meta b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs.meta new file mode 100644 index 0000000..6838e13 --- /dev/null +++ b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a73f85cd904406945a2192aaecb2c310 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/ScoreManager.cs b/Assets/Scripts/Gameplay/ScoreManager.cs new file mode 100644 index 0000000..c972b5b --- /dev/null +++ b/Assets/Scripts/Gameplay/ScoreManager.cs @@ -0,0 +1,137 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.Multiplayer.Samples.BossRoom; +using UnityEngine; +using Unity.Netcode; + +public class ScoreManager : NetworkBehaviour +{ + public static ScoreManager Instance { get; private set; } + + private Dictionary playerScores = new Dictionary(); + + private void Awake() + { + if (Instance != null && Instance != this) + { + Destroy(gameObject); + return; + } + Instance = this; + } + + public override void OnNetworkSpawn() + { + if (IsServer) + { + StartCrowPenaltyCoroutineServerRpc(); + } + } + + [ServerRpc(RequireOwnership = false)] + public void InitializePlayerScoreServerRpc(ulong ownerClientId) + { + if (!playerScores.ContainsKey(ownerClientId)) + { + playerScores[ownerClientId] = 200; + Debug.Log($"[ScoreManager] Player {ownerClientId} initialized with a starting score of 200."); + UpdatePlayerScoreClientRpc(ownerClientId, 200); + } + else + { + Debug.LogWarning($"[ScoreManager] Player {ownerClientId} already initialized."); + } + } + + + public void UpdatePlayerScore(ulong ownerClientId, int newScore) + { + if (playerScores.ContainsKey(ownerClientId)) + { + playerScores[ownerClientId] = newScore; + Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {newScore}."); + UpdatePlayerScoreClientRpc(ownerClientId, newScore); + } + else + { + Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}. Cannot update score."); + } + } + + public int GetPlayerScore(ulong ownerClientId) + { + if (playerScores.TryGetValue(ownerClientId, out var score)) + { + return score; + } + Debug.LogError($"[ScoreManager] No entry found for Player {ownerClientId}."); + return 0; // Default score + } + + [ServerRpc] + public void StartCrowPenaltyCoroutineServerRpc() + { + StartCoroutine(ApplyCrowPenaltyCoroutine()); + } + + private IEnumerator ApplyCrowPenaltyCoroutine() + { + yield return new WaitUntil(() => PlatformManager.Instance != null && PlatformManager.Instance.AreAllPlatformsOccupied()); + while (true) + { + var modifications = new List>(); + + foreach (var entry in playerScores) + { + var ownerClientId = entry.Key; + var score = entry.Value; + + // Check if the player is the crow + if (CrowManager.Instance != null && CrowManager.Instance.GetCurrentCrow().OwnerClientId == ownerClientId) + { + var newScore = score - 2; + modifications.Add(new KeyValuePair(ownerClientId, newScore)); + Debug.Log($"[ScoreManager] Applied crow penalty to Player {ownerClientId}. New score: {newScore}"); + } + } + + // Apply the modifications after the iteration + foreach (var modification in modifications) + { + UpdatePlayerScore(modification.Key, modification.Value); + } + + // Wait for the next penalty application + yield return new WaitForSeconds(5f); + } + } + + [ClientRpc] + public void UpdatePlayerScoreClientRpc(ulong ownerClientId, int newScore) + { + Debug.Log($"[ScoreManager] Received score update for Player {ownerClientId}: {newScore}"); + var playerScoreComponent = FindPlayerScoreComponent(ownerClientId); + if (playerScoreComponent != null) + { + playerScoreComponent.UpdateScore(newScore); + } + else + { + Debug.LogError($"[ScoreManager] Could not find PlayerScoreComponent for Player {ownerClientId}"); + } + } + + + private PlayerScoreComponent FindPlayerScoreComponent(ulong ownerClientId) + { + foreach (var scoreComponent in FindObjectsOfType()) + { + if (scoreComponent.OwnerClientId == ownerClientId) + { + return scoreComponent; + } + } + Debug.LogError($"[ScoreManager] Could not find PlayerScoreComponent for Player {ownerClientId}"); + return null; + } +} diff --git a/Assets/Scripts/Gameplay/ScoreManager.cs.meta b/Assets/Scripts/Gameplay/ScoreManager.cs.meta new file mode 100644 index 0000000..e02683b --- /dev/null +++ b/Assets/Scripts/Gameplay/ScoreManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c42f66f946855da4b99f79c5bde1d545 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 3d1ef50..02c5013 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -4,7 +4,7 @@ QualitySettings: m_ObjectHideFlags: 0 serializedVersion: 5 - m_CurrentQuality: 4 + m_CurrentQuality: 0 m_QualitySettings: - serializedVersion: 3 name: Low @@ -29,6 +29,7 @@ QualitySettings: billboardsFaceCameraPosition: 0 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 25 lodBias: 0.3 maximumLODLevel: 1 enableLODCrossFade: 1 @@ -79,6 +80,7 @@ QualitySettings: billboardsFaceCameraPosition: 0 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 25 lodBias: 0.4 maximumLODLevel: 0 enableLODCrossFade: 1 @@ -129,6 +131,7 @@ QualitySettings: billboardsFaceCameraPosition: 1 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 25 lodBias: 1.5 maximumLODLevel: 0 enableLODCrossFade: 1 @@ -179,6 +182,7 @@ QualitySettings: billboardsFaceCameraPosition: 1 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 50 lodBias: 2 maximumLODLevel: 0 enableLODCrossFade: 1 @@ -229,6 +233,7 @@ QualitySettings: billboardsFaceCameraPosition: 0 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 50 lodBias: 0.4 maximumLODLevel: 1 enableLODCrossFade: 1 @@ -278,6 +283,7 @@ QualitySettings: billboardsFaceCameraPosition: 0 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 100 lodBias: 1 maximumLODLevel: 0 enableLODCrossFade: 1 @@ -327,6 +333,7 @@ QualitySettings: billboardsFaceCameraPosition: 0 useLegacyDetailDistribution: 1 vSyncCount: 0 + realtimeGICPUUsage: 25 lodBias: 1.5 maximumLODLevel: 0 enableLODCrossFade: 1