플레이어의 최대 자원이 플레이어에 정의한 값을 사용하도록 함
50으로 설정해도 100으로 작동하는 문제가 해결됨
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Northbound
|
||||
public static ServerResourceManager Instance { get; private set; }
|
||||
|
||||
private Dictionary<ulong, int> _playerResources = new Dictionary<ulong, int>();
|
||||
private Dictionary<ulong, int> _playerMaxCapacity = new Dictionary<ulong, int>();
|
||||
private NetworkVariable<int> _resourcesData = new NetworkVariable<int>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user