Esempio n. 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);
            }
        }
Esempio n. 2
0
        private IEnumerator Reset(GoapFsm fsm, GoapAgent agent)
        {
            _fsm.Pop();
            _fsm.Push(_idle);

            yield return(0);
        }
Esempio n. 3
0
        public GoapAgent(IGoapMoveHandle move)
        {
            _move = move;

            _fsm = new GoapFsm(this);

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

            _fsm.Push(_idle);
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
        private IEnumerator Walk(GoapFsm fsm, GoapAgent agent)
        {
            fsm.Pop();
            var action = _actions.Peek();

            _move.SetTarget(action.Target);

            while (_move.pathPending() && !agent.InterruptState)
            {
                yield return(0);
            }

            while (!_move.IsDone() && !agent.InterruptState)
            {
                _move.MoveUpdate();
                yield return(0);
            }

            _move.Stop();

            action.Enter();
        }