Exemple #1
0
        public TaskState Process()
        {
            CurrentTask = TaskList.OrderBy(p => p.Source.OrderOfPlay).First();
            TaskList.Remove(CurrentTask);
            Game.Log(LogLevel.VERBOSE, BlockType.TRIGGER, "TaskQueue", $"LazyTask[{CurrentTask.Source}]: '{CurrentTask.GetType().Name}' is processed!" +
                     $"'{CurrentTask.Source.Card.Text?.Replace("\n", " ")}'");


            // power block
            if (Game.History)
            {
                Game.PowerHistory.Add(PowerHistoryBuilder.BlockStart(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();

            //if (Game.Splits.Count == 0 && CurrentTask.Splits != null && CurrentTask.Splits.Count > 0)
            //{
            //    Log.Info($"Parallel-threading splits '{CurrentTask.Splits.Count}' starting now! [Info: {Game.Splits.Count}]");
            //    Game.Splits = CurrentTask.Splits;
            //}
            return(success);
        }
Exemple #2
0
        public void Execute(ISimpleTask task, Controller controller, IPlayable source, IPlayable target)
        {
            ISimpleTask clone = task.Clone();

            clone.Game       = controller.Game;
            clone.Controller = controller;
            clone.Source     = source;
            clone.Target     = target;
            Game.Log(LogLevel.VERBOSE, BlockType.TRIGGER, "TaskQueue", $"PriorityTask[{clone.Source}]: '{clone.GetType().Name}' is processed!" +
                     $"'{clone.Source.Card.Text?.Replace("\n", " ")}'");

            // power block
            if (controller.Game.History)
            {
                controller.Game.PowerHistory.Add(PowerHistoryBuilder.BlockStart(BlockType.POWER, source.Id, "", -1, target?.Id ?? 0));
            }

            clone.Process();

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

            Game.TaskStack.Reset();
        }
        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);
        }
Exemple #4
0
        public static IPlayable Draw(Controller c, int index)
        {
            IPlayable playable = c.DeckZone.Remove(index);

            c.Game.Log(LogLevel.INFO, BlockType.ACTION, "DrawPhase", !c.Game.Logging ? "" : $"{c.Name} draws {playable}");

            c.NumCardsDrawnThisTurn++;
            c.NumCardsDrawnThisGame++;
            c.LastCardDrawn = playable.Id;

            if (AddHandPhase.Invoke(c, playable))
            {
                // DrawTrigger vs TOPDECK ?? not sure which one is first

                Game game = c.Game;

                game.TaskQueue.StartEvent();
                game.TriggerManager.OnDrawTrigger(playable);
                game.ProcessTasks();
                game.TaskQueue.EndEvent();

                ISimpleTask task = playable.Power?.TopDeckTask;
                if (task != null)
                {
                    if (game.History)
                    {
                        // TODO: triggerkeyword: TOPDECK
                        game.PowerHistory.Add(
                            PowerHistoryBuilder.BlockStart(BlockType.TRIGGER, playable.Id, "", 0, 0));
                    }

                    c.SetasideZone.Add(c.HandZone.Remove(playable));

                    game.Log(LogLevel.INFO, BlockType.TRIGGER, "TOPDECK",
                             !game.Logging ? "" : $"{playable}'s TOPDECK effect is activated.");

                    task.Process(game, c, playable, null);

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

            c.DeckZone.ResetPositions();

            return(playable);
        }
Exemple #5
0
        public TaskState Process()
        {
            // at the start move over initial parameters ...
            if (State == TaskState.READY)
            {
                Playables = Playables ?? new List <IPlayable>();
                CardIds   = CardIds ?? new List <string>();
            }

            State = TaskState.RUNNING;
            for (_position = 0; _position < Count && State == TaskState.RUNNING; _position++)
            {
                ISimpleTask task = this[_position];
                if (task.State == TaskState.COMPLETE)
                {
                    continue;
                }

                task.Game       = Game;
                task.Controller = Controller;
                task.Source     = Source;
                task.Target     = Target;
                //task.Playables = Playables;
                //task.Flag = Flag;
                //task.Number = Number;

                // execution
                if (task.Process() != TaskState.COMPLETE)
                {
                    break;
                }

                // move over in queue
                Game       = task.Game;
                Controller = task.Controller;
                Source     = task.Source;
                Target     = task.Target;
                //Playables = task.Playables;
                //Flag = task.Flag;
                //Number = task.Number;
            }

            return(TaskState.COMPLETE);
        }