/// <summary> /// Handles state changes related to mementos /// /// If this enemy's nest is empty, it checks nearby for any abandoned mementos. /// If a memento is found, it changes the enemy state to TrackingMemento and /// sets the navAgent's destination /// If this enemy's nest is empty, and it's linked to another nest that does /// have a memento, it changes the enemy state to TargetingMemento and sets /// the navAgent's destination /// </summary> /// <return> true if the enemy state was changed, false otherwise </return> /// <thoughts> /// This method is called Check, but it does more than that, and it shouldn't. /// TODO: Break the contents of this function into two pieces: /// AttemptStateChange() /// ProcessStateChange() /// </thoughts> private bool CheckMemento() { if (NEST != null && NEST.MEMENTO == null) { //Check for any memento's out of Nests GameObject memento = _mementoUtils.GetClosestMemento(transform.position); Memento mc = memento.GetComponent <Memento> (); if (mc != null && Vector3.Distance(mc.transform.position, transform.position) <= MEMENTO_SEARCH_RADIUS && mc.GetHeldBy() == Memento.HeldBy.None && !mc.IN_NEST) { //Debug.Log("<color=blue>AI Debug: State Change: Patrolling -> TargetingMemento (nearby)</color>"); ChangeState(EnemyState.TargetingMemento); _navAgent.SetDestination(memento.transform.position); return(true); } else if (NEST != null && NEST.NEST_TO_TAKE_FROM != null && NEST.NEST_TO_TAKE_FROM.MEMENTO != null && Time.time - NEST.TIME_MEMENTO_ENTERED >= DELAY_BEFORE_TAKING_FROM_LINKED_NEST) { //Debug.Log("<color=blue>AI Debug: State Change: Patrolling -> TargetingMemento (other nest)</color>"); ChangeState(EnemyState.TargetingMemento); _navAgent.SetDestination(NEST.NEST_TO_TAKE_FROM.MEMENTO.transform.position); return(true); } } return(false); }