private void createPerformActionState() { performActionState = (fsm, gameObj) => { // Perform the action if (!hasActionPlan()) { // No actions to perform fsm.popState(); fsm.pushState(idleState); dataProvider.actionsFinished(); return; } GOAPAction action = currentActions.Peek(); if (action.isDone()) { // The action is done. We can remove it, onto the next one! currentActions.Dequeue(); } if (hasActionPlan()) { // Perform the next action action = currentActions.Peek(); bool inRange = action.requiresInRange() ? action.isInRange() : true; if (inRange) { // We're in range, so perform the action bool success = action.perform(gameObj); if (!success) { // Action failed, we need to plan again fsm.popState(); fsm.pushState(idleState); dataProvider.planAborted(action); } } else { // We need to move to our target first // Let's make the AI move fsm.pushState(moveToTargetState); } } // If all fails, change back to idleState (planning stage) else { fsm.popState(); fsm.pushState(idleState); dataProvider.actionsFinished(); } }; }
private void createPerformActionState() { performActionState = (fsm, obj) => { if (!hasActionPlan()) { fsm.popState(); fsm.pushState(idleState); dataProvider.actionsFinished(); return; } GOAPAction action = currentActions.Peek(); if (action.IsDone()) { currentActions.Dequeue(); } if (hasActionPlan()) { action = currentActions.Peek(); bool inRange = action.RequiresInRange() ? action.isInRange() : true; if (inRange) { bool success = action.Perform(obj); if (!success) { fsm.popState(); fsm.pushState(idleState); createIdleState(); dataProvider.planAborted(action); } } else { fsm.pushState(moveToState); } } else { fsm.popState(); fsm.pushState(idleState); dataProvider.actionsFinished(); } }; }