Example #1
0
    private IEnumerator HarvestingRoutine(BaseInteractable aHarvestingResource)
    {
        float timer = 0;

        this._rigidBody.velocity = Vector3.zero;
        Debug.Log("HarvestingRoutine");
        ResourceInteractable resource = (ResourceInteractable)aHarvestingResource;
        float       harvestingTime    = resource.HarvestingTime;
        ProgressBar bar = UIManager.Instance.GetProgressBar(resource.gameObject);

        while (timer <= harvestingTime)
        {
            bar.SetProgress(timer / harvestingTime);
            timer += Time.deltaTime;
            yield return(null);
        }
        Destroy(bar.gameObject);
        if (mInventory.ContainsItem(resource.itemScriptableObject))
        {
            for (int i = 0; i < mInventory.m_Items.Count; i++)
            {
                if (mInventory.m_Items[i].ItemType == ItemType.RESOURCE && mInventory.m_Items[i].ResourceType == resource.ResourceType)
                {
                    mInventory.m_Items[i].IncreaseQuantity(resource.Interact(mInventory.GetCurrentItem()));
                }
            }
        }
        else
        {
            //Create a new item
            Item newItem = Instantiate(resource.itemScriptableObject);
            newItem.IncreaseQuantity(resource.Interact(mInventory.GetCurrentItem()));
            mInventory.AddNewItem(newItem);
        }

        if (resource.secondaryHarvest)
        {
            if (mInventory.ContainsItem(resource.secondaryHarvestItem))
            {
                for (int i = 0; i < mInventory.m_Items.Count; i++)
                {
                    if (mInventory.m_Items[i].ItemType == ItemType.RESOURCE && mInventory.m_Items[i].ResourceType == resource.SecondaryResourceType)
                    {
                        mInventory.m_Items[i].IncreaseQuantity(resource.Interact(mInventory.GetCurrentItem()));
                    }
                }
            }
            else
            {
                //Create a new item
                Item newItem = Instantiate(resource.secondaryHarvestItem);
                newItem.IncreaseQuantity(resource.Interact(mInventory.GetCurrentItem()));
                mInventory.AddNewItem(newItem);
            }
        }

        resource.ItemHarvested();
        if (resource.limitedResource)
        {
            if (resource.DepletedResource)
            {
                Destroy(resource.gameObject);
            }
        }
        mResources.DepleteResource(PlayerResoureType.STAMINA, true);
        //Do the harvesting things

        ChangeState(PlayerState.NORMAL, Vector3.zero);
        yield return(null);
    }