コード例 #1
0
ファイル: PackExtensionMethods.cs プロジェクト: llebel/OCTGN
        public static PackContent GenerateContent(this Pack pack)
        {
            var packContents      = new PackContent();
            var cardSelectionPool = pack.Set.Cards.ToList();
            var game = pack.Set.GetGame();

            // add the include cards to the set for this booster
            var includeCards =
                (
                    from qset in pack.Includes.Select(x => x.SetId)
                    .Distinct()
                    .Select(x => SetManager.Get().GetById(x))
                    from card in qset.Cards
                    join inc in pack.Includes on qset.Id equals inc.SetId
                    where card.Id == inc.Id
                    select new { Card = card, Include = inc }
                )
                .Select(picked =>
            {
                var card = new Card(picked.Card);

                foreach (var include in picked.Include.Properties)
                {
                    card.PropertySets[""].Properties[include.Property] = include.Value;
                }
                ;
                return(card);
            });

            cardSelectionPool.AddRange(includeCards);

            packContents.Merge(ProcessPackItems(pack, pack.Items, cardSelectionPool));
            return(packContents);
        }
コード例 #2
0
            public PackContent GenerateContent(Pack pack)
            {
                var result = new PackContent();

                foreach (PackContent defContent in this.Select(def => def.GetCards(pack)))
                {
                    result.Merge(defContent);
                }
                return(result);
            }
コード例 #3
0
ファイル: PickCardsDialog.xaml.cs プロジェクト: uwat79/OCTGN
        public void OpenPacks(IEnumerable <Guid> packs)
        {
            new Task(
                () =>
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    TabControlMain.IsEnabled           = false;
                    ProgressBarLoading.Visibility      = Visibility.Visible;
                    ProgressBarLoading.IsIndeterminate = true;
                    ProgressBarLoading.Maximum         = packs.Count();
                }));
                this.StopListenningForFilterValueChanges();

                foreach (Pack pack in packs.Select(Program.GameEngine.Definition.GetPackById))
                {
                    if (pack == null)
                    {
                        Program.GameMess.Warning("Received pack is missing from the database. Pack is ignored.");
                        continue;
                    }
                    PackContent content = pack.CrackOpen();
                    foreach (ObservableMultiCard c in content.LimitedCards.Select(x => x.ToMultiCard().AsObservable()))
                    {
                        Dispatcher.Invoke(new Action(() => { this.CardPool.Add(c); }));
                    }

                    foreach (ObservableMultiCard c in content.UnlimitedCards.Select(x => x.ToMultiCard().AsObservable()))
                    {
                        Dispatcher.Invoke(new Action(() => { this.UnlimitedPool.Add(c); }));
                    }

                    Dispatcher.Invoke(new Action(() =>
                    {
                        ProgressBarLoading.IsIndeterminate = false;
                        ProgressBarLoading.Value          += 1;
                    }));
                }

                Dispatcher.Invoke(
                    new Action(() =>
                {
                    this.UpdateFilters();

                    this.ListenForFilterValueChanges();
                    ProgressBarLoading.IsIndeterminate = false;
                    ProgressBarLoading.Visibility      = Visibility.Collapsed;
                    TabControlMain.IsEnabled           = true;
                }));
            }).Start();
        }
コード例 #4
0
            public override PackContent GetCards(Pack pack)
            {
                var result     = new PackContent();
                var conditions = new string[2];

                conditions[0] = "set_id = '" + pack.Set.Id + "'";
                conditions[1] = string.Format("{0} = '{1}'", Key, Value);
                if (Quantity < 0)
                {
                    result.UnlimitedCards.AddRange(pack.Set.Game.SelectCardModels(conditions));
                }
                else
                {
                    result.LimitedCards.AddRange(pack.Set.Game.SelectRandomCardModels(Quantity, conditions));
                }
                return(result);
            }
コード例 #5
0
        private static PackContent ProcessPackItems(Pack pack, List <object> items, List <Card> cardPool)
        {
            PackContent content = new PackContent();

            foreach (var item in items)
            {
                if (item is Pick pick)
                {
                    var filteredPool = new List <Card>(cardPool);
                    foreach (PickProperty pickProperty in pick.Properties)
                    {
                        var Prop  = pickProperty.Property;
                        var Value = pickProperty.Value;
                        var list  = (
                            from card in filteredPool
                            where
                            card.MatchesPropertyValue(Prop.Name, Value)
                            select card).ToList();
                        filteredPool = list;
                    }

                    if (pick.Quantity < 0)
                    {
                        content.UnlimitedCards.AddRange(filteredPool);
                    }
                    else
                    {
                        for (var i = 0; i < pick.Quantity; i++)
                        {
                            var randomCard = filteredPool.RandomElement();
                            if (randomCard != null)
                            {
                                content.LimitedCards.Add(randomCard);
                                filteredPool.Remove(randomCard);
                            }
                            else
                            {
                                //TODO: Proper error logging here
                                Log.Warn(String.Format("Set {0} ({1}) does not contain enough cards to create this booster pack correctly.", pack.Set.Name, pack.Name));
                            }
                        }
                    }
                }
                else if (item is OptionsList optionsList)
                {
                    double threshold = 0;
                    if (_provider == null)
                    {
                        _provider = new RNGCryptoServiceProvider();
                    }
                    var result = new byte[8];
                    _provider.GetBytes(result);
                    var value = ((double)BitConverter.ToUInt64(result, 0) / ulong.MaxValue);

                    Option selectedOption = null;
                    foreach (Option option in optionsList.Options)
                    {
                        threshold += option.Probability;
                        if (value <= threshold)
                        {
                            selectedOption = option;
                            break;
                        }
                    }
                    if (selectedOption != null)
                    {
                        content.Merge(ProcessPackItems(pack, selectedOption.Items, cardPool));
                    }
                }
            }
            return(content);
        }
