示例#1
0
        public GoapMiner()
        {
            // we need an ActionPlanner before we can do anything
            _planner = new ActionPlanner();

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

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

            var drink = new Action("drink");

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

            var mine = new Action("mine");

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

            var depositGold = new Action("depositGold");

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

            // set our state machine to idle. When it is in idle it will ask the ActionPlanner for a new plan
            InitialState = MinerBobState.Idle;
        }
示例#2
0
文件: UDog.cs 项目: jasonboninger/dog
        private void _InitializeActions()
        {
            // Set default action
            _actionDefault = new Idle();
            // Get movement actions
            var actionsMovement = _actionsMovementContainer.GetComponentsInChildren <UDogActionMovement>();

            // Run through movement actions
            for (int i = 0; i < actionsMovement.Length; i++)
            {
                var actionMovement = actionsMovement[i];
                // Initialize movement action
                actionMovement.Initialize(_controls);
            }
            // Get actions
            var actions = _actionsContainer.GetComponentsInChildren <UDogActionStandard>();

            // Add and initialize actions
            for (int i = 0; i < actions.Length; i++)
            {
                var action = actions[i];
                // Get global
                var global = action.Global;
                // Get type
                var type = action.GetType();
                // Initialize action
                action.Initialize(_controls);
                // Check if global
                if (global)
                {
                    // Add global standard action
                    _actionPlanner.AddAction(action);
                }
                else
                {
                    // Add standard action
                    _actionsStandard.Add(type, action);
                }
                // Check if destination action
                if (action is IDogActionDestination actionDestination)
                {
                    // Create movement action
                    var actionMovement = new Move(action.gameObject, actionsMovement, actionDestination);
                    // Check if global
                    if (global)
                    {
                        // Add global movement action
                        _actionPlanner.AddAction(actionMovement);
                    }
                    else
                    {
                        // Add movement action
                        _actionsMovement.Add(type, actionMovement);
                    }
                }
            }
        }
示例#3
0
文件: Move.cs 项目: jasonboninger/dog
 public Move(GameObject gameObject, IReadOnlyList <IDogActionMovement> actionsMovement, IDogActionDestination actionDestination)
 {
     // Set action planner
     _actionPlanner = new ActionPlanner <Dog, IDogActionMovement>();
     // Set action state machine
     _actionStateMachine = new ActionStateMachine <Dog, IDogActionMovement, float>();
     // Run through movement actions
     for (int i = 0; i < actionsMovement.Count; i++)
     {
         // Create movement action
         var actionMovement = actionsMovement[i].Create(gameObject, actionDestination);
         // Add movement action
         _actionPlanner.AddAction(actionMovement);
     }
     // Set destination action
     _actionDestination = actionDestination;
     // Get plan
     _plan = _actionPlanner.GetPlan();
     // Set plan
     _actionPlanner.PopulatePlan(_plan, _actionPlanner.Actions[0]);
 }