Esempio n. 1
0
        private void searchResultUpdater_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                while (!this.Disposing && !this.IsDisposed && !((BackgroundWorker)sender).CancellationPending)
                {
                    System.Threading.Thread.Sleep(100);
                    if (resultTask != null && resultTask.IsCompleted && !loading)
                    {
                        Console.WriteLine("Results available. Fetching...");

                        effectGrouping = resultTask.Result;
                        resultTask     = null;

                        List <ListViewItem> items = new List <ListViewItem>();
                        for (int i = 0; i < effectGrouping.effects.Count; i++)
                        {
                            items.Add(new ListViewItem(new string[] { effectGrouping.effects[i], Convert.ToString(effectGrouping.values[i]) }));
                        }

                        items = items.OrderBy(i => i.SubItems[0].Text).OrderBy(i => Convert.ToInt32(i.SubItems[1].Text)).ToList();
                        items.Reverse();

                        this.Invoke(new MethodInvoker(delegate
                        {
                            //ClearResults();
                            //resultEffectGroups.Items.AddRange(items.ToArray());
                            UpdateInPlace(resultEffectGroups, items);
                            searchProgressBar.Visible = false;
                        }));
                    }
                }
            }
            catch (System.InvalidOperationException exception) { }
        }
Esempio n. 2
0
        EffectGrouping GetPotions(System.Threading.CancellationToken token)
        {
            List <Ingredient> selectedIngredients = new List <Ingredient>();
            int alchemySkill     = 0,
                fortifyAlchemy   = 0,
                alchemistPerk    = 0;
            bool physicianPerk   = false,
                 benefactorPerk  = false,
                 poisonerPerk    = false,
                 seekerOfShadows = false,
                 purityPerk      = false;

            this.Invoke(new MethodInvoker(delegate
            {
                selectedIngredients = ownedIngredientBox.CheckedItems.Cast <Ingredient>().ToList();
                alchemySkill        = (int)alchemySkillUpDown.Value;
                fortifyAlchemy      = (int)fortifyAlchemyDomain.Value;
                alchemistPerk       = Convert.ToInt32(alchemistPerkComboBox.Text.Replace('%', '\0'));
                physicianPerk       = physicianPerkCheckBox.Checked;
                benefactorPerk      = benefactorPerkCheckBox.Checked;
                poisonerPerk        = poisonerPerkCheckBox.Checked;
                seekerOfShadows     = seekerOfShadowsCheckBox.Checked;
                purityPerk          = purityPerkCheckBox.Checked;

                searchProgressBar.Maximum = (selectedIngredients.Count * (selectedIngredients.Count - 1) * (selectedIngredients.Count + 1)) / 6;
                searchProgressBar.Value   = 0;
                searchProgressBar.Visible = true;
            }));


            EffectGrouping effectGrouping = new EffectGrouping();
            //Iterate through all possible potion mixes
            //Tetrahedral number of iterations
            //221815 iterations for 110 ingredients
            int count = 0,
                predictedTotalCount = (selectedIngredients.Count * (selectedIngredients.Count - 1) * (selectedIngredients.Count + 1)) / 6;

            for (int i = 0; i < selectedIngredients.Count && !token.IsCancellationRequested; i++)
            {
                for (int j = i + 1; j < selectedIngredients.Count; j++)
                {
                    for (int k = j; k < selectedIngredients.Count; k++)
                    {
                        Potion potion = new Potion(selectedIngredients[i], selectedIngredients[j], selectedIngredients[k]
                                                   , alchemySkill
                                                   , fortifyAlchemy
                                                   , alchemistPerk
                                                   , physicianPerk
                                                   , benefactorPerk
                                                   , poisonerPerk
                                                   , seekerOfShadows
                                                   , purityPerk);
                        if (potion.IsValid && potion.effects.Any(e => desiredEffectBox.CheckedItems.Contains(e.name)))
                        {
                            effectGrouping.Add(potion);
                        }
                        count++;
                    }
                }
                this.Invoke(new MethodInvoker(delegate
                {
                    searchProgressBar.Value = count;
                }));
            }
            if (token.IsCancellationRequested)
            {
                Console.WriteLine("Aborted search");
            }
            //this.Invoke(new MethodInvoker(delegate
            //{
            //    searchProgressBar.Visible = false;
            //}));
            return(effectGrouping);
        }