예제 #1
0
    private IEnumerator GatherNode(ResourceNode node)
    {
        Debug.Log("Now gathering " + node.resourceType);
        // m_anim.SetTrigger("Gather");
        m_gathering = true;
        m_curNode   = node;
        node.AddGatherer(this);
        m_progressBar.gameObject.SetActive(true);
        m_progressBar.SetResourceIcon(node.resourceType);
        m_progressBar.SetFillAmount(0);
        float gatherProgress           = 0;
        GatheringOccupation occupation = (GatheringOccupation)m_unitStats.GetOccupation(GatheringOccupation.GetOccupationFromResource(node.resourceType));

        while (m_gathering)
        {
            if (!m_unitInventory.inventoryFull())
            {
                gatherProgress += occupation.GetGatherSpeed() * Time.deltaTime;
                int amount = (int)gatherProgress;
                if (amount >= 1)
                {
                    amount = node.Harvest(1);
                    if (amount == 0)
                    {
                        StopTask();
                        break;
                    }
                    if (m_unitInventory.tryAddResource(node.resourceType, amount))
                    {
                        occupation.GiveGatherExp(amount);
                    }
                    gatherProgress -= amount;
                    Debug.Log(node.resourceType + " gathered. unit now has " + m_unitInventory.getResource(node.resourceType) + "\ngather speed is " + occupation.GetGatherSpeed() + ". exp is " + occupation.getCurrentExp());
                }
                m_progressBar.SetFillAmount(gatherProgress);
            }
            if (m_unitInventory.inventoryFull())
            {
                // If inventory is full, cap gathering progress
                m_progressBar.SetFillAmount(1);
            }
            yield return(null);
        }
    }