private Dictionary <int, Dictionary <int, double> > ResourcesForBlock() { var templates = new Dictionary <int, Dictionary <int, double> >(); FlatConfigBlockById .ForEach(B => { var idCfg = B.Value.Attr.FirstOrDefault(A => A.Name == "Id"); if (!int.TryParse(idCfg?.Value?.ToString(), out var id)) { return; } var ressList = new Dictionary <int, double>(); var templateRoot = B.Value.Attr.FirstOrDefault(A => A.Name == "TemplateRoot")?.Value?.ToString() ?? idCfg.AddOns?.FirstOrDefault(A => A.Key == "Name").Value?.ToString(); if (string.IsNullOrEmpty(templateRoot)) { return; } if (!FlatConfigTemplatesByName.TryGetValue(templateRoot, out var templateRootBlock)) { return; } ScanTemplates(templateRootBlock, ressList, 1); if (ressList.Count > 0 && !templates.ContainsKey(id)) { templates.Add(id, ressList); } }); return(templates); }
private void ScanTemplates(EcfBlock templateRootBlock, Dictionary <int, double> ressList, double multiplyer) { var templateName = templateRootBlock.Attr.FirstOrDefault(A => A.Name == "Name")?.Value.ToString(); bool.TryParse(templateRootBlock.Attr.FirstOrDefault(A => A.Name == "BaseItem")?.Value.ToString(), out var isBaseItem); templateRootBlock.Childs? .FirstOrDefault(C => C.Key == "Child Inputs").Value?.Attr? .ForEach(C => { if (C.Name.ToString() == templateName) { return; } if (!isBaseItem && FlatConfigTemplatesByName.TryGetValue(C.Name, out var recipe)) { bool.TryParse(recipe.Attr.FirstOrDefault(A => A.Name == "BaseItem")?.Value.ToString(), out var isSubBaseItem); if (!isSubBaseItem) { var recipeMultiplyer = multiplyer * (int)C.Value; if (recipe.Values.TryGetValue("OutputCount", out var outputCount)) { recipeMultiplyer /= (int)outputCount; } ScanTemplates(recipe, ressList, recipeMultiplyer); return; } } if (!FlatConfigBlockByName.TryGetValue(C.Name, out var ressource)) { return; } if (!ressource.Values.TryGetValue("Id", out var ressId)) { return; } if (ressList.TryGetValue((int)ressId, out var count)) { ressList[(int)ressId] = count + multiplyer * (int)C.Value; } else { ressList.Add((int)ressId, multiplyer * (int)C.Value); } }); }