Exemple #1
0
        public void Tick(TContext context)
        {
            if (!_locked)
            {
                var nextAction = _queuedActions.PeekMax().Item;

                if (!nextAction.Equals(CurrentAction))
                {
                    CurrentAction?.OnFinish(context);
                    CurrentAction = nextAction;
                    CurrentAction?.OnEnter(context);
                }
            }

            if (CurrentAction is null)
            {
                return;
            }

            var result = CurrentAction.OnTick(context);

            switch (result)
            {
            case ActionResult.Yield:
                _locked = false;
                break;

            case ActionResult.Reconsider:
                _locked = false;
                Consider(CurrentAction.Strategy, context);
                break;

            case ActionResult.Continue:
                _locked = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }