Пример #1
0
    private void CreateIdleState()
    {
        idleState = (fsm, gameObj) =>
        {
            // GOAP planning

            // get the world state and the goal we want to plan for
            Dictionary <string, object>   worldState = dataProvider.GetWorldState();
            KeyValuePair <string, object> goal       = dataProvider.GetCurrentGoal();

            // search enable Plan
            Queue <GoapAction> plan = planner.Plan(gameObject, availableActions, worldState, goal, dataProvider);

            if (plan != null)
            {
                // we have a plan, hooray!
                currentActions = plan;
                dataProvider.PlanFound(goal, plan);

                fsm.PopState();  // move to PerformAction state
                fsm.PushState(performActionState);
            }
            else
            {
                // ugh, we couldn't get a plan
                Debug.Log("[" + this.name + "] " + "<color=orange>Plan failed:</color> " + PrettyPrint(goal) + " = NO PLAN");
                dataProvider.PlanFailed(goal);
                fsm.PopState();  // move back to IdleAction state
                fsm.PushState(idleState);
            }
        };
    }