Example #1
0
    /* PLANINING PHASE */
    public override bool CheckProceduralPreconditions()
    {
        GameObject pickable = detectedMemory.GetSortedDetected();

        Agent enemy = agent.Memory.Enemies.GetSortedDetected()?.GetComponent <Agent>();

        // Enemy in sight
        if (enemy != null && pickable != null)
        {
            // How many seconds until agent reaches pickable
            float timeToPickable = Utilities.TimeToReach(transform.position, pickable, agent.Navigation.currentSpeed);

            // Total seconds until agent collects pickable
            float timeAgentToExecute = timeToPickable + pickable.GetComponent <Pickable>().timeToCollect;

            // How many seconds until enemy reaches agent
            float timeToEnemy = Utilities.TimeToReach(transform.position, enemy.gameObject, enemy.Navigation.currentSpeed);

            // How many seconds until enemy fires all ammo
            float timeToFullDamage = enemy.Inventory.Ammo.Amount * 0.5f;

            // Total time until enemy reaches agent and fires all ammo
            float timeToEnemyExecute = timeToEnemy + timeToFullDamage;

            // How many seconds can agent sustain damage
            float timeToDeath = (agent.Inventory.Health.Amount / 10) * 0.5f;

            if (timeAgentToExecute > timeToEnemyExecute)
            {
                return(true);
            }
            else
            {
                // Agent can survive the attack
                if (timeToDeath - timeToFullDamage > 0)
                {
                    return(true);
                }
                // Agent can not survive attack
                else
                {
                    detectedMemory.InvalidateDetected(pickable, 4f);
                    return(false);
                }
            }
        }
        else
        {
            // No enemies in sight
            return(true);
        }
    }
Example #2
0
    /* LIFECYCLE PHASE */


    public override void SetActionTarget()
    {
        if (detectedMemory.IsAnyValidDetected())
        {
            target = detectedMemory.GetSortedDetected();
            agent.Navigation.SetTarget(target);
        }
        else
        {
            ActionAbort();
        }
    }