using Unity.Netcode; using UnityEngine; namespace Northbound { /// /// 플레이어의 자원 인벤토리 관리 /// public class PlayerResourceInventory : NetworkBehaviour { [Header("Inventory Settings")] public int maxResourceCapacity = 100; // 최대 자원 보유량 private NetworkVariable _currentResourceAmount = new NetworkVariable( 0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server ); public int CurrentResourceAmount => _currentResourceAmount.Value; public int MaxResourceCapacity => maxResourceCapacity; /// /// 자원을 추가할 수 있는지 확인 /// public bool CanAddResource(int amount) { return _currentResourceAmount.Value + amount <= maxResourceCapacity; } /// /// 추가 가능한 최대 자원량 계산 /// public int GetAvailableSpace() { return maxResourceCapacity - _currentResourceAmount.Value; } /// /// 자원 추가 (서버에서만 호출) /// [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)] public void AddResourceServerRpc(int amount) { if (amount <= 0) return; int actualAmount = Mathf.Min(amount, maxResourceCapacity - _currentResourceAmount.Value); _currentResourceAmount.Value += actualAmount; Debug.Log($"플레이어 {OwnerClientId} - 자원 추가: +{actualAmount}, 현재: {_currentResourceAmount.Value}/{maxResourceCapacity}"); } /// /// 자원 제거 (서버에서만 호출) /// [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)] public void RemoveResourceServerRpc(int amount) { if (amount <= 0) return; int actualAmount = Mathf.Min(amount, _currentResourceAmount.Value); _currentResourceAmount.Value -= actualAmount; Debug.Log($"플레이어 {OwnerClientId} - 자원 사용: -{actualAmount}, 현재: {_currentResourceAmount.Value}/{maxResourceCapacity}"); } /// /// 자원 설정 (서버에서만 호출) /// [Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)] public void SetResourceServerRpc(int amount) { _currentResourceAmount.Value = Mathf.Clamp(amount, 0, maxResourceCapacity); } } }