コード例 #1
0
    public override void DoEffect(Tile t)
    {
        selectedCardIds.Clear();
        cardsToShuffleBack.Clear();
        gemsNeededToShuffleBack = CARDS_TO_SHUFFLE_BACK;

        List <Card> pickableCards = card.Owner.Hand.GetAllCardsWithTag(Tag.Gem);

        CompoundQueueableCommand.Builder cmdBuilder = new CompoundQueueableCommand.Builder();
        for (int i = 0; i < CARDS_TO_SHUFFLE_BACK; i++)
        {
            IQueueableCommand cmd = CardPicker.CreateCommand(pickableCards, 1, 1, "Select a gem to shuffle back. " + gemsNeededToShuffleBack + " remaining", card.Owner, delegate(List <Card> cardList)
            {
                pickableCards.RemoveAll(c => c.CardId == cardList[0].CardId); // remove already selected cards
                cardsToShuffleBack.Add(cardList[0]);
                gemsNeededToShuffleBack--;
            });
            cmdBuilder.AddCommand(cmd);
        }
        cmdBuilder.AddCommand(SingleTileTargetEffect.CreateCommand(Board.Instance.GetAllTilesWithCreatures(card.Owner.OppositePlayer, false), delegate(Tile targetTile)
        {
            foreach (Card c in cardsToShuffleBack)
            {
                c.MoveToCardPile(card.Owner.Deck, card);
            }
            card.Owner.Deck.Shuffle();
            targetTile.Creature.TakeDamage(DAMAGE, card);
            card.Owner.DrawCards(CARDS_DRAWN);
        }));
        cmdBuilder.BuildAndQueue();
    }
コード例 #2
0
        public async Task <bool> HandleRecievedItemAsync <TCommand, TResult>(QueueItem <TCommand> item, int maxDequeueCount) where TCommand : class, ICommand <TResult>
        {
            try
            {
                _logger.LogInfo($"Recieved command {item.GetType().Name} from queue");
                bool shouldDequeue = true;
                IQueueableCommand queueableCommand = item.Item as IQueueableCommand;
                if (queueableCommand != null)
                {
                    queueableCommand.DequeueCount = item.DequeueCount;
                }
                Task commandTask = _commandExecuter.ExecuteAsync(item.Item);
                while (!commandTask.Wait(TimeSpan.FromSeconds(10)))
                {
                    await item.ExtendLeaseAsync();
                }

                if (queueableCommand != null)
                {
                    shouldDequeue = queueableCommand.ShouldDequeue;
                }
                _logger.LogInfo($"Completed processing command {item.GetType().Name} and returning a shouldDequeue status of {shouldDequeue}");
                return(shouldDequeue);
            }
            catch (Exception ex)
            {
                if (item.DequeueCount > maxDequeueCount)
                {
                    _logger.LogError($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will not try again.", item.Item, ex);
                    return(true);
                }
                _logger.LogWarning($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will try again.", item.Item, ex);
                return(false);
            }
        }
コード例 #3
0
 private void ProcessCommands()
 {
     if (currentAnimation != null && !currentAnimation.IsFinished) // command is in progress
     {
         return;
     }
     if (currentAnimation != null && currentAnimation.IsFinished) // command finishes
     {
         currentAnimation = null;
         if (NetInterface.Get().localPlayer != null)
         {
             NetInterface.Get().localPlayer.RemoveLock(playingAnimationsLock);
         }
     }
     if (animationQueue.Count == 0) // command is finished but there is no new command
     {
         return;
     }
     currentAnimation = animationQueue.Dequeue(); // start new command
     if (NetInterface.Get().localPlayer != null)
     {
         NetInterface.Get().localPlayer.AddLock(playingAnimationsLock);
     }
     currentAnimation.Execute();
 }
        private async Task ProcessMessageAsync(Message message, CancellationToken cancellationToken)
        {
            TCommand command = default(TCommand);

            try
            {
                command = _serializer.Deserialize <TCommand>(message.Body);
                _logger.LogInfo($"Recieved command {command.GetType().Name} from queue");
                bool shouldDequeue = true;

                // ReSharper disable once SuspiciousTypeConversion.Global
                IQueueableCommand queueableCommand = command as IQueueableCommand;
                if (queueableCommand != null)
                {
                    queueableCommand.DequeueCount = message.SystemProperties.DeliveryCount;
                }

                await ExecuteCommandAsync(command, cancellationToken);

                if (queueableCommand != null)
                {
                    shouldDequeue = queueableCommand.ShouldDequeue;
                }

                _logger.LogInfo($"Completed processing command {command.GetType().Name} and returning a shouldDequeue status of {shouldDequeue}");
                if (shouldDequeue)
                {
                    await _queueClient.CompleteAsync(message.SystemProperties.LockToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Error during processing command of type {typeof(TCommand).Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {message.SystemProperties.DeliveryCount}, will try again.",
                                   command, ex);
            }
        }
コード例 #5
0
 public Builder AddCommand(IQueueableCommand c)
 {
     commands.Enqueue(c);
     return(this);
 }
コード例 #6
0
 private void MoveToNextCommand()
 {
     currentCommand = commandList.Dequeue();
     currentCommand.Execute();
 }
コード例 #7
0
 public void AddAnimation(IQueueableCommand cmd)
 {
     animationQueue.Enqueue(cmd);
 }