diff --git a/Assets/Prefabs/Worker.prefab b/Assets/Prefabs/Worker.prefab index a5c5ed3..b99e747 100644 --- a/Assets/Prefabs/Worker.prefab +++ b/Assets/Prefabs/Worker.prefab @@ -105,7 +105,8 @@ MonoBehaviour: miningSpeed: 1 followDistance: 3 movementSpeed: 21.41 - resourcesPerMining: 5 + resourcesPerMining: 29 + recruitmentCost: 10 interactionAnimationTrigger: miningEffectPrefab: {fileID: 0} depositEffectPrefab: {fileID: 0} diff --git a/Assets/Scripts/Resource.cs b/Assets/Scripts/Resource.cs index 390e9e3..c3d3c0f 100644 --- a/Assets/Scripts/Resource.cs +++ b/Assets/Scripts/Resource.cs @@ -78,21 +78,21 @@ namespace Northbound return _currentWorkerId.Value == workerId; } - public void TakeResourcesForWorker(int amount, ulong workerId) + public int TakeResourcesForWorker(int amount, ulong workerId) { - if (!IsServer) return; + if (!IsServer) return 0; if (!allowMultipleWorkers) { if (_currentWorkerId.Value != ulong.MaxValue && _currentWorkerId.Value != workerId) - return; + return 0; } int availableResources = _currentResources.Value; int actualAmount = Mathf.Min(amount, availableResources); if (actualAmount <= 0) - return; + return 0; _currentResources.Value -= actualAmount; _lastGatheringTime = Time.time; @@ -108,6 +108,8 @@ namespace Northbound } ShowGatheringEffectClientRpc(); + + return actualAmount; } private NetworkVariable _currentResources = new NetworkVariable( diff --git a/Assets/Scripts/Worker.cs b/Assets/Scripts/Worker.cs index b2c3a0c..f2ec360 100644 --- a/Assets/Scripts/Worker.cs +++ b/Assets/Scripts/Worker.cs @@ -8,7 +8,8 @@ namespace Northbound Idle = 0, Following = 1, Mining = 2, - Returning = 3 + Returning = 3, + WaitingForResource = 4 } [RequireComponent(typeof(Collider))] @@ -136,6 +137,9 @@ namespace Northbound case WorkerState.Returning: HandleReturning(); break; + case WorkerState.WaitingForResource: + HandleWaitingForResource(); + break; } } @@ -186,6 +190,13 @@ namespace Northbound return; } + if (!_targetResource.HasResourcesAvailable()) + { + SetState(WorkerState.WaitingForResource); + PlayIdleAnimation(); + return; + } + float distance = GetDistanceToCollider(_targetResource.GetComponent()); if (distance > 2f) @@ -225,6 +236,41 @@ namespace Northbound } } + private void HandleWaitingForResource() + { + if (_targetResource == null) + { + SetState(WorkerState.Following); + PlayIdleAnimation(); + return; + } + + if (IsBagFull) + { + SetState(WorkerState.Returning); + PlayIdleAnimation(); + return; + } + + if (_targetResource.HasResourcesAvailable()) + { + SetState(WorkerState.Mining); + PlayMoveAnimation(); + return; + } + + float distance = GetDistanceToCollider(_targetResource.GetComponent()); + + if (distance > 3f) + { + MoveTowards(_targetResource.transform.position); + } + else + { + PlayIdleAnimation(); + } + } + private float GetDistanceToCollider(Collider targetCollider) { if (targetCollider == null) @@ -274,8 +320,8 @@ namespace Northbound if (mineAmount > 0) { - _targetResource.TakeResourcesForWorker(mineAmount, NetworkObject.NetworkObjectId); - _currentBagResources.Value += mineAmount; + int actualAmount = _targetResource.TakeResourcesForWorker(mineAmount, NetworkObject.NetworkObjectId); + _currentBagResources.Value += actualAmount; _lastMiningTime = Time.time; ShowMiningEffectClientRpc(); @@ -303,6 +349,10 @@ namespace Northbound { SetState(WorkerState.Mining); } + else if (_targetResource != null) + { + SetState(WorkerState.WaitingForResource); + } else { SetState(WorkerState.Following); @@ -427,6 +477,7 @@ namespace Northbound WorkerState.Following => "따라가는 중", WorkerState.Mining => "채굴 중", WorkerState.Returning => "반환 중", + WorkerState.WaitingForResource => "자원 대기 중", _ => "대기 중" }; return $"워커 (가방: {_currentBagResources.Value}/{maxBagCapacity}) - {stateText}"; @@ -507,6 +558,9 @@ namespace Northbound case WorkerState.Returning: PlayMoveAnimation(); break; + case WorkerState.WaitingForResource: + PlayIdleAnimation(); + break; } } @@ -642,6 +696,12 @@ namespace Northbound Gizmos.DrawLine(transform.position, _targetResource.transform.position); } + if (_currentState.Value == WorkerState.WaitingForResource && _targetResource != null) + { + Gizmos.color = Color.blue; + Gizmos.DrawLine(transform.position, _targetResource.transform.position); + } + if (_currentState.Value == WorkerState.Returning && _core != null) { Gizmos.color = Color.green;