Exemplo n.º 1
0
        public DeckModel(Deck originalDeck, CardRepository repo, CollectionSnapshot collection, CollectedCardsDeckTransformation transformation)
        {
            int countInMain(Card c) => Deck.MainDeck.Count.TryGet(c.Id);
            int countTotal(Card c, int countInDeck) => countInDeck;
            int countCollected(Card c, int countInDeck) => Math.Min(countInDeck, Collection.GetCount(c));
            int countCollectedSide(Card c, int countInDeck) => (Collection.GetCount(c) - countInMain(c)).WithinRange(0, countInDeck);

            float priceTotal(Card c, int countInDeck) => countInDeck * (c.PriceMid ?? 0f);
            float priceCollected(Card c, int countInDeck) => countCollected(c, countInDeck) * (c.PriceMid ?? 0f);
            float priceCollectedSide(Card c, int countInDeck) => countCollectedSide(c, countInDeck) * (c.PriceMid ?? 0f);

            IList <string> generatedMana(Card c, int countInDeck) => c.GeneratedManaArr;

            float f0() => 0f;
            int i0() => 0;
            float fSum(float a, float b) => a + b;
            int iSum(int a, int b) => a + b;
            float fE(float a) => a;
            int iE(int a) => a;
            Deck deck() => Deck;

            _priceTotalCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceTotal, fE);

            _countTotalCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countTotal, iE);

            _priceCollectedCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceCollected, fE);

            _countCollectedCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countCollected, iE);

            _priceCollectedSideCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceCollectedSide, fE);

            _countCollectedSideCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countCollectedSide, iE);

            _generatedManaCache = new DeckAggregateCache <IList <string>, Dictionary <string, int>, string>(
                repo,
                () => OriginalDeck,
                () => new Dictionary <string, int>(Str.Comparer),
                (a, b) =>
            {
                foreach (string s in b)
                {
                    a.TryGetValue(s, out int count);
                    count++;
                    a[s] = count;
                }

                return(a);
            },
                generatedMana,
                a => string.Concat(a.Keys.OrderBy(s => KeywordDefinitions.GeneratedMana.IndexOf(s, Str.Comparer))));

            _filterNone           = c => true;
            _filterPriceIsUnknown = c => !c.PriceMid.HasValue;

            _filterIsCreature   = c => c.TypesArr.IndexOf("creature", Str.Comparer) >= 0;
            _filterIsLand       = c => c.TypesArr.IndexOf("land", Str.Comparer) >= 0;
            _filterIsOtherSpell = c => !_filterIsCreature(c) && !_filterIsLand(c);

            _filterIsLandAndPriceIsUnknown       = c => _filterIsLand(c) && _filterPriceIsUnknown(c);
            _filterIsCreatureAndPriceIsUnknown   = c => _filterIsCreature(c) && _filterPriceIsUnknown(c);
            _filterIsOtherSpellAndPriceIsUnknown = c => _filterIsOtherSpell(c) && _filterPriceIsUnknown(c);

            Collection      = collection;
            _repo           = repo;
            _transformation = transformation;
            OriginalDeck    = originalDeck;
        }
Exemplo n.º 2
0
        public DeckModel(Deck deck, UiModel ui)
        {
            Ui   = ui;
            Deck = deck;

            int countInMain(Card c) => Deck.MainDeck.Count.TryGet(c.Id);
            int countTotal(Card c, int countInDeck) => countInDeck;
            int countOwned(Card c, int countInDeck) => Math.Min(countInDeck, c.CollectionCount(Ui));
            int countOwnedSide(Card c, int countInDeck) => (c.CollectionCount(Ui) - countInMain(c)).WithinRange(0, countInDeck);

            float priceTotal(Card c, int countInDeck) => countInDeck * (c.PriceMid ?? 0f);
            float priceOwned(Card c, int countInDeck) => countOwned(c, countInDeck) * (c.PriceMid ?? 0f);
            float priceOwnedSide(Card c, int countInDeck) => countOwnedSide(c, countInDeck) * (c.PriceMid ?? 0f);

            IList <string> generatedMana(Card c, int countInDeck) => c.GeneratedManaArr;

            _priceTotalCache = new DeckAggregateCache <float, float, float>(
                () => Ui,
                () => Deck,
                () => 0f,
                (a, b) => a + b,
                priceTotal,
                a => a);

            _countTotalCache = new DeckAggregateCache <int, int, int>(
                () => Ui,
                () => Deck,
                () => 0,
                (a, b) => a + b,
                countTotal,
                a => a);

            _priceOwnedCache = new DeckAggregateCache <float, float, float>(
                () => Ui,
                () => Deck,
                () => 0f,
                (a, b) => a + b,
                priceOwned,
                a => a);

            _countOwnedCache = new DeckAggregateCache <int, int, int>(
                () => Ui,
                () => Deck,
                () => 0,
                (a, b) => a + b,
                countOwned,
                a => a);

            _priceOwnedSideCache = new DeckAggregateCache <float, float, float>(
                () => Ui,
                () => Deck,
                () => 0f,
                (a, b) => a + b,
                priceOwnedSide,
                a => a);

            _countOwnedSideCache = new DeckAggregateCache <int, int, int>(
                () => Ui,
                () => Deck,
                () => 0,
                (a, b) => a + b,
                countOwnedSide,
                a => a);

            _generatedManaCache = new DeckAggregateCache <IList <string>, Dictionary <string, int>, string>(
                () => Ui,
                () => Deck,
                () => new Dictionary <string, int>(Str.Comparer),
                (a, b) =>
            {
                foreach (string s in b)
                {
                    a.TryGetValue(s, out int count);
                    count++;
                    a[s] = count;
                }

                return(a);
            },
                generatedMana,
                a => string.Concat(a.Keys.OrderBy(s => KeywordDefinitions.GeneratedMana.IndexOf(s, Str.Comparer))));

            _filterNone           = c => true;
            _filterPriceIsUnknown = c => !c.PriceMid.HasValue;

            _filterIsCreature   = c => c.TypesArr.IndexOf("creature", Str.Comparer) >= 0;
            _filterIsLand       = c => c.TypesArr.IndexOf("land", Str.Comparer) >= 0;
            _filterIsOtherSpell = c => !_filterIsCreature(c) && !_filterIsLand(c);

            _filterIsLandAndPriceIsUnknown       = c => _filterIsLand(c) && _filterPriceIsUnknown(c);
            _filterIsCreatureAndPriceIsUnknown   = c => _filterIsCreature(c) && _filterPriceIsUnknown(c);
            _filterIsOtherSpellAndPriceIsUnknown = c => _filterIsOtherSpell(c) && _filterPriceIsUnknown(c);
        }