diff --git a/Assets/Prefabs/Resource.prefab b/Assets/Prefabs/Resource.prefab index f0c4c6a..339c590 100644 --- a/Assets/Prefabs/Resource.prefab +++ b/Assets/Prefabs/Resource.prefab @@ -76,7 +76,7 @@ MonoBehaviour: maxResources: 200 resourcesPerGathering: 10 gatheringCooldown: 0 - resourceName: "\uAD11\uC11D" + resourceName: Mana rechargeInterval: 1 rechargeAmount: 5 _qualityPercentage: diff --git a/Assets/Scenes/GameMain.unity b/Assets/Scenes/GameMain.unity index a13f6e4..d462488 100644 --- a/Assets/Scenes/GameMain.unity +++ b/Assets/Scenes/GameMain.unity @@ -3482,7 +3482,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3} propertyPath: m_AnchoredPosition.y - value: 0 + value: -100 objectReference: {fileID: 0} - target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3} propertyPath: m_LocalEulerAnglesHint.x diff --git a/Assets/Scripts/PlayerResourceInventory.cs b/Assets/Scripts/PlayerResourceInventory.cs index 222dd25..b015eee 100644 --- a/Assets/Scripts/PlayerResourceInventory.cs +++ b/Assets/Scripts/PlayerResourceInventory.cs @@ -11,10 +11,21 @@ namespace Northbound public int CurrentResourceAmount => _displayAmount; public int MaxResourceCapacity => maxResourceCapacity; + [Rpc(SendTo.Server)] + private void SetMaxCapacityServerRpc(int maxCapacity) + { + var resourceManager = ServerResourceManager.Instance; + if (resourceManager != null) + { + resourceManager.SetPlayerMaxCapacity(OwnerClientId, maxCapacity); + } + } + public override void OnNetworkSpawn() { if (IsClient && IsOwner) { + SetMaxCapacityServerRpc(maxResourceCapacity); RequestResourceUpdateServerRpc(); } } diff --git a/Assets/Scripts/ServerResourceManager.cs b/Assets/Scripts/ServerResourceManager.cs index 27e0c46..a190f2c 100644 --- a/Assets/Scripts/ServerResourceManager.cs +++ b/Assets/Scripts/ServerResourceManager.cs @@ -9,6 +9,7 @@ namespace Northbound public static ServerResourceManager Instance { get; private set; } private Dictionary _playerResources = new Dictionary(); + private Dictionary _playerMaxCapacity = new Dictionary(); private NetworkVariable _resourcesData = new NetworkVariable(); private void Awake() @@ -51,6 +52,7 @@ namespace Northbound private void OnClientDisconnected(ulong clientId) { _playerResources.Remove(clientId); + _playerMaxCapacity.Remove(clientId); } public int GetPlayerResourceAmount(ulong clientId) @@ -64,27 +66,30 @@ namespace Northbound public bool CanAddResource(ulong clientId, int amount) { - if (_playerResources.TryGetValue(clientId, out var resource)) + if (_playerResources.TryGetValue(clientId, out var resource) && + _playerMaxCapacity.TryGetValue(clientId, out var maxCapacity)) { - return resource + amount <= 100; + return resource + amount <= maxCapacity; } return false; } public int GetAvailableSpace(ulong clientId) { - if (_playerResources.TryGetValue(clientId, out var resource)) + if (_playerResources.TryGetValue(clientId, out var resource) && + _playerMaxCapacity.TryGetValue(clientId, out var maxCapacity)) { - return 100 - resource; + return maxCapacity - resource; } return 0; } public void AddResource(ulong clientId, int amount) { - if (_playerResources.TryGetValue(clientId, out var resource)) + if (_playerResources.TryGetValue(clientId, out var resource) && + _playerMaxCapacity.TryGetValue(clientId, out var maxCapacity)) { - int actualAmount = Mathf.Min(amount, 100 - resource); + int actualAmount = Mathf.Min(amount, maxCapacity - resource); _playerResources[clientId] = resource + actualAmount; } } @@ -97,5 +102,19 @@ namespace Northbound _playerResources[clientId] = resource - actualAmount; } } + + public void SetPlayerMaxCapacity(ulong clientId, int maxCapacity) + { + _playerMaxCapacity[clientId] = maxCapacity; + } + + public int GetPlayerMaxCapacity(ulong clientId) + { + if (_playerMaxCapacity.TryGetValue(clientId, out var maxCapacity)) + { + return maxCapacity; + } + return 100; + } } }