예제 #1
0
    protected override bool ExecuteBehaviour(NewTaskCallback onTaskChangeCallback)
    {
        // Chase target and attack in melee


        if (aiController.CombatTarget != null && aiController.CombatTarget.GetComponent <CombatStats>().IsAlive)
        {
            float distance = Vector3.Distance(owner.transform.position, aiController.CombatTarget.transform.position);

            if (distance > aiController.SearchRadius)
            {
                aiController.IsAttackingMelee = false;
                // Later, make this event based. All animations should be handled within AIController.
                characterAnimator.SetBool("IsAttackingMelee", aiController.IsAttackingMelee);
                aiController.CombatTarget = null;
                navAgent.isStopped        = false;
                //StartCoroutine(LookForTargetTask());
                onTaskChangeCallback.Invoke(this, taskMngr.GetTaskOfType <LookForTarget>());
                return(false);
            }
            else if (distance > (aiController.MeleeDistance - 1f))
            {
                aiController.IsAttackingMelee = false;
                characterAnimator.SetBool("IsAttackingMelee", aiController.IsAttackingMelee);
                if (navAgent.destination != aiController.CombatTarget.transform.position)
                {
                    navAgent.destination = aiController.CombatTarget.transform.position;
                }
                navAgent.isStopped = false;
            }
            else
            {
                if (!aiController.IsAttackingMelee)
                {
                    // Set melee enabled should probably also be some kind of event.
                    aiController.SetMeleeEnabled(true);
                    characterAnimator.SetFloat("MeleeAttackSpeed", combatStats.MeleeAttackSpeed);

                    // Need some kind of way to stop this once the the task is completed.
                    taskMngr.StartCoroutine(aiController.RotateTowardsTarget());
                }
            }
        }
        else
        {
            aiController.CombatTarget = null;
            aiController.SetMeleeEnabled(false);
            //StartCoroutine(LookForTargetTask());
            onTaskChangeCallback.Invoke(this, taskMngr.GetTaskOfType <LookForTarget>());
            return(false);
        }
        return(true);
    }
예제 #2
0
    // I used to have a Run method in Task but since Task is no longer a monoBehaviour the coroutine is now started on TaskManager, so Process is public now. I might remove coroutines and create a thread instead, it would look better to have Process be private and Task have a public Run method instead.
    public IEnumerator Process(NewTaskCallback onTaskChangeCallback, params object[] paramArr)
    {
        //isRunning = false;
        OnStart(paramArr);
        bool running = true;

        while (running && combatStats.IsAlive)
        {
            running = taskBehaviour(onTaskChangeCallback);
            yield return(new WaitForSeconds(AIManager.TASK_UPDATE_RATE));
        }

        // Need some check to see if it should run this. Maybe some behaviours in this method should not run when a task is killed but only when it is finished.
        OnEnd();
    }
예제 #3
0
    protected override bool ExecuteBehaviour(NewTaskCallback onTaskChangeCallback)
    {
        // Stand stationary until enemy comes close

        bool foundTarget = false;

        foundTarget = aiController.SearchForTarget();

        if (foundTarget)
        {
            taskMngr.DetermineAttackTask(this);
        }
        //Debug.Log("Running: " + GetType() + ", on " + owner.name + ", FoundTarget " + foundTarget + " , at " + Time.time);
        // return negated foundTarget so that if it hasn't found a target it keeps iterating.
        return(!foundTarget);
    }
예제 #4
0
 protected override bool ExecuteBehaviour(NewTaskCallback onTaskChangeCallback)
 {
     if (!aiController.SearchForTarget())
     {
         if (Vector3.Distance(owner.transform.position, navAgent.destination) < 1f)
         {
             onTaskChangeCallback.Invoke(this, taskMngr.GetTaskOfType <Guard>());
             return(false);
         }
     }
     else
     {
         taskMngr.DetermineAttackTask(this);
         return(false);
     }
     return(true);
 }
예제 #5
0
    protected override bool ExecuteBehaviour(NewTaskCallback onTaskChangeCallback)
    {
        // Look around for target for a bit by walking to random points within the AI entity's search radius.

        bool foundTarget = false;

        if (searchTimer >= searchTime)
        {
            searchTimer = 0f;
            // Set to return to start position.
            onTaskChangeCallback.Invoke(this, taskMngr.GetTaskOfType <ReturnToOrigin>());
            return(true);
        }
        else
        {
            foundTarget = aiController.SearchForTarget();

            if (!foundTarget)
            {
                if (Vector3.Distance(owner.transform.position, navAgent.destination) > 1f)
                {
                    // Do nothing?
                    //Debug.Log("Distance more than 1f");
                }
                else
                {
                    //Debug.Log("Trying to find new destination...");
                    Vector3 newDestination;
                    if (aiController.GetRandomVectorInSearchRadius(out newDestination))
                    {
                        //Debug.Log("Found new destination! At vector: " + newDestination);
                        navAgent.destination = newDestination;
                    }
                }
            }
        }
        searchTimer += AIManager.TASK_UPDATE_RATE;
        //Debug.Log("Running: " + GetType() + ", on " + owner.name + ", foundTarget " + foundTarget + " , at " + Time.time + ", SearchTimer at " + searchTimer);
        if (foundTarget)
        {
            taskMngr.DetermineAttackTask(this);
        }
        return(!foundTarget);
    }
예제 #6
0
 // returning true means keep running the task, returning false means to stop the task.
 protected abstract bool ExecuteBehaviour(NewTaskCallback onTaskChangeCallback);