void addAction(GOAP.Action action) { if (actions.Contains(action)) { return; } actions.Add(action); if (currentState != null) { currentState.remainingActions.Add(action); } }
void Act() { if (m_currentActionSet != null && m_currentActionSet.Count > 0) { GOAP.Action action = m_currentActionSet.Peek() as GOAP.Action; if (action.TickAction()) { m_currentActionSet.Pop(); //Action complete, take off stack. } } else { m_spiderAnimation.CrossFade(ANIMATION_IDLE); } }
private void CreateMoveToState() { moveToState = (fsm, gameObj) => { GOAP.Action action = currentActions.Peek(); if (action.RequiresInRange() && action.target == null) { Debug.Log("<color=red>Fatal error:</color> Action requires a target but has none. Planning failed. You did not assign the target in your Action.checkProceduralPrecondition()"); fsm.PopState(); fsm.PopState(); fsm.PushState(idleState); return; } if (dataProvider.MoveAgent(action)) { fsm.PopState(); } }; }
private void OnDrawGizmos() { if (Gizmo.IsPlaying) { if (currentActions == null || currentActions.Count == 0) { return; } GOAP.Action current = currentActions.Peek(); bool selected = false; GameObject target = current.target; if (target == null) { target = gameObject; } switch (Gizmo.show) { case Gizmo.Filter.Agent: selected = Gizmo.SelectedInHierachy == gameObject; break; case Gizmo.Filter.Action: selected = target.gameObject == Gizmo.SelectedInHierachy; break; case Gizmo.Filter.All: selected = true; break; } if (selected) { Gizmo.DrawLine(target.transform.position, transform.position, Color.yellow); Gizmo.DrawCircle(target.transform.position, 16, current.minExecDist / 1.5f, Color.yellow); Gizmo.DrawText(transform.position, current.GetType().Name); } } }
private void CreatePerformActionState() { performActionState = (fsm, gameObj) => { // perform the action GOAP.Action action = currentActions.Peek(); if (action.IsDone()) { currentActions.Dequeue(); } if (!HasActionPlan()) { // no actions to perform Debug.Log("<color=red>Done actions</color>"); fsm.PopState(); fsm.PushState(idleState); dataProvider.ActionsFinished(action); return; } else { action = currentActions.Peek(); bool inRange = action.RequiresInRange() ? action.inRange : true; if (inRange) { bool success = action.Perform(gameObj); // If action fails, abort plan if (!success) { OverridePlan(); dataProvider.PlanAborted(action); } } else { fsm.PushState(moveToState); } } }; }
public void RemoveAction(GOAP.Action action) { _ = availableActions.Remove(action); }
public void AddAction(GOAP.Action action) { _ = availableActions.Add(action); }
public static string ToString(GOAP.Action action) { String s = "" + action.GetType().Name; return(s); }
public void createAction(string id, Dictionary <string, bool> preconditions, Dictionary <string, bool> effects) { GOAP.Action action = new GOAP.Action(id, preconditions, effects); addAction(action); }