Ejemplo n.º 1
0
 private DiscoverTask(DiscoverType type, Card enchantmentCard, ISimpleTask afterDiscoverTask, int number)
 {
     _discoverType    = type;
     _enchantmentCard = enchantmentCard;
     _taskTodo        = afterDiscoverTask;
     _numberOfChoices = number;
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            Console.WriteLine("Copy new versions into the Plugins folder, and the output below should change. Press [enter] to exit");

            IPluginWatcher <ISimpleTask> watcher = new PluginWatcher <ISimpleTask>("./Plugins");

            watcher.PluginsChanged += watcher_PluginsChanged;

            current = Latest(watcher.CurrentlyAvailable);

            Console.WriteLine("\r\nInitial startup\r\nLatest version:");
            Console.WriteLine(current.Version());

            // Here we set some state that should be maintained between versions
            current.SetGreets("Hello");

            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(200);
                    lock (VersionLock)
                    {
                        Console.SetCursorPosition(0, 8);
                        Console.WriteLine(current.Greeting("world"));
                    }
                }
            }while (Console.ReadKey().Key != ConsoleKey.Enter);
        }
Ejemplo n.º 4
0
 public RevealTask(ISimpleTask successJoustTask, ISimpleTask failedJoustTask = null,
                   CardType type = CardType.MINION)
 {
     _successJoustTask = successJoustTask;
     _failedJoustTask  = failedJoustTask;
     _type             = type;
 }
Ejemplo n.º 5
0
        public override TaskState Process()
        {
            int times = SpellDmg ? Amount + Controller.Hero.SpellPowerDamage : Amount;

            for (int i = 0; i < times; i++)
            {
                // clone task here
                ISimpleTask clone = Task.Clone();
                clone.ResetState();
                clone.Game       = Controller.Game;
                clone.Controller = Controller;
                clone.Source     = Source as IPlayable;
                clone.Target     = Target as IPlayable;

                Controller.Game.TaskQueue.Enqueue(clone);
                Controller.Game.TaskQueue.Enqueue(
                    new ClearStackTask
                {
                    Game       = Controller.Game,
                    Controller = Controller,
                    Source     = Source as IPlayable,
                    Target     = Target as IPlayable
                });
            }
            return(TaskState.COMPLETE);
        }
Ejemplo n.º 6
0
        public void EnqueueBase(ISimpleTask task)
        {
            _baseQueue.Enqueue(task);

            _game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "TaskQueue",
                      !_game.Logging ? "" : $"{task.GetType().Name} is Enqueued in 0th stack");
        }
Ejemplo n.º 7
0
        public void ActivateTask(PowerActivation activation = PowerActivation.POWER, IPlayable target = null, int chooseOne = 0, IPlayable source = null)
        {
            if (ChooseOne)
            {
                if (Controller.ChooseBoth &&
                    !Card.Id.Equals("EX1_165") &&                       // OG_044a, using choose one 0 option
                    !Card.Id.Equals("BRM_010") &&                       // OG_044b, using choose one 0 option
                    !Card.Id.Equals("AT_042") &&                        // OG_044c, using choose one 0 option
                    !Card.Id.Equals("UNG_101") &&                       // UNG_101t3
                    !Card.Id.Equals("ICC_051") &&                       // ICC_051t3
                    !Card.Id.Equals("ICC_047"))                         // using choose one 0 option
                {
                    ChooseOnePlayables[0].ActivateTask(activation, target, chooseOne, this);
                    ChooseOnePlayables[1].ActivateTask(activation, target, chooseOne, this);
                    return;
                }

                if (!Controller.ChooseBoth && chooseOne > 0)
                {
                    ChooseOnePlayables[chooseOne - 1].ActivateTask(activation, target, chooseOne, this);
                    return;
                }
            }

            if (Power == null)
            {
                return;
            }

            ISimpleTask task = null;

            switch (activation)
            {
            case PowerActivation.POWER:
                task = Power.PowerTask;
                break;

            case PowerActivation.DEATHRATTLE:
                task = Power.DeathrattleTask;
                break;

            case PowerActivation.COMBO:
                task = Power.ComboTask;
                break;
            }
            if (task == null)
            {
                return;
            }

            // clone task here
            ISimpleTask clone = task.Clone();

            clone.Game       = source?.Game ?? Game;
            clone.Controller = source?.Controller ?? Controller;
            clone.Source     = source ?? this;
            clone.Target     = target;

            clone.Game.TaskQueue.Enqueue(clone);
        }
