示例#1
0
    public bool UpdatePlan(WorldState curWS)
    {
        if (_actions.Count == 0)
        {
            return(false);
        }

        GOAPAction curGOAPAction = _actions.Peek();

        if (!curGOAPAction.IsValid())
        {
            Clear();
            return(false);
        }

        if (curGOAPAction.IsFinished)
        {
            //curGOAPAction.ApplyEffect(curWS); // 实施效果(其实没必要调用了,因为这时候没有必要设置ws效果了,因为ws的效果没有意义,接着执行下面的action就行)
            _actions.Dequeue().Release();
            if (_actions.Count > 0)
            {
                curGOAPAction = _actions.Peek();
                curGOAPAction.Activate();
            }
        }
        else
        {
            curGOAPAction.UpdateGOAPAction();
        }

        return(true);
    }
示例#2
0
 public bool Execute()
 {
     curAction = isFinished ? null : m_Actions[curStep];
     if (curAction != null)
     {
         if (!curAction.CheckPreconditions())
         {
             return(false);
         }
         curAction.Activate();
     }
     return(true);
 }
示例#3
0
    /*
     * Activate the GOAP plan
     */

    public bool Activate(Agent ai, GOAPGoal goal)
    {
        Owner = ai;

        /*if(ai.debugGOAP)
         * {
         *  string s = this.ToString() + " - Activated for " + goal.ToString() + " do actions:";
         *  for (int i = 0 ; i < m_Actions.Count ; i++)
         *      s += " " + m_Actions[i].ToString();
         *
         *  Debug.Log(Time.timeSinceLevelLoad + " " + s);
         * }*/

        if (m_Actions.Count == 0)
        {
            return(false);
        }

        //Get the first action
        CurrentStep = 0;

        //For the first action, first check if context preconditions are satisfied.
        GOAPAction a = CurrentAction;

        if (a != null)
        {
            if (a.ValidateContextPreconditions(Owner) == false)
            {//Are the context preconditions validated????
                //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - " + a.ToString() + " ValidateContextPreconditions failed !!");
                return(false);
            }

            a.Activate();
//			if(a.IsActionComplete())
//				AdvancePlan();
        }

        return(true);
    }