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.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); } }
public State(StateCargo stateCargo) { Cargo = stateCargo; History = new StateHistory(); Loadout = new StateLoadout(); }