Ejemplo n.º 8
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.º 9
0
        private void ProcessInternal(IEntity source)
        {
            Validated = false;

            Game.Log(LogLevel.INFO, BlockType.TRIGGER, "Trigger",
                     !Game.Logging ? "" : $"{_owner}'s {_triggerType} Trigger is triggered by {source}.");

            if (RemoveAfterTriggered)
            {
                Remove();
            }

            if (FastExecution)
            {
                Game.TaskQueue.Execute(SingleTask, _owner.Controller, _owner,
                                       source is IPlayable ? (IPlayable)source
                                                                                : _owner is Enchantment ew && ew.Target is IPlayable p ? p
                                                                                : null);
            }
            else
            {
                ISimpleTask taskInstance = SingleTask.Clone();
                taskInstance.Game       = Game;
                taskInstance.Controller = _owner.Controller;
                taskInstance.Source     = _owner is Enchantment ec ? ec : _owner;
                taskInstance.Target     = source is IPlayable ? source : _owner is Enchantment ew && ew.Target is IPlayable p ? p : null;
                taskInstance.IsTrigger  = true;

                Game.TaskQueue.Enqueue(taskInstance);
            }

            Validated = false;
        }
Ejemplo n.º 10
0
        public override TaskState Process()
        {
            if (Number < 1)
            {
                return(TaskState.STOP);
            }

            int times = SpellDmg ? Number + Controller.CurrentSpellPower : Number;

            for (int i = 0; i < times; i++)
            {
                // clone task here
                ISimpleTask clone = Task.Clone();
                clone.Game       = Controller.Game;
                clone.Controller = Controller;
                clone.Source     = Source as IPlayable;
                clone.Target     = Target as IPlayable;

                Controller.Game.TaskQueue.Enqueue(clone);
                //Controller.Game.TaskQueue.EnqueueBase(
                //	new ClearStackTask
                //	{
                //		Game = Controller.Game,
                //		Controller = Controller,
                //		Source = Source as IPlayable,
                //		Target = Target as IPlayable
                //	});
            }
            return(TaskState.COMPLETE);
        }
Ejemplo n.º 11
0
        public void Copy(ISimpleTask task)
        {
            State = task.State;

            if (task.Game == null)
            {
                return;
            }

            Game       = task.Game;
            Controller = task.Controller;
            Source     = task.Source;
            Target     = task.Target;

            Playables = task.Playables;
            CardIds   = task.CardIds;
            Flag      = task.Flag;
            Number    = task.Number;
            Number1   = task.Number1;
            Number2   = task.Number2;
            Number3   = task.Number3;
            Number4   = task.Number4;

            //Splits = task.Splits;
            //Sets = task.Sets;
        }
Ejemplo n.º 12
0
        internal int GetAmount <T>(ISimpleTask simpleTask, Controller c = null)
        {
            var stateTaskList = simpleTask as StateTaskList;

            if (stateTaskList.TaskList.Any(t => t is T))
            {
                if (typeof(T) == typeof(DiscardTask))
                {
                    var discardTask = (DiscardTask)stateTaskList.TaskList.Where(t => t is DiscardTask).ToList()[0];

                    if (stateTaskList.TaskList.Any(t => t is RandomTask))
                    {
                        return(_function(stateTaskList.TaskList.Where(t => t is RandomTask).ToList()[0]));
                    }

                    else if (discardTask.Type == EntityType.STACK)
                    {
                        return(1);
                    }

                    else if (discardTask.Type == EntityType.HAND && c != null)
                    {
                        return(c.HandZone.Count);
                    }
                }

                return(_function(stateTaskList.TaskList.Where(t => t is T).ToList()[0]));
            }
            return(0);
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        static void Main()
        {
            Console.WriteLine("Copy new versions into the Plugins folder, and the output below should change. Press [enter] to exit");

            IPluginWatcher<ISimpleTask> watcher = new PluginWatcher<ISimpleTask>("./Plugins");
            watcher.PluginsChanged += watcher_PluginsChanged;

            current = Latest(watcher.CurrentlyAvailable);

            Console.WriteLine("\r\nInitial startup\r\nLatest version:");
            Console.WriteLine(current.Version());

            // Here we set some state that should be maintained between versions
            current.SetGreets("Hello");

            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(200);
                    lock (VersionLock)
                    {
                        Console.SetCursorPosition(0, 8);
                        Console.WriteLine(current.Greeting("world"));
                    }
                }
            }
            while (Console.ReadKey().Key != ConsoleKey.Enter);
        }
