Esempio n. 1
0
            public void removeListener(DIntervalListener p_listener)
            {
                if (!m_listeners.Contains(p_listener))
                {
                    return;
                }

                m_listeners.Remove(p_listener);
            }
Esempio n. 2
0
            public void addListener(float p_period, DIntervalListener p_listener)
            {
                if (!m_ticks.ContainsKey(p_period))
                {
                    m_ticks.Add(p_period, new IntervalTick(p_period));
                }

                m_ticks[p_period].addListener(p_listener);
            }
Esempio n. 3
0
            public void removeListener(float p_period, DIntervalListener p_listener)
            {
                if (!m_ticks.ContainsKey(p_period))
                {
                    return;
                }

                m_ticks[p_period].removeListener(p_listener);

                if (m_ticks[p_period].numListeners() == 0)
                {
                    m_ticks.Remove(p_period);
                }
            }
Esempio n. 4
0
 public void addListener(DIntervalListener p_listener)
 {
     m_listeners.Add(p_listener);
 }
    private void gather()
    {
        //Get list of gatherable resources
        GameObject[] obs = sense("RESOURCE");

        List <GameObject> resources     = new List <GameObject>();
        Vector3           this_position = gameObject.transform.position;

        foreach (GameObject o in obs)
        {
            if (Vector2Calc.proximity(this_position, o.transform.position) < 1f)
            {
                resources.Add(o);
            }
        }

        //If there are none, return
        if (resources.Count == 0)
        {
            return;
        }

        //Get the closest resource in gather arc
        float      closeness  = float.PositiveInfinity;
        GameObject to_harvest = null;

        foreach (GameObject o in resources)
        {
            float proximity = Vector2Calc.proximity(this_position, o.transform.position);
            if (!(proximity < closeness))
            {
                continue;
            }
            closeness  = proximity;
            to_harvest = o;
        }

        //Gather the resource
        m_brain_stop         = true;
        m_rb.velocity        = Vector3.zero;
        m_rb.angularVelocity = 0;
        m_actions.flush();

        m_cooldowns.activate("GATHER", 0.5f);

        GameObject line = LineCreator.createLine(this_position + (Vector3Calc.fromVec2(m_forward) * 0.1f), to_harvest.transform.position, Color.green, 0.05f, 0.5f);

        Resource          harvesting  = to_harvest.GetComponent <Resource>();
        DIntervalListener energy_suck = () =>
        {
            float harvest_power = m_energy.Max - m_energy.Value;
            if (harvest_power > 10f)
            {
                harvest_power = 10f;
            }
            if (to_harvest != null)
            {
                m_energy.add(harvesting.collect(harvest_power));
            }
        };

        m_im.addListener(0.1f, energy_suck);

        m_tm.addTimeout(0.5f, () =>
        {
            m_im.removeListener(0.1f, energy_suck);
            m_brain_stop = false;
        });
    }