Ejemplo n.º 1
0
        public ICardCollection UpdateCollectionName(ICardCollection collection, string name)
        {
            using (new WriterLock(_lock))
            {
                if (collection == null || string.IsNullOrWhiteSpace(name) || GetCollection(name) != null)
                {
                    return(collection);
                }


                if (collection is not CardCollection newCollection)
                {
                    return(collection);
                }

                newCollection.Name = name;

                using (IDbConnection cnx = _databaseConnection.GetMagicConnection())
                {
                    Mapper <CardCollection> .UpdateOne(cnx, newCollection);
                }

                return(newCollection);
            }
        }
Ejemplo n.º 2
0
        private void RemoveCommandExecute(object o)
        {
            HierarchicalResultViewModel vm = Hierarchical.Selected;

            if (vm == null)
            {
                return;
            }

            ICardCollection sourceCollection = _magicDatabase.GetAllCollections().First(cc => cc.Name == Hierarchical.Name);

            InputViewModel questionViewModel = InputViewModelFactory.Instance.CreateQuestionViewModel("Remove", string.Format("Remove selected from {0}?", sourceCollection.Name));

            OnInputRequested(questionViewModel);

            if (questionViewModel.Result == true)
            {
                using (_magicDatabaseForCardInCollection.BatchMode())
                {
                    foreach (ICardInCollectionCount cicc in GetCardInCollectionInSelected(vm, sourceCollection))
                    {
                        ICardCount cardCount = new CardCount();
                        foreach (KeyValuePair <ICardCountKey, int> kv in cicc.GetCardCount())
                        {
                            cardCount.Add(kv.Key, -kv.Value);
                        }

                        _magicDatabaseForCardInCollection.InsertOrUpdateCardInCollection(sourceCollection.Id, cicc.IdGatherer, cicc.IdLanguage, cardCount);
                    }
                }

                LoadCardsHierarchy();
            }
        }
Ejemplo n.º 3
0
        private void MoveCardToOtherCollection(ICardCollection collection, int idGatherer, int idLanguage, int countToMove, ICardCountKey cardCountKey, ICardCollection collectionDestination)
        {
            if (countToMove <= 0 || cardCountKey == null)
            {
                return;
            }

            using (new WriterLock(_lock))
            {
                ICardInCollectionCount cardInCollectionCount = GetCardCollection(collection, idGatherer, idLanguage);
                if (cardInCollectionCount == null)
                {
                    return;
                }

                if (cardInCollectionCount.GetCount(cardCountKey) < countToMove)
                {
                    return;
                }

                CardCount cardCountSource = new CardCount
                {
                    { cardCountKey, -countToMove }
                };

                CardCount cardCountDestination = new CardCount
                {
                    { cardCountKey, countToMove }
                };

                InsertOrUpdateCardInCollection(collection.Id, idGatherer, idLanguage, cardCountSource);
                InsertOrUpdateCardInCollection(collectionDestination.Id, idGatherer, idLanguage, cardCountDestination);
            }
        }
Ejemplo n.º 4
0
        public void MoveCollection(string toBeDeletedCollectionName, string toAddCollectionName)
        {
            using (new WriterLock(_lock))
            {
                ICardCollection toBeDeletedCollection = GetCollection(toBeDeletedCollectionName);
                if (toBeDeletedCollection == null)
                {
                    return;
                }

                ICollection <ICardInCollectionCount> collectionToRemove = GetCardCollection(toBeDeletedCollection);
                if (collectionToRemove == null || collectionToRemove.Count == 0)
                {
                    return;
                }

                ICardCollection toAddCollection = GetCollection(toAddCollectionName);
                if (toAddCollection == null)
                {
                    return;
                }

                using (BatchMode())
                {
                    foreach (ICardInCollectionCount cardInCollectionCount in collectionToRemove)
                    {
                        InsertOrUpdateCardInCollection(toAddCollection.Id, cardInCollectionCount.IdGatherer, cardInCollectionCount.IdLanguage, cardInCollectionCount.GetCardCount());
                    }

                    DeleteAllCardInCollection(toBeDeletedCollectionName);
                }
            }
        }
