Пример #1
0
        void addAction(GOAP.Action action)
        {
            if (actions.Contains(action))
            {
                return;
            }

            actions.Add(action);

            if (currentState != null)
            {
                currentState.remainingActions.Add(action);
            }
        }
Пример #2
0
    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);
        }
    }
Пример #3
0
    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();
            }
        };
    }
Пример #4
0
    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);
            }
        }
    }
Пример #5
0
    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);
                }
            }
        };
    }
Пример #6
0
 public void RemoveAction(GOAP.Action action)
 {
     _ = availableActions.Remove(action);
 }
Пример #7
0
 public void AddAction(GOAP.Action action)
 {
     _ = availableActions.Add(action);
 }
Пример #8
0
    public static string ToString(GOAP.Action action)
    {
        String s = "" + action.GetType().Name;

        return(s);
    }
Пример #9
0
 public void createAction(string id, Dictionary <string, bool> preconditions, Dictionary <string, bool> effects)
 {
     GOAP.Action action = new GOAP.Action(id, preconditions, effects);
     addAction(action);
 }