Пример #1
0
        private bool CheckPerimeter(ICardAllDbInfo cai)
        {
            if (PerimeterScope == PerimeterScope.All)
            {
                return(true);
            }

            IEnumerable <ICardInCollectionCount> cardStats = CountIsNameBased ? cai.Statistics :
                                                             //We filter statitiscs on only current version of the card
                                                             cai.Statistics.Where(s => s.IdGatherer == cai.IdGatherer);

            //Filter on collection
            ICardInCollectionCount[] statistics = cardStats.Where(s => CollectionsSelected.Any(cc => cc.Id == s.IdCollection)).ToArray();

            int count = statistics.Sum(stat => stat.Number);

            if (CountIncludeFoil)
            {
                count += statistics.Sum(stat => stat.FoilNumber);
            }
            if (CountIncludeAltArt)
            {
                count += statistics.Sum(stat => stat.AltArtNumber);
            }
            if (CountIncludeAltArt && CountIncludeFoil)
            {
                count += statistics.Sum(stat => stat.FoilAltArtNumber);
            }

            return(_countComparatorWanted == ComparisonType.GreaterOrEquals ? count >= CountSelected : count < CountSelected);
        }
Пример #2
0
        private bool CheckType(ICardAllDbInfo cai)
        {
            if (ExcludeSpecialCards)
            {
                if (MultiPartCardManager.Instance.IsSpecial(cai))
                {
                    return(false);
                }
            }

            if (TypesSelected.Count == 0)
            {
                return(true);
            }

            CardType type = MultiPartCardManager.Instance.GetCardType(cai);

            CardType wantedType = TypesSelected.Aggregate(CardType.Token, (current, newtype) => current | newtype);

            if (TypeAggregation == MultiSelectedAggregation.And)
            {
                return(Matcher <CardType> .IncludeValue(type, wantedType));
            }
            //TypeAggregation == MultiSelectedAggregation.Or
            return(Matcher <CardType> .HasValue(type, wantedType));
        }
Пример #3
0
        private bool CheckEdition(ICardAllDbInfo cai)
        {
            if (ExcludeFunEditions)
            {
                if (_magicDatabase.GetEdition(cai.IdGatherer).IdBlock == _idBlockFun)
                {
                    return(false);
                }
            }
            if (ExcludeOnlineOnlyEditions)
            {
                if (_magicDatabase.GetEdition(cai.IdGatherer).IdBlock == _idBlockOnlineOnly)
                {
                    return(false);
                }
            }

            if (EditionsSelected.Count == 0)
            {
                return(true);
            }

            IEdition edition = _magicDatabase.GetEdition(cai.IdGatherer);

            return(EditionsSelected.Contains(edition));
        }
Пример #4
0
 public bool IsSpecial(ICardAllDbInfo cai)
 {
     if (MagicRules.IsSpecial(cai.Card.Type))
     {
         return(true);
     }
     return(IsSplitted(cai.Card) && MagicRules.IsSpecial(cai.CardPart2.Type));
 }
Пример #5
0
        public CardType GetCardType(ICardAllDbInfo cai)
        {
            CardType type = MagicRules.GetCardType(cai.Card.Type, cai.Card.CastingCost);

            if (IsSplitted(cai.Card))
            {
                type |= MagicRules.GetCardType(cai.CardPart2.Type, cai.CardPart2.CastingCost);
            }
            return(type);
        }
Пример #6
0
        private void AddNewCard()
        {
            CardCount cardCount = new CardCount
            {
                { new CardCountKey(IsFoil, IsAltArt), Count }
            };

            ICardAllDbInfo cardAllDbInfo = _allCardInfos.First(cadi => cadi.Edition == EditionSelected && cadi.Card == _cardSelected);

            _magicDatabase.InsertOrUpdateCardInCollection(CardCollection.Id, cardAllDbInfo.IdGatherer, LanguageSelected.Id, cardCount);
        }