Ejemplo n.º 5
0
        public DeckFactory(DeckSettings settings, IRandomGenerator randomGenerator)
        {
            Guard.AgainstNull(settings, nameof(settings));
            Guard.AgainstNull(randomGenerator, nameof(randomGenerator));

            this.cards           = settings.Cards;
            this.randomGenerator = randomGenerator;
        }
Ejemplo n.º 6
0
        public Deck(ICardCollection cards, IRandomGenerator randomGenerator)
        {
            Guard.AgainstNull(cards, nameof(cards));
            Guard.AgainstNull(randomGenerator, nameof(randomGenerator));

            this.cards           = cards;
            this.randomGenerator = randomGenerator;
            this.Shuffle();
        }
Ejemplo n.º 7
0
        public ICollection <ICardInCollectionCount> GetCardCollection(ICardCollection cardCollection)
        {
            if (cardCollection == null)
            {
                return(null);
            }

            return(GetCardCollection(cardCollection.Id));
        }
Ejemplo n.º 8
0
        public ICollection <ICardInCollectionCount> GetCardCollection(ICardCollection cardCollection, int idGatherer)
        {
            if (cardCollection == null)
            {
                return(null);
            }

            return(GetCardCollection(cardCollection.Id, idGatherer));
        }
Ejemplo n.º 9
0
        public ICardInCollectionCount GetCardCollection(ICardCollection cardCollection, int idGatherer, int idLanguage)
        {
            if (cardCollection == null)
            {
                return(null);
            }

            return(GetCardCollection(cardCollection.Id, idGatherer, idLanguage));
        }
Ejemplo n.º 10
0
        public Player(string name, ICardCollection faceDownPile, ICardCollection faceUpPile)
        {
            Check.NotNull(faceDownPile, "faceDownPile");
            Check.NotNull(faceUpPile, "faceUpPile");

            Name = name;

            FaceDownPile = faceDownPile;
            FaceUpPile   = faceUpPile;
        }
Ejemplo n.º 11
0
        public ImportStatus ImportToNewCollection(string importFilePath, string newCollectionName)
        {
            IMagicDatabaseReadAndWriteCollection magicDatabaseCollection = MagicDatabaseManager.ReadAndWriteCollection;
            ICardCollection collection = magicDatabaseCollection.InsertNewCollection(newCollectionName);

            if (collection == null)
            {
                throw new ArgumentException("Collection name already exists", nameof(newCollectionName));
            }

            return(ImportToCollection(importFilePath, collection));
        }
Ejemplo n.º 12
0
        public void MoveCardToOtherCollection(ICardCollection collection, int idGatherer, int idLanguage, ICardCount cardCount, ICardCollection collectionDestination)
        {
            if (cardCount == null)
            {
                return;
            }

            foreach (KeyValuePair <ICardCountKey, int> kv in cardCount)
            {
                MoveCardToOtherCollection(collection, idGatherer, idLanguage, kv.Value, kv.Key, collectionDestination);
            }
        }
Ejemplo n.º 13
0
        public ImportStatus ImportToExistingCollection(string importFilePath, string collectionToCompletName)
        {
            IMagicDatabaseReadAndWriteCardInCollection magicDatabaseCollection = MagicDatabaseManager.ReadAndWriteCardInCollection;
            ICardCollection collection = magicDatabaseCollection.GetCollection(collectionToCompletName);

            if (collection == null)
            {
                throw new ArgumentException("Collection name doesn't exist", nameof(collectionToCompletName));
            }

            return(ImportToCollection(importFilePath, collection));
        }
Ejemplo n.º 14
0
        public UiModel(
            ImageLoader imageLoader,
            ImageRepository imageRepo,
            CardRepository cardRepo,
            [Optional, Named("collection")] ICardCollection collection)
        {
            CardRepo    = cardRepo;
            Collection  = collection;
            ImageLoader = imageLoader;
            ImageRepo   = imageRepo;

            LanguageController = new LanguageController(CardLocalization.DefaultLanguage);
        }
Ejemplo n.º 15
0
        public void DeleteCollection(string name)
        {
            using (new WriterLock(_lock))
            {
                ICardCollection cardCollection = GetCollection(name);
                if (cardCollection == null)
                {
                    return;
                }

                RemoveFromDbAndUpdateReferential(cardCollection as CardCollection, RemoveFromReferential);
                AuditRemoveCollection(cardCollection.Id);
            }
        }
