public void execute() { if (!mSelf.hasActionPlan()) { // no actions to perform Debug.Log("<color=red>Done actions</color>"); mSelf.ChangeState(new Idle()); return; } GoapAction action = mSelf.currentActions.Peek(); if (action.isDone()) { // the action is done. Remove it so we can perform the next one mSelf.currentActions.Dequeue(); } if (mSelf.hasActionPlan()) { // perform the next action action = mSelf.currentActions.Peek(); bool inRange = action.requiresInRange() ? action.isInRange() : true; if (inRange) { // we are in range, so perform the action bool success = action.perform(mSelf.gameObject); if (!success) { // action failed, we need to plan again mSelf.ChangeState(new Idle()); mSelf.dataProvider.planAborted(action); } } else { // we need to move there first // push moveTo state Debug.Log("Move Action"); } } else { // no actions left, move to Plan state mSelf.ChangeState(new Idle()); mSelf.dataProvider.actionsFinished(); } }
public void execute() { HashSet <KeyValuePair <string, object> > worldState = mSelf.dataProvider.getWorldState(); HashSet <KeyValuePair <string, object> > goal = mSelf.dataProvider.createGoalState(); // Plan Queue <GoapAction> plan = mSelf.planner.plan(mSelf.gameObject, mSelf.availableActions, worldState, goal); if (plan != null) { // we have a plan, hooray! mSelf.currentActions = plan; //mSelf.dataProvider.planFound(goal, plan); mSelf.ChangeState(new PerformAction()); } else { // ugh, we couldn't get a plan Debug.Log("<color=orange>Failed Plan:</color>" + (goal)); mSelf.dataProvider.planFailed(goal); } }