Пример #7
0
        public CardSubType GetCardSubType(ICardAllDbInfo cai)
        {
            CardSubType subType = MagicRules.GetCardSubType(cai.Card.Type);

            if (IsSplitted(cai.Card))
            {
                subType |= MagicRules.GetCardSubType(cai.CardPart2.Type);
            }

            return(subType);
        }
Пример #8
0
        public ShardColor GetColor(ICardAllDbInfo cai)
        {
            ShardColor color = MagicRules.GetColor(cai.Card.CastingCost);

            if (IsSplitted(cai.Card))
            {
                color |= MagicRules.GetColor(cai.CardPart2.CastingCost);
            }

            return(color);
        }
Пример #9
0
        private bool CheckSubType(ICardAllDbInfo cai)
        {
            if (SubTypesSelected.Count == 0)
            {
                return(true);
            }

            CardSubType subType = MultiPartCardManager.Instance.GetCardSubType(cai);

            CardSubType wantedSubType = SubTypesSelected.Aggregate(CardSubType.None, (current, newsubtype) => current | newsubtype);

            if (SubTypeAggregation == MultiSelectedAggregation.And)
            {
                return(Matcher <CardSubType> .IncludeValue(subType, wantedSubType));
            }
            //SubTypeAggregation == MultiSelectedAggregation.Or
            return(Matcher <CardSubType> .HasValue(subType, wantedSubType));
        }
Пример #10
0
        private bool CheckName(ICardAllDbInfo cai)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                return(true);
            }

            if (!AllLanguages)
            {
                return((cai.Card.Name.IndexOf(Name, StringComparison.InvariantCultureIgnoreCase) >= 0) ||
                       (cai.CardPart2 != null && cai.CardPart2.Name.IndexOf(Name, StringComparison.InvariantCultureIgnoreCase) >= 0));
            }

            return(_magicDatabase.GetAllLanguages().Any(l =>
            {
                string name = cai.Card.ToString(l.Id);
                return !string.IsNullOrEmpty(name) && name.IndexOf(Name, StringComparison.InvariantCultureIgnoreCase) >= 0;
            }));
        }
Пример #11
0
        private bool CheckColor(ICardAllDbInfo cai)
        {
            if (ColorsSelected.Count == 0)
            {
                return(true);
            }


            ShardColor color = MultiPartCardManager.Instance.GetColor(cai);

            bool wantedColorless = ColorsSelected.Contains(ShardColor.Colorless);

            ShardColor wantedColor = ColorsSelected.Aggregate(ShardColor.Colorless, (current, newColor) => current | newColor);

            if (ColorAggregation == MultiSelectedAggregation.And)
            {
                return(Matcher <ShardColor> .IncludeValue(color, wantedColor));
            }
            //ColorAggregation == MultiSelectedAggregation.Or
            return(Matcher <ShardColor> .HasValue(color, wantedColor) || (wantedColorless && color == ShardColor.Colorless));
        }