Ejemplo n.º 16
0
        protected internal ICardCollection GenerateCardsFor(ICardCollection cardCollection, int count)
        {
            var availableCardTypes = m_cardTypeDescriptor.GetAvailableCardTypesOf(cardCollection.ContentType);
            var rnd = new Random();

            // shuffle add cards
            for (int i = 0; i < count; i++)
            {
                var index = rnd.Next(0, availableCardTypes.Count - 1);
                cardCollection.Add(m_cardObjectFactory.CreateCardObject(availableCardTypes.ElementAt(index)));
            }

            return(cardCollection);
        }
Ejemplo n.º 17
0
        public void MoveCardToOtherCollection(ICardCollection collection, ICard card, IEdition edition, ILanguage language, ICardCount cardCount, ICardCollection collectionDestination)
        {
            if (cardCount == null)
            {
                return;
            }

            using (new WriterLock(_lock))
            {
                int idGatherer = GetIdGatherer(card, edition);
                int idLanguage = language.Id;
                MoveCardToOtherCollection(collection, idGatherer, idLanguage, cardCount, collectionDestination);
            }
        }
        private static ICardGamePlayer SetupNormalPlayerMock()
        {
            var player = Substitute.For <ICardGamePlayer>();

            player.IsComputerPlayer.Returns(false);
            player.CardCount.Returns(3);

            ICardCollection faceDownPile = SetupFaceDownPileMock();
            ICardCollection faceUpPile   = SetupFaceUpPileMock();

            player.FaceDownPile.Returns(faceDownPile);
            player.FaceUpPile.Returns(faceUpPile);

            return(player);
        }
Ejemplo n.º 19
0
        public Deck()
        {
            _cards = new CardCollection();

            var colors = Enum.GetValues(typeof(CardColor));

            foreach (CardColor c in colors)
            {
                for (var i = MinCardValue; i <= MaxCardValue; i++)
                {
                    _cards.Add(new Card(c, i));
                }
            }

            _cards.Shuffle();
        }
Ejemplo n.º 20
0
            void IInteractionRule.Interact(Card card, ICardCollection source)
            {
                _NextRule = InteractionRuleType.Peek2;

                if (_CardCollections.Inspect.Count < 2)
                {
                    source.RemoveCard(card);
                    _CardCollections.Inspect.AddCard(card);
                }
                else
                {
                    source.AddCard(_CardCollections.Inspect.RemoveFirstCard());
                    source.AddCard(_CardCollections.Inspect.RemoveFirstCard());
                    _NextRule = InteractionRuleType.Default;
                }
            }
