Esempio n. 1
0
    /// <summary>
    /// Perform the collect ore action.
    /// </summary>
    /// <param name="agent">The agent performing this action.</param>
    /// <returns>If the action was performed this frame.</returns>
    public override bool Perform(GameObject agent)
    {
        // Make sure the ore vein is active.
        if (m_Target.activeSelf != false)
        {
            if (m_StartTime == 0.0f)
            {
                m_StartTime = Time.time;
            }

            // Work complete.
            if (Time.time - m_StartTime > m_WorkDuration)
            {
                // Update everything that work has been done.
                m_Inventory.IncreaseOre(1);
                m_Mined = true;
                OreVein oreVein = m_Target.GetComponent <OreVein>();
                oreVein.DecreaseOreAmount(1);
                oreVein.SetCurrentMiner(null);

                agent.GetComponent <Worker>().DecreaseHunger(m_WorkHunger);
            }

            // Set progress for progress bar.
            m_Inventory.SetProgress((Time.time - m_StartTime) / m_WorkDuration);

            // The action was performed this frame.
            return(true);
        }
        // The action was not performed this frame.
        else
        {
            return(false);
        }
    }