Esempio n. 1
0
        private void CheckRecipe(IEnumerable <Item> items, StashTab tab, CombinationRequirements requirements)
        {
            LogLargeWarning(items.Count(), tab.Name);
            this._stopwatch.Restart();

            // prepare qualities and combinations
            IReadOnlyDictionary <Item, int> qualities = RecipeCombination.ExtractItemQualities(items);

            Log.Verbose("Generating permutations");
            IEnumerable <IEnumerable <KeyValuePair <Item, int> > > permutations = Permutator.GetCombinations(qualities, requirements.MaxItems);

            // track already done just to reduce spam in output
            HashSet <RecipeCombination> alreadyDone = new HashSet <RecipeCombination>();
            // only output tab name the first time
            bool tabNameShown = false;
            // skip showing invalid if capacity is exceeded
            bool exceedsCapacity = permutations.LongCount() > int.MaxValue / 2;

            if (exceedsCapacity && _options.ShowInvalid)
            {
                Log.Warning("Possible combinations count exceed capacity - logging of invalid combinations will be disabled");
            }
            Log.Verbose("Permutations generated in {Time} ms", this._stopwatch.ElapsedMilliseconds);

            // calculate total quality of each combination
            Log.Verbose("Calculating combinations");
            foreach (IEnumerable <KeyValuePair <Item, int> > sequence in permutations)
            {
                RecipeCombination combination = RecipeCombination.Calculate(sequence, requirements.TargetQuality);

                // determine if set should be shown
                if (_options.OnlyExact && combination.TotalQuality != requirements.TargetQuality)
                {
                    continue;
                }
                if ((!_options.ShowInvalid || exceedsCapacity) && combination.TotalQuality < requirements.TargetQuality)
                {
                    continue;
                }

                // ensure this set wasn't already calculated, based just on items qualities
                if (!alreadyDone.Add(combination))
                {
                    continue;
                }

                // for the first item in set, notify user what tab it's in
                if (!tabNameShown)
                {
                    Log.Information("Found possible trades with items from tab {TabName}", tab);
                    tabNameShown = true;
                }

                // output the set and total quality
                Console.Write(combination.ToString() + ": ");
                ConsoleColor previousColor = Console.ForegroundColor;
                if (combination.TotalQuality == requirements.TargetQuality)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else if (combination.TotalQuality > requirements.TargetQuality)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.Write(combination.TotalQuality);
                Console.ForegroundColor = previousColor;
                if (_options.ShowItemNames)
                {
                    Console.Write($" ({string.Join(", ", combination.Items)})");
                }
                Console.WriteLine();
            }

            Log.Verbose("Done checking stash tab {TabName} ({Time} ms)", tab.Name, this._stopwatch.ElapsedMilliseconds);
        }
 public bool Equals(RecipeCombination other)
 => other != null && this.Qualities.SequenceEqual(other.Qualities);