Ejemplo n.º 21
0
            void IInteractionRule.Interact(Card card, ICardCollection source)
            {
                switch (source.Type)
                {
                case InteractionController.CardCollectionType.Draw:
                {
                    _NextRule = InteractionRuleType.FromDraw;
                    if (card.Type != Card.CardType.Normal)
                    {
                        _NextRule = InteractionRuleType.FromDrawSpecial;
                    }

                    var topCard = source.RemoveCard(default);
                    _CardCollections.Inspect.AddCard(topCard);

                    break;
                }
Ejemplo n.º 22
0
        private ImportStatus ImportToCollection(string importFilePath, ICardCollection collection)
        {
            ImportStatus status = ImportStatus.BuildStatus(GetImport(importFilePath));

            IMagicDatabaseReadAndWriteCardInCollection magicDatabase = MagicDatabaseManager.ReadAndWriteCardInCollection;

            using (magicDatabase.BatchMode())
            {
                //Add in database the good one
                foreach (IImportExportCardCount importExportCardCount in status.ReadyToBeInserted)
                {
                    magicDatabase.InsertOrUpdateCardInCollection(collection.Id, importExportCardCount.IdGatherer, importExportCardCount.IdLanguage, importExportCardCount.GetCardCount());
                }
            }

            return(status);
        }
Ejemplo n.º 23
0
        public void Export(string[] collectionNames, string outpath, ExportFormat exportFormatSelected)
        {
            if (!Directory.Exists(outpath))
            {
                throw new ArgumentException("output path doesn't exist", nameof(outpath));
            }

            IImportExportFormatter formatter = ImportExportFormatterFactory.Create(exportFormatSelected);

            if (formatter == null)
            {
                throw new ArgumentException("Can't find appropriate formatter for " + exportFormatSelected, nameof(exportFormatSelected));
            }

            IMagicDatabaseReadOnly magicDatabase = MagicDatabaseManager.ReadOnly;

            foreach (string collectionName in collectionNames)
            {
                ICardCollection cardcollection = magicDatabase.GetCollection(collectionName);
                IEnumerable <ICardInCollectionCount> cardsInCollection = magicDatabase.GetCardCollection(cardcollection);

                if (cardsInCollection == null)
                {
                    throw new ImportExportException("Can't find collection named {0}", collectionName);
                }

                string filePath = Path.Combine(outpath, collectionName + formatter.Extension);

                try
                {
                    using (StreamWriter sw = new StreamWriter(filePath, false))
                    {
                        sw.Write(formatter.ToFile(cardsInCollection));
                    }
                }
                catch (ImportExportException)
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 24
0
        private IEnumerable <AuditInfo> GetAudit()
        {
            foreach (IAudit audit in _allAudit.Where(a => a.OperationDate >= MinDate && a.OperationDate < MaxDate.AddDays(1)))
            {
                AuditInfo info = new AuditInfo
                {
                    Quantity      = audit.Quantity,
                    OperationDate = audit.OperationDate.ToLocalTime().ToString("G"),
                    IsFoil        = audit.IsFoil.HasValue && audit.IsFoil.Value,
                    IsAltArt      = audit.IsAltArt.HasValue && audit.IsAltArt.Value,
                };

                ICardCollection cardCollection = _magicDatabase.GetCollection(audit.IdCollection);
                info.CollectionName = cardCollection == null ? "(Deleted) " + audit.IdCollection : cardCollection.Name;

                if (audit.IdGatherer.HasValue)
                {
                    ICard card = _magicDatabase.GetCard(audit.IdGatherer.Value);
                    if (card == null)
                    {
                        info.CardName    = "(Not found) " + audit.IdGatherer.Value;
                        info.EditionName = "(Not found) " + audit.IdGatherer.Value;
                    }
                    else
                    {
                        info.CardName = card.Name;
                        IEdition edition = _magicDatabase.GetEdition(audit.IdGatherer.Value);
                        info.EditionName = edition == null ? "(Not found) " + audit.IdGatherer.Value : edition.Name;
                    }
                    if (audit.IdLanguage.HasValue)
                    {
                        ILanguage language = _magicDatabase.GetLanguage(audit.IdLanguage.Value);
                        info.Language = language == null ? "(Not found) " + audit.IdLanguage.Value : language.Name;
                    }
                    else
                    {
                        info.Language = "(Missing language)";
                    }
                }

                yield return(info);
            }
        }
Ejemplo n.º 25
0
        public void ChangeCardEditionFoilAltArtLanguage(ICardCollection collection, ICard card, int countToChange, IEdition editionSource, ICardCountKey cardCountKeySource, ILanguage languageSource,
                                                        IEdition editionDestination, ICardCountKey cardCountKeyDestination, ILanguage languageDestination)
        {
            if (countToChange <= 0)
            {
                return;
            }

            using (new WriterLock(_lock))
            {
                if (languageSource == null || languageDestination == null || cardCountKeySource == null || cardCountKeyDestination == null)
                {
                    return;
                }

                int idGathererSource      = GetIdGatherer(card, editionSource);
                int idGathererDestination = GetIdGatherer(card, editionDestination);
                ICardInCollectionCount cardInCollectionCount = GetCardCollection(collection, idGathererSource, languageSource.Id);

                if (cardInCollectionCount == null || idGathererDestination == 0)
                {
                    return;
                }

                if (cardInCollectionCount.GetCount(cardCountKeySource) < countToChange)
                {
                    return;
                }

                CardCount cardCountSource = new CardCount
                {
                    { cardCountKeySource, -countToChange }
                };

                CardCount cardCountDestination = new CardCount
                {
                    { cardCountKeyDestination, countToChange }
                };

                InsertOrUpdateCardInCollection(collection.Id, idGathererSource, languageSource.Id, cardCountSource);
                InsertOrUpdateCardInCollection(collection.Id, idGathererDestination, languageDestination.Id, cardCountDestination);
            }
        }
Ejemplo n.º 26
0
        public CardSourceViewModel(IMagicDatabaseReadOnly magicDatabase, ICardCollection sourceCardCollection, ICard card)
        {
            _magicDatabase = magicDatabase;

            Card = card;

            _cardInCollectionCounts = _magicDatabase.GetCollectionStatisticsForCard(sourceCardCollection, Card)
                                      .ToArray();

            _editions = _cardInCollectionCounts.Select(cicc => _magicDatabase.GetEdition(cicc.IdGatherer))
                        .Distinct()
                        .Ordered()
                        .ToArray();

            if (_editions.Length > 0)
            {
                EditionSelected = _editions[0];
            }
        }
Ejemplo n.º 27
0
        public void OnInteraction(Card card, ICardCollection source)
        {
            if (!_IsInitialized || Locked)
            {
                return;
            }
            if (!_CurrentInteractionRule.CanInteract(source.Type))
            {
                return;
            }

            _CurrentInteractionRule.Interact(card, source);

            if (_CurrentInteractionRule.NextRule == InteractionRules.InteractionRuleType.Default)
            {
                OnPlayerEndTurn?.Invoke(this, new OnPlayerEndTurnArgs());
            }

            _CurrentInteractionRule = _RuleBook[_CurrentInteractionRule.NextRule];
        }
Ejemplo n.º 28
0
        public static Deck MakeRandomDeck(ICardCollection cardCollection, GameRules gameRules, int deckSize, Random random)
        {
            var cards = cardCollection.GetCards().ToList();

            if (deckSize < gameRules.MinDeckSize || deckSize > gameRules.MaxDeckSize)
            {
                throw new ArgumentException("Deck size is incorrect");
            }
            var deck = new Deck(gameRules);

            while (deck.Count < deckSize)
            {
                var card = random.ChoiceOrDefault(cards.Where(x => deck.CanAddCard(x)));
                if (card == null)
                {
                    throw new ArgumentException("Collection is not large enough");
                }
                deck.Add(card);
            }
            return(deck);
        }
Ejemplo n.º 29
0
        public void DeleteAllCardInCollection(string name)
        {
            using (new WriterLock(_lock))
            {
                ICardCollection cardCollection = GetCollection(name);
                if (cardCollection == null)
                {
                    return;
                }

                ICollection <ICardInCollectionCount> collection = GetCardCollection(cardCollection);
                if (collection == null || collection.Count == 0)
                {
                    return;
                }

                using (BatchMode())
                {
                    using (IDbConnection cnx = _databaseConnection.GetMagicConnection())
                    {
                        Mapper <CardInCollectionCount> .DeleteMulti(cnx, collection.Cast <CardInCollectionCount>());
                    }

                    foreach (ICardInCollectionCount cardInCollectionCount in collection)
                    {
                        ICardCount cardCount = new CardCount();
                        foreach (KeyValuePair <ICardCountKey, int> kv in cardInCollectionCount.GetCardCount())
                        {
                            cardCount.Add(kv.Key, -kv.Value);
                        }
                        AuditAddCard(cardInCollectionCount.IdCollection, cardInCollectionCount.IdGatherer, cardInCollectionCount.IdLanguage, cardCount);

                        RemoveFromReferential(cardInCollectionCount);
                    }
                }
            }
        }
        private IEnumerable <CardViewModel> CardCollectionAsViewModel(string collectionName)
        {
            ICardCollection cardCollection = _magicDatabase.GetCollection(collectionName);

            return(_magicDatabase.GetAllInfos(cardCollection.Id).Select(cai => new CardViewModel(cai)));
        }
Ejemplo n.º 31
0
 public void ShufleDeck(ICardCollection deck)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 32
0
 public void DealCards(ICardCollection deck)
 {
     throw new NotImplementedException();
 }