void StartHarvest(IHarvestable harvestable) { if (!_harvesting && harvestable != null) { // Turn off movement if we need to stay for harvest if (harvestable.StayToHarvest()) { _behaviour.canMove = false; } _harvesting = true; harvestable.Harvest(CollectHarvest); } }
public override void Execute() { (_objectToHarvest as IDestroyable).OnDestroyed -= OnObjectDestroyedOutside; _objectToHarvest.Harvest(); Finish(true); }
private IEnumerator Harvest() { Harvesting = true; while (Harvesting) { agent.isStopped = false; agent.SetDestination(currentHarvestable.Position); while (Vector3.Magnitude(Position - currentHarvestable.Position) > agent.stoppingDistance * 2) { if (!Harvesting) { break; } else if (harvestableUpdated) { agent.SetDestination(currentHarvestable.Position); harvestableUpdated = false; } yield return(null); } if (!Harvesting) { break; } agent.isStopped = true; if (Stash != 0) { if (ResourceType != currentHarvestable.ResourceType) { Stash = 0; } } ResourceType = currentHarvestable.ResourceType; var timeElapsed = 0f; while (Stash < Settings.MaxWorkerStash) { timeElapsed = 0f; while (timeElapsed < Settings.WorkIterationLength) { timeElapsed += Time.deltaTime; if (!Harvesting || harvestableUpdated) { break; } yield return(null); } if (!Harvesting || harvestableUpdated) { break; } else { Stash += currentHarvestable.Harvest(); } } if (!Harvesting) { break; } else if (harvestableUpdated) { harvestableUpdated = false; } else { if (resourceDepot == null) { resourceDepot = resourceDepotManager.GetClosestDepot(this, ResourceType); } var closestPoint = resourceDepot.GetClosestPoint(Position); agent.isStopped = false; agent.SetDestination(closestPoint); while (Vector3.Magnitude(Position - closestPoint) > agent.stoppingDistance * 2) { yield return(null); } agent.isStopped = true; resourceDepotManager.Deliver(ResourceType, Stash); Stash = 0; } } }
private static void Harvest(IHarvestable harvestable) { harvestable.Harvest(); }