Example #1
0
    public void ManageGoals()
    {
        //First check if the current plan is invalid.
        //Then check if the current plan has validated the WS conditions
        //If this is so, then we need to find a new relevant goal and set that to the current goal
        if (CurrentGoal != null)
        {
            if (CurrentGoal.ReplanRequired())
            {
                if (Owner.debugGOAP)
                {
                    Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - REPLAN required !!", Owner);
                }

                if (ReplanCurrentGoal() == false)
                {
                    if (Owner.debugGOAP)
                    {
                        Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - REPLAN failed, find new goal", Owner);
                    }

                    FindNewGoal();
                }
            }
            else if (!CurrentGoal.IsPlanValid())
            {
                //Current goal's plan is invalid, replan and update goals flags set

                if (Owner.debugGOAP)
                {
                    Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - INVALID, find new goal", Owner);
                }

                FindNewGoal();
            }
            else if (CurrentGoal.IsSatisfied())
            {
//	Current goal's goal WS has been satisfied, replan and update goals flags set
                if (Owner.debugGOAP)
                {
                    Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - DONE, find new goal", Owner);
                }

                FindNewGoal();
            }
            else if (CurrentGoal.IsPlanInterruptible())
            {
                FindMostImportantGoal();
            }
        }
        else
        {
            FindNewGoal();
        }
    }