Ejemplo n.º 15
0
 public static Trigger Inspire(ISimpleTask task)
 {
     return(new TriggerBuilder().Create()
            .EnableConditions(SelfCondition.IsInZone(Zone.PLAY), SelfCondition.IsNotSilenced)
            .TriggerEffect(GameTag.HEROPOWER_ACTIVATIONS_THIS_TURN, 1)
            .SingleTask(task)
            .Build());
 }
Ejemplo n.º 16
0
 public ComputedTask(ISimpleTask simpleTask)
     : base(simpleTask)
 {
     this.Command  = simpleTask.Pattern.Shift();
     this.Name     = simpleTask.GetName();
     this.Examples = simpleTask.GetExamples();
     this.Compute();
 }
Ejemplo n.º 17
0
        public void Change(Entity entity, GameTag gameTag, int oldValue, int newValue)
        {
            var target = entity as IPlayable;

            //Game.Log(LogLevel.INFO, BlockType.TRIGGER, "Trigger", $"{entity} {gameTag} {oldValue} {newValue}");

            if (!Effects.ContainsKey(gameTag))
            {
                Game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Trigger", $"GameTag {gameTag} not concerned by this enchanting(change) ...");
                return;
            }

            if (!IsEnabled())
            {
                Game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Trigger", "Trigger isn't enabled!");
                return;
            }

            if (!IsApplying(target))
            {
                Game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Trigger", $"Trigger conditions not meet.");
                Game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Trigger", $"Owner: {Owner}, Target: {target}");
                return;
            }

            if (Effects[gameTag] > 0 && oldValue >= newValue ||
                Effects[gameTag] < 0 && oldValue <= newValue)
            {
                Game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Trigger", $"Enchant(change) on {gameTag} conditions not meet positiv or negativ. {Effects[gameTag]} && {oldValue} == {newValue}");
                return;
            }

            // do a clone of the task
            ISimpleTask clone = SingleTask.Clone();

            clone.Game       = Owner.Controller.Game;
            clone.Controller = Owner.Controller;
            clone.Source     = Owner;
            clone.Target     = target;
            // let the change move into the task
            clone.Number = newValue - oldValue;

            if (FastExecution)
            {
                Owner.Controller.Game.TaskQueue.Execute(SingleTask, Owner.Controller, Owner, target);
            }
            else
            {
                Owner.Controller.Game.TaskQueue.Enqueue(clone);
            }

            Executions++;

            if (MaxExecutions != 0 && Executions >= MaxExecutions)
            {
                Remove();
            }
        }
Ejemplo n.º 18
0
 public static ISimpleTask Repeat(ISimpleTask task, int times)
 {
     ISimpleTask[] list = new ISimpleTask[times];
     for (int i = 0; i < times; i++)
     {
         list[i] = task;
     }
     return(Create(list));
 }
Ejemplo n.º 19
0
        public static ISimpleTask Create(ISimpleTask task, int times)
        {
            var list = new ISimpleTask[times];

            for (var i = 0; i < times; i++)
            {
                list[i] = task;
            }
            return(Create(list));
        }
Ejemplo n.º 20
0
 public static Trigger FriendlySpellTargetingMe(ISimpleTask task)
 {
     return(new TriggerBuilder().Create()
            .EnableConditions(SelfCondition.IsInZone(Zone.PLAY), SelfCondition.IsNotSilenced)
            .ApplyConditions(RelaCondition.IsOther(SelfCondition.IsSpell), RelaCondition.IsTargetingMe, RelaCondition.IsFriendly)
            .FastExecution(true)
            .TriggerEffect(GameTag.JUST_PLAYED, 1)
            .SingleTask(task)
            .Build());
 }
Ejemplo n.º 21
0
        private StateTaskList(ISimpleTask[] list)
        {
            var tasks = new ISimpleTask[list.Length];

            for (int i = 0; i < list.Length; ++i)
            {
                tasks[i] = list[i].Clone();
            }

            _tasks = tasks;
        }
