public IList <DatabaseItemStat> GetRecipeItemStats(ICollection <string> items) { return(ThreadExecuter.Execute( () => repo.GetRecipeItemStats(items) )); }
/// <summary> /// Update the internal database with player formulas /// </summary> /// <param name="formulasGstFile">Path to player formula file, generally my games\grim dawn</param> public void UpdateFormulas(string formulasGstFile, bool isHardcore) { try { FormulaEntry formulaEntries = ReadFormulas(formulasGstFile); ICollection <string> formulas = formulaEntries.Formulas; if (formulas == null) { Logger.Error("Error reading recipe file, formula file either corrupted or file format has changed"); return; } formulas = formulas.Where(formula => !formula.StartsWith("records/items/crafting/blueprints/component") && !formula.StartsWith("records/items/crafting/blueprints/other/craft_elixir") && !formula.StartsWith("records/items/crafting/blueprints/other/craft_oil") && !formula.StartsWith("records/items/crafting/blueprints/other/craft_potion") && !formula.StartsWith("records/items/crafting/blueprints/other/craft_special") ).ToList(); ISet <string> alreadyProcessed = new SortedSet <string>(); if (formulas.Count > 0) { _recipeItemDao.DeleteAll(isHardcore); // References to the actual item [eg artifactName => record] IList <DatabaseItemStat> stats = _recipeItemDao.GetRecipeStats(formulas); // Stats for the actual item IList <DatabaseItemStat> itemStats = _recipeItemDao.GetRecipeItemStats( stats.Select(m => m.TextValue).ToArray() ); List <RecipeItem> toSave = new List <RecipeItem>(); foreach (string formula in formulas) { var q = stats.Where(s => s.Parent.Record.Equals(formula)); if (q.Any()) { DatabaseItemStat item = q.First(); if (!string.IsNullOrEmpty(item.TextValue)) { var minimumLevel = itemStats .Where(m => m.Parent.Record.Equals(item.TextValue)) .Where(m => "levelRequirement".Equals(m.Stat)) .FirstOrDefault()?.Value ?? 0f; if (!alreadyProcessed.Contains(item.TextValue)) { toSave.Add(new RecipeItem { BaseRecord = item.TextValue, IsHardcore = isHardcore, MinimumLevel = minimumLevel, IsExpansion1 = formulaEntries.IsExpansion1 }); alreadyProcessed.Add(item.TextValue); } } else { Logger.Warn($"Could not parse formula \"{formula}\""); } } } _recipeItemDao.Save(toSave); Logger.InfoFormat("Updated internal recipe database with {0} recipes.", formulas.Count); } } catch (Exception ex) { Logger.Warn(ex.Message); Logger.Warn(ex.StackTrace); } }