示例#1
0
        private IEnumerator DoAction(GoapFsm fsm, GoapAgent agent)
        {
            if (_actions.Count > 0)
            {
                var action = _actions.Peek();

                if (action.IsDone())
                {
                    agent.Effects.Add(action.EffectsAdd);
                    agent.Effects.Remove(action.EffectsRemove);
                    action.Exit();
                    fsm.Pop();
                    fsm.Push(_idle);
                    _actions.Dequeue();
                }
                else
                {
                    yield return(action.Update(agent));
                }
            }
            else
            {
                fsm.Pop();
                fsm.Push(_idle);
            }
        }
示例#2
0
        private IEnumerator Reset(GoapFsm fsm, GoapAgent agent)
        {
            _fsm.Pop();
            _fsm.Push(_idle);

            yield return(0);
        }
示例#3
0
        private IEnumerator Idle(GoapFsm fsm, GoapAgent agent)
        {
            if (_actions.Count > 0)
            {
                fsm.Pop();

                var action = _actions.Peek();

                if (CurrentAction != action)
                {
                    CurrentAction = action;
                    GoalActionChanged?.Invoke();
                }

                yield return(action.CheckInRange(agent));

                if (action.InRange)
                {
                    action.Enter();
                    fsm.Push(_doAction);
                }
                else
                {
                    fsm.Push(_doAction);
                    fsm.Push(_walk);
                }
            }
            else
            {
                if (!_manualMode)
                {
                    yield return(Planer(agent));
                }
                else
                {
                    if (CurrentAction != null)
                    {
                        CurrentAction = null;
                        GoalActionChanged?.Invoke();
                    }

                    yield return(0);
                }
            }
        }
示例#4
0
        public GoapAgent(IGoapMoveHandle move)
        {
            _move = move;

            _fsm = new GoapFsm(this);

            _reset    = Reset;
            _idle     = Idle;
            _walk     = Walk;
            _doAction = DoAction;

            _fsm.Push(_idle);
        }