Ejemplo n.º 22
0
        public static string GetName(this ISimpleTask simpleTask)
        {
            var type      = simpleTask.GetType();
            var attribute = type.GetCustomAttributes(false).OfType <TaskNameAttribute>().FirstOrDefault();

            if (attribute != null)
            {
                return(attribute.Name);
            }
            return(type.Name);
        }
Ejemplo n.º 23
0
        public static IEnumerable <string> GetExamples(this ISimpleTask simpleTask)
        {
            var type       = simpleTask.GetType();
            var attributes = type.GetCustomAttributes(false).OfType <TaskExampleAttribute>();

            if (attributes.Any())
            {
                return(attributes.Select(a => a.Example));
            }
            return(null);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Enqueue tasks that will be proccess by the DeathAndAuraProcessing.
        /// IMPORTANT: only enqueue cloned tasks ....
        /// </summary>
        /// <param name="task"></param>
        public void Enqueue(ISimpleTask task)
        {
            // TODO ... check if necessary ... frothing beserker ... check for duplicates, ex. auras
            //if (_lazyTaskQueue.Contains(task))
            //    return;

            // TODO reset task from previous uses .. maybee need to clone it?
            //task.Reset();

            TaskList.Add(task);
        }
Ejemplo n.º 25
0
        public static void ValidateTask(ISimpleTask simpleTask)
        {
            if (string.IsNullOrEmpty(simpleTask.Pattern))
            {
                throw new InvalidTaskDefinitionException("Task pattern cannot be null or empty");
            }

            if (simpleTask.Stuff == null)
            {
                throw new InvalidTaskDefinitionException("Action to be performed on invoke cannot be null");
            }
        }
Ejemplo n.º 26
0
        public void Enqueue(ISimpleTask task)
        {
            if (_standbyEvent != null)
            {
                _eventStack.Push(_standbyEvent.Value);
                _standbyEvent = null;
                _eventCreated = true;
            }

            CurrentQueue.Enqueue(task);

            _game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "TaskQueue",
                      !_game.Logging ? "" : $"{task.GetType().Name} is Enqueued in {_eventStack.Count}th stack");
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
 public void Stamp(TaskQueue taskQueue)
 {
     TaskList = new List <ISimpleTask>();
     taskQueue.TaskList.ForEach(p => TaskList.Add(p.Clone()));
     if (taskQueue.CurrentTask != null)
     {
         CurrentTask      = taskQueue.CurrentTask.Clone();
         CurrentTask.Game = Game;
     }
     TaskList.ForEach(p =>
     {
         p.Game = Game;
         //p.Reset();
     });
 }
Ejemplo n.º 29
0
        internal static bool ControllerNeeded <T>(ISimpleTask simpleTask)
        {
            var stateTaskList = simpleTask as StateTaskList;

            if (stateTaskList.TaskList.Any(t => t is T))
            {
                if (typeof(T) == typeof(DiscardTask))
                {
                    var discardTask = (DiscardTask)stateTaskList.TaskList.Where(t => t is DiscardTask).ToList()[0];
                    return(discardTask.Type == EntityType.HAND);
                }
            }

            return(false);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Do a version upgrade!
 /// </summary>
 static void Upgrade(IHotSwap old, ISimpleTask latest)
 {
     lock (VersionLock)
     {
         try
         {
             latest.SetState(old.GetState());
             current = latest;
         }
         catch (Exception ex)
         {
             Console.WriteLine("Can't upgrade: " + ex.Message);
         }
     }
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Do a version upgrade!
 /// </summary>
 static void Upgrade(IHotSwap old, ISimpleTask latest)
 {
     lock (VersionLock)
     {
         try
         {
             latest.SetState(old.GetState());
             current = latest;
         }
         catch (Exception ex)
         {
             Console.WriteLine("Can't upgrade: " + ex.Message);
         }
     }
 }
Ejemplo n.º 32
0
 public static ISimpleTask RecursiveTask(ConditionTask repeatCondition, params ISimpleTask[] tasks)
 {
     ISimpleTask[] taskList = new ISimpleTask[tasks.Length + 2];
     tasks.CopyTo(taskList, 0);
     taskList[tasks.Length]     = repeatCondition;
     taskList[tasks.Length + 1] =
         new FlagTask(true,
                      new FuncNumberTask(p =>
     {
         p.ActivateTask(PowerActivation.POWER);
         return(0);
     }
                                         ));
     return(StateTaskList.Chain(taskList));
 }