コード例 #6
0
 public void Merge(PackContent content)
 {
     LimitedCards.AddRange(content.LimitedCards);
     UnlimitedCards.AddRange(content.UnlimitedCards);
 }
コード例 #7
0
        public bool UpdateMultiple(int playerId, List <Deck> newDecks)
        {
            bool updateIsValid  = true;
            var  optionsBuilder = new DbContextOptionsBuilder <GodsArenaApiContext>();

            optionsBuilder.UseSqlServer(Startup.connectionString);
            using (IDbContextTransaction transaction = GodsArenaApiContext.Database.BeginTransaction())
            {
                Pack       pack = _packRepository.GetInclude <Pack>(p => p.PlayerId == playerId, p => p.PackContents);
                List <int> levelSlotIdTakenCardFromList = new List <int>();
                //List of the Player old decks state
                List <Deck> oldDecks = GetMultipleInclude <Deck>(d => d.PlayerId == playerId, d => d.LevelSlots).ToList();
                Dictionary <int, Dictionary <int, LevelSlot> > levelTo_IdToLevelSlotDictionaryForLooping = new Dictionary <int, Dictionary <int, LevelSlot> >();
                //Will be used as a cash to search in the old levelSlots
                Dictionary <int, Dictionary <int, LevelSlot> > levelTo_IdToLevelSlotDictionaryForVerification = new Dictionary <int, Dictionary <int, LevelSlot> >();
                Dictionary <int, Deck> idToDeckDictionary = new Dictionary <int, Deck>();

                foreach (var deck in oldDecks)
                {
                    idToDeckDictionary.Add(deck.Id, deck);

                    foreach (var levelSlot in deck.LevelSlots)
                    {
                        if (!levelTo_IdToLevelSlotDictionaryForVerification.ContainsKey(levelSlot.Level))
                        {
                            levelTo_IdToLevelSlotDictionaryForVerification.Add(levelSlot.Level, new Dictionary <int, LevelSlot>());
                            levelTo_IdToLevelSlotDictionaryForLooping.Add(levelSlot.Level, new Dictionary <int, LevelSlot>());
                        }

                        levelTo_IdToLevelSlotDictionaryForVerification[levelSlot.Level].Add(levelSlot.Id, levelSlot);
                        levelTo_IdToLevelSlotDictionaryForLooping[levelSlot.Level].Add(levelSlot.Id, levelSlot);
                    }
                }


                foreach (var newDeck in newDecks)
                {
                    if (updateIsValid)
                    {
                        var oldDeck = idToDeckDictionary[newDeck.Id];
                        foreach (var oldLevelSlot in oldDeck.LevelSlots)
                        {
                            LevelSlot newLevelSlot = newDeck.LevelSlots.Find(ls => ls.Level == oldLevelSlot.Level);
                            if (oldLevelSlot.CardId != newLevelSlot.CardId)
                            {
                                //Immediatly take it out of consideration as we won't look in itself for the card
                                levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Remove(oldLevelSlot.Id);
                                PackContent packContentContainingNewDeckCard = pack.PackContents.Find(pc => pc.CardId == newLevelSlot.CardId);
                                if (packContentContainingNewDeckCard != null)
                                {
                                    _packContentRepository.RemoveCard(packContentContainingNewDeckCard);
                                    if (!levelSlotIdTakenCardFromList.Contains(oldLevelSlot.Id))
                                    {
                                        _packContentRepository.AddCard(pack.Id, oldLevelSlot.CardId);
                                    }
                                    _packContentRepository.Save();
                                }
                                else
                                {
                                    LevelSlot levelSlotContainingNewDeckCard = levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Where(p => p.Value.CardId == newLevelSlot.CardId).FirstOrDefault().Value;
                                    if (levelSlotContainingNewDeckCard != null)
                                    {
                                        levelSlotIdTakenCardFromList.Add(levelSlotContainingNewDeckCard.Id);
                                        levelTo_IdToLevelSlotDictionaryForVerification[oldLevelSlot.Level].Remove(levelSlotContainingNewDeckCard.Id);
                                        _packContentRepository.AddCard(pack.Id, oldLevelSlot.CardId);
                                        _packContentRepository.Save();
                                    }
                                    else
                                    {
                                        //Here it hasn't been found in pack neither in any old level slot so it came from nowhere and can't be added
                                        transaction.Rollback();
                                        updateIsValid = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                //Here if updateIsValid is till true it means that the update is valid and we can then modify the decks
                if (updateIsValid)
                {
                    foreach (var newDeck in newDecks)
                    {
                        var oldDeck = idToDeckDictionary[newDeck.Id];
                        foreach (var newLevelSlot in newDeck.LevelSlots)
                        {
                            //levelTo_IdToLevelSlotDictionaryForLooping[newLevelSlot.Level][newLevelSlot.Id].CardId = newLevelSlot.CardId;
                            oldDeck.LevelSlots.Where(ls => ls.Level == newLevelSlot.Level).FirstOrDefault().CardId = newLevelSlot.CardId;
                        }
                    }
                    transaction.Commit();
                }
            }

            return(updateIsValid);
        }