private void CreateMoveToState(GOAPComponent aic) { aic.moveToState = (fsm, gameObject) => { //aic.AnnounceMoveToState(); GOAPAction action = aic.currentActions.Peek(); if (action.requiresInRange() && action.target == null) { fsm.popState(); fsm.popState(); fsm.pushState(aic.idleState); return; } if (aic.IsAgentInRange(action)) { fsm.popState(); } else { if (aic.IsActionInterrupted(action)) { fsm.popState(); fsm.pushState(aic.idleState); } aic.gameObject.GetComponent <NavMeshAgent>()?.SetDestination(action.target.transform.position); } }; }
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(GOAPComponent aic) { aic.performActionState = (fsm, obj) => { //aic.AnnouncePerformActionState(); if (!aic.HasActionPlan()) { fsm.popState(); fsm.pushState(aic.idleState); aic.ActionsFinished(); return; } GOAPAction action = aic.currentActions.Peek(); if (action.isDone()) { aic.currentActions.Dequeue(); } if (aic.HasActionPlan()) { action = aic.currentActions.Peek(); bool inRange = action.requiresInRange() ? action.isInRange() : true; if (inRange) { bool success = action.perform(obj); if (!success) { fsm.popState(); fsm.pushState(aic.idleState); CreateIdleState(aic); aic.PlanAborted(action); } } else { fsm.pushState(aic.moveToState); } } else { fsm.popState(); fsm.pushState(aic.idleState); aic.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(); } }; }
private void createMoveToState() { moveToState = (fsm, gameObject) => { GOAPAction action = currentActions.Peek(); if (action.requiresInRange() && action.target == null) { fsm.popState(); fsm.popState(); fsm.pushState(idleState); return; } if (dataProvider.IsAgentInRange(action)) { fsm.popState(); } }; }
private void createMoveToTargetState() { moveToTargetState = (fsm, gameObj) => { // Moves AI towards target GOAPAction action = currentActions.Peek(); // Action requires a target but has none. Go back to planning stage if (action.requiresInRange() && action.rTarget == null) { fsm.popState(); // Clear moveToTargetState fsm.popState(); // Clear performActionState fsm.pushState(idleState); return; } // If the moveAgent variable becomes true (which tells us if the AI reached the target), clear moveToTargetState if (dataProvider.moveAgent(action)) { fsm.popState(); } }; }