// Gets a resource target if possible public void GetResourceTarget(TileManager tileManager) { // Value of the target resource int resourceValue = 0; // Get all objects within move distance sphere on layer 9 (resource layer) float radius = GPSM.GetDist() * TileUtils.PlayerMoveDistance; Collider2D[] hitColliders = Physics2D.OverlapCircleAll(merchant.Position, radius, 1 << LayerMask.NameToLayer("Resources")); // Determine highest value if possible for (int index = 0; index < hitColliders.Length; index++) { // Get ResourceType of resource hit ResourceType resourceType = tileManager.GetResourceType(hitColliders[index].gameObject.name); // Get worth/value of the resource Resource resource = (Resource)ItemDatabase.Instance.Items.Find(tempItem => tempItem.Type == resourceType.ToString()); // Check if the AI can carry the resource if (((Merchant)Entity).TotalWeight + resource.Weight <= ((Merchant)Entity).MaxWeight) { // If the value is higher than current target, replace it as the new target if (resourceValue < resource.Worth) { merchant.Target = hitColliders[index].transform.position; resourceValue = resource.Worth; } // end if resourceValue < resource.Worth } // end if } //end for // Verify there is a target, otherwise set it to a village if (merchant.Target == Vector3.zero) { // Get the proper market target GetMarketTarget(tileManager); } //end if }