플레이어의 최대 자원이 플레이어에 정의한 값을 사용하도록 함
50으로 설정해도 100으로 작동하는 문제가 해결됨
This commit is contained in:
@@ -76,7 +76,7 @@ MonoBehaviour:
|
|||||||
maxResources: 200
|
maxResources: 200
|
||||||
resourcesPerGathering: 10
|
resourcesPerGathering: 10
|
||||||
gatheringCooldown: 0
|
gatheringCooldown: 0
|
||||||
resourceName: "\uAD11\uC11D"
|
resourceName: Mana
|
||||||
rechargeInterval: 1
|
rechargeInterval: 1
|
||||||
rechargeAmount: 5
|
rechargeAmount: 5
|
||||||
_qualityPercentage:
|
_qualityPercentage:
|
||||||
|
|||||||
@@ -3482,7 +3482,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3}
|
- target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3}
|
||||||
propertyPath: m_AnchoredPosition.y
|
propertyPath: m_AnchoredPosition.y
|
||||||
value: 0
|
value: -100
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3}
|
- target: {fileID: 4412526746668541195, guid: 274613c415998a647a86a5e09950ce41, type: 3}
|
||||||
propertyPath: m_LocalEulerAnglesHint.x
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
|||||||
@@ -11,10 +11,21 @@ namespace Northbound
|
|||||||
public int CurrentResourceAmount => _displayAmount;
|
public int CurrentResourceAmount => _displayAmount;
|
||||||
public int MaxResourceCapacity => maxResourceCapacity;
|
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()
|
public override void OnNetworkSpawn()
|
||||||
{
|
{
|
||||||
if (IsClient && IsOwner)
|
if (IsClient && IsOwner)
|
||||||
{
|
{
|
||||||
|
SetMaxCapacityServerRpc(maxResourceCapacity);
|
||||||
RequestResourceUpdateServerRpc();
|
RequestResourceUpdateServerRpc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Northbound
|
|||||||
public static ServerResourceManager Instance { get; private set; }
|
public static ServerResourceManager Instance { get; private set; }
|
||||||
|
|
||||||
private Dictionary<ulong, int> _playerResources = new Dictionary<ulong, int>();
|
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 NetworkVariable<int> _resourcesData = new NetworkVariable<int>();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
@@ -51,6 +52,7 @@ namespace Northbound
|
|||||||
private void OnClientDisconnected(ulong clientId)
|
private void OnClientDisconnected(ulong clientId)
|
||||||
{
|
{
|
||||||
_playerResources.Remove(clientId);
|
_playerResources.Remove(clientId);
|
||||||
|
_playerMaxCapacity.Remove(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetPlayerResourceAmount(ulong clientId)
|
public int GetPlayerResourceAmount(ulong clientId)
|
||||||
@@ -64,27 +66,30 @@ namespace Northbound
|
|||||||
|
|
||||||
public bool CanAddResource(ulong clientId, int amount)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetAvailableSpace(ulong clientId)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddResource(ulong clientId, int amount)
|
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;
|
_playerResources[clientId] = resource + actualAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,5 +102,19 @@ namespace Northbound
|
|||||||
_playerResources[clientId] = resource - actualAmount;
|
_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