Ejemplo n.º 1
0
        public TaskState Process()
        {
            ISimpleTask currentTask = CurrentQueue.Dequeue();

            CurrentTask = currentTask;

            //if (currentTask is StateTaskList tasks)
            //	tasks.Stack = new TaskStack(_game);

            _game.Log(LogLevel.VERBOSE, BlockType.TRIGGER, "TaskQueue", !_game.Logging ? "" : $"LazyTask[{currentTask.Source}]: '{currentTask.GetType().Name}' is processed!" +
                      $"'{currentTask.Source.Card.Text?.Replace("\n", " ")}'");
            if (_game.History)
            {
                _game.PowerHistory.Add(PowerHistoryBuilder.BlockStart(currentTask.IsTrigger ? BlockType.TRIGGER : BlockType.POWER, currentTask.Source.Id, "", -1, currentTask.Target?.Id ?? 0));
            }

            TaskState success = currentTask.Process();

            if (_game.History)
            {
                _game.PowerHistory.Add(PowerHistoryBuilder.BlockEnd());
            }

            // reset between task execution
            //_game.TaskStack.Reset();

            CurrentTask = null;

            return(success);
        }
Ejemplo n.º 2
0
        // Advances the game state forward in time
        public bool Update(Func <ActionResult> inputAction)
        {
            if (inputAction == null && !Player.HasNextStep)
            {
                return(false);
            }

            var characters = CurrentFloor.Entities.OfType <Character>().ToArray();

            Ticks++;
            if (Ticks % RegenRate == 0)
            {
                foreach (var character in characters)
                {
                    character.Regenerate();
                }
            }

            Player.PendingAction = inputAction;
            Player.Update(this);
            NextQueue.Enqueue(Player, -Player.Sequence);

            if (CurrentQueue.Count == 0)
            {
                foreach (var character in CurrentFloor.Entities.OfType <Character>())
                {
                    CurrentQueue.Enqueue(character, -character.Sequence);
                }
            }

            while (CurrentQueue.Count != 0)
            {
                var current = CurrentQueue.Dequeue();

                if (current is Player)
                {
                    return(true);
                }

                var actionResult = current.Update(this);
                Log.LogActionResult(actionResult);
                NextQueue.Enqueue(current, -current.Sequence);
            }

            var tempQueue = CurrentQueue;

            CurrentQueue = NextQueue;
            NextQueue    = tempQueue;
            NextQueue.Clear();

            return(true);
        }
Ejemplo n.º 3
0
 /** Removes the element on top of the stack and returns that element. */
 public int Pop()
 {
     return(CurrentQueue.Dequeue());
 }