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); } }
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(); } }
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); } }
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); } } }
public DeckFactory(DeckSettings settings, IRandomGenerator randomGenerator) { Guard.AgainstNull(settings, nameof(settings)); Guard.AgainstNull(randomGenerator, nameof(randomGenerator)); this.cards = settings.Cards; this.randomGenerator = randomGenerator; }
public Deck(ICardCollection cards, IRandomGenerator randomGenerator) { Guard.AgainstNull(cards, nameof(cards)); Guard.AgainstNull(randomGenerator, nameof(randomGenerator)); this.cards = cards; this.randomGenerator = randomGenerator; this.Shuffle(); }
public ICollection <ICardInCollectionCount> GetCardCollection(ICardCollection cardCollection) { if (cardCollection == null) { return(null); } return(GetCardCollection(cardCollection.Id)); }
public ICollection <ICardInCollectionCount> GetCardCollection(ICardCollection cardCollection, int idGatherer) { if (cardCollection == null) { return(null); } return(GetCardCollection(cardCollection.Id, idGatherer)); }
public ICardInCollectionCount GetCardCollection(ICardCollection cardCollection, int idGatherer, int idLanguage) { if (cardCollection == null) { return(null); } return(GetCardCollection(cardCollection.Id, idGatherer, idLanguage)); }
public Player(string name, ICardCollection faceDownPile, ICardCollection faceUpPile) { Check.NotNull(faceDownPile, "faceDownPile"); Check.NotNull(faceUpPile, "faceUpPile"); Name = name; FaceDownPile = faceDownPile; FaceUpPile = faceUpPile; }
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)); }
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); } }
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)); }
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); }
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); } }
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); }
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); }
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(); }
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; } }
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; }
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); }
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; } } }
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); } }
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); } }
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]; } }
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]; }
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); }
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))); }
public void ShufleDeck(ICardCollection deck) { throw new System.NotImplementedException(); }
public void DealCards(ICardCollection deck) { throw new NotImplementedException(); }