Esempio n. 1
0
        public static IEnumerable <MaterialTrade> FindPossibleTrades(StateCargo cargo, Dictionary <Entry, int> missingIngredients, Dictionary <EntryData, int> deduced)
        {
            var ingredients = cargo.Ingredients.Values
                              .Where(i => i.Count > 0 &&
                                     i.Data.Group.HasValue &&
                                     i.Data.Group != Group.Thargoid &&
                                     i.Data.Group != Group.Guardian &&
                                     i.Data.Group != Group.Commodities &&
                                     i.Data.Rarity.Rank() != null &&
                                     !missingIngredients.ContainsKey(i)).ToList();

            var allTrades = AllTrades(missingIngredients, ingredients, deduced).ToList();

            var coveredTrades    = allTrades.Where(trade => trade.WillBeEnough).OrderBy(trade => trade.TradedNeeded).ToList();
            var incompleteTrades = allTrades.Where(trade => !trade.WillBeEnough).OrderBy(trade => trade.TradedNeeded).ToList();

            var coveredIngredients = new HashSet <EntryData>();

            foreach (var currentTrade in coveredTrades)
            {
                if (currentTrade.Traded.Count - currentTrade.TradedNeeded - deduced.GetOrDefault(currentTrade.Traded.Data) < 0)
                {
                    continue;
                }

                coveredIngredients.Add(currentTrade.Needed.Data);

                if (deduced.ContainsKey(currentTrade.Traded.Data))
                {
                    deduced[currentTrade.Traded.Data] += currentTrade.TradedNeeded;
                }
                else
                {
                    deduced[currentTrade.Traded.Data] = currentTrade.TradedNeeded;
                }

                yield return(currentTrade);
            }

            foreach (var currentTrade in incompleteTrades)
            {
                if (coveredIngredients.Contains(currentTrade.Needed.Data))
                {
                    continue;
                }

                if (deduced.ContainsKey(currentTrade.Traded.Data))
                {
                    deduced[currentTrade.Traded.Data] += currentTrade.TradedNeeded;
                }
                else
                {
                    deduced[currentTrade.Traded.Data] = currentTrade.TradedNeeded;
                }

                yield return(currentTrade);
            }
        }
Esempio n. 2
0
        public ShoppingListViewModel(StateCargo stateCargo, List <Blueprint> blueprints, ILanguage languages)
        {
            this.blueprints = blueprints.GroupBy(b => Tuple.Create(b.Type, b.BlueprintName)).ToList();
            this.stateCargo = stateCargo;
            this.languages  = languages;

            foreach (var ingredientsValue in stateCargo.Ingredients)
            {
                ingredientsValue.Value.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == "Count")
                    {
                        OnPropertyChanged(nameof(MaterialTrades));
                    }
                };
            }
        }
 public void Setup()
 {
     entries = JsonConvert.DeserializeObject <List <EntryData> >(Helpers.GetEntryDatasJson());
     cargo   = new StateCargo(entries, Mock.Of <ILanguage>(), StateCargo.COUNT_COMPARER);
 }