Пример #12
0
        private CardViewModel(ICardAllDbInfo cardAllDbInfo, bool otherPart)
        {
            CardAllDbInfo = cardAllDbInfo;
            Card          = otherPart ? cardAllDbInfo.CardPart2 : cardAllDbInfo.Card;
            IEdition edition = cardAllDbInfo.Edition;

            Statistics           = cardAllDbInfo.Statistics.Select(s => new StatisticViewModel(s)).ToArray();
            Prices               = cardAllDbInfo.Prices.Select(p => new PriceViewModel(p, edition)).ToArray();
            IsDownSide           = false;
            Edition              = edition;
            Rarity               = cardAllDbInfo.Rarity;
            IdGatherer           = otherPart ? cardAllDbInfo.IdGathererPart2 : cardAllDbInfo.IdGatherer;
            VariationIdGatherers = otherPart ? cardAllDbInfo.VariationIdGatherers2.ToArray() : cardAllDbInfo.VariationIdGatherers.ToArray();
            IsMultiPart          = MultiPartCardManager.Instance.HasMultiPart(Card);
            Is90DegreeSide       = MultiPartCardManager.Instance.Is90DegreeSide(Card);
            if (!string.IsNullOrWhiteSpace(Card.Power) && !string.IsNullOrWhiteSpace(Card.Toughness))
            {
                PowerToughnessLoyalty     = string.Format("{0}/{1}", Card.Power, Card.Toughness);
                PowerToughnessLoyaltyText = "Power/Toughness";
            }
            else if (!string.IsNullOrWhiteSpace(Card.Loyalty))
            {
                PowerToughnessLoyalty     = Card.Loyalty;
                PowerToughnessLoyaltyText = "Loyalty";
            }

            if (!string.IsNullOrWhiteSpace(CastingCost))
            {
                DisplayedCastingCost = CastingCost.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (IsMultiPart && !otherPart)
            {
                OtherCardPart = new CardViewModel(cardAllDbInfo, true);
                if (MultiPartCardManager.Instance.IsDownSide(cardAllDbInfo.CardPart2))
                {
                    OtherCardPart.IsDownSide = true;
                }
            }
        }
Пример #13
0
        private void RefreshDisplayedData(InputMode modifyData)
        {
            UpdateCurrentCollectionDetailAndTranslate();

            //None one the key changed, nothing to recompute
            if (modifyData == InputMode.None)
            {
                return;
            }

            //Change one of the key but no the reference one
            if (InputMode != modifyData)
            {
                Languages.Clear();
                IEdition editionSelected  = EditionSelected;
                ICard    cardNameSelected = _cardSelected;
                if (editionSelected == null || cardNameSelected == null)
                {
                    return;
                }

                ICardAllDbInfo cardAllDbInfo = _allCardInfos.First(cadi => cadi.Edition == editionSelected && cadi.Card == cardNameSelected);
                if (cardAllDbInfo == null)
                {
                    return;
                }

                foreach (ILanguage language in _magicDatabase.GetLanguages(cardAllDbInfo.IdGatherer))
                {
                    Languages.Add(language);
                }

                if (Languages.Count > 0)
                {
                    if (_inputLanguage != null && Languages.Contains(_inputLanguage))
                    {
                        LanguageSelected = _inputLanguage;
                    }
                    else
                    {
                        LanguageSelected = Languages[0];
                    }
                }
            }
            else
            {
                //Change the reference
                switch (InputMode)
                {
                case InputMode.ByEdition:

                    IEdition editionSelected = EditionSelected;
                    Cards.Clear();
                    Languages.Clear();
                    if (editionSelected == null)
                    {
                        return;
                    }

                    List <string> sorted = new List <string>();
                    //Could not call directly GetAllCardsOrderByTranslation because the key must be the same as in all card even if there is no duplicate traduction in the subset
                    foreach (KeyValuePair <string, ICard> kv in _allCardInfos.Where(cadi => cadi.Edition == editionSelected).GetAllCardWithTranslation(_inputLanguage))
                    {
                        //Normal case
                        if (_allCardSorted.ContainsKey(kv.Key))
                        {
                            sorted.Add(kv.Key);
                        }
                        else
                        {
                            //Key was changed because of duplicate traduction, we need to look for the card
                            sorted.Add(_allCardSorted.First(acsKv => kv.Value == acsKv.Value).Key);
                        }
                    }
                    sorted.Sort();
                    Cards.AddRange(sorted);
                    break;

                case InputMode.ByCard:

                    ICard cardNameSelected = _cardSelected;
                    Editions.Clear();
                    Languages.Clear();
                    if (cardNameSelected == null)
                    {
                        return;
                    }

                    foreach (IEdition edition in _allCardInfos.GetAllEditionIncludingCardOrdered(cardNameSelected))
                    {
                        Editions.Add(edition);
                    }

                    if (Editions.Count > 0)
                    {
                        EditionSelected = Editions[0];
                    }

                    break;
                }
            }
        }
Пример #14
0
 public CardViewModel(ICardAllDbInfo cardAllDbInfo)
     : this(cardAllDbInfo, false)
 {
 }