示例#1
0
        public static StateMachine <GOAPMinerState> BuildAI()
        {
            var goapMinerState = new GOAPMinerState();

            goapMinerState.Planner = new ActionPlanner();

            // setup our Actions and add them to the planner
            var sleep = new GOAPAction("sleep");

            sleep.SetPrecondition(IsFatigued, true);
            sleep.SetPostcondition(IsFatigued, false);
            goapMinerState.Planner.AddAction(sleep);

            var drink = new GOAPAction("drink");

            drink.SetPrecondition(IsThirsty, true);
            drink.SetPostcondition(IsThirsty, false);
            goapMinerState.Planner.AddAction(drink);

            var mine = new GOAPAction("mine");

            mine.SetPrecondition(HasEnoughGold, false);
            mine.SetPostcondition(HasEnoughGold, true);
            goapMinerState.Planner.AddAction(mine);

            var depositGold = new GOAPAction("depositGold");

            depositGold.SetPrecondition(HasEnoughGold, true);
            depositGold.SetPostcondition(HasEnoughGold, false);
            goapMinerState.Planner.AddAction(depositGold);

            var stateMachine = new StateMachine <GOAPMinerState>(goapMinerState, new Idle());

            stateMachine.AddState(new GoTo());
            stateMachine.AddState(new PerformAction());

            return(stateMachine);
        }