Ejemplo n.º 1
0
        void CalculatePotions()
        {
            SaveInventory();

            //Calculate potions
            List <Ingredient> checkedIngredients = new List <Ingredient>(ingredientBox.CheckedItems.Cast <Ingredient>());
            List <Potion>     potions            = Potion.GetAllPotions(checkedIngredients);

            //Populate search results with unique effect combinations
            searchResultBox.Items.Clear();
            potions.ForEach(p => searchResultBox.Items.Add(p.ToString()));

            //Get unique effect strings and sort by number of effects
            List <Potion> uniqueEffectPotions = new List <Potion>(potions.Distinct(new PotionEffectComparer()));
            bool          madeChange;

            do
            {
                madeChange = false;
                for (int i = 0; i < uniqueEffectPotions.Count; i++)
                {
                    for (int j = i + 1; j < uniqueEffectPotions.Count; j++)
                    {
                        if (uniqueEffectPotions[i].effects.Count() < uniqueEffectPotions[j].effects.Count())
                        {
                            Potion temp = uniqueEffectPotions[i];
                            uniqueEffectPotions[i] = uniqueEffectPotions[j];
                            uniqueEffectPotions[j] = temp;
                            madeChange             = true;
                        }
                    }
                }
            } while (madeChange == true);
            searchResultBox.Items.Clear();
            uniqueEffectPotions.ForEach(p => searchResultBox.Items.Add(Effect.GetEffectString(p.effects)));
        }