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); } }); }
public EcfBlock MergeRefBlocks(EcfBlock target, EcfBlock source) { if (source == null || source.Values == null) { return(target); } if (source.Values.TryGetValue("Ref", out var refValue) && ConfigBlockByName.TryGetValue(refValue?.ToString(), out var refBlock)) { target = MergeRefBlocks(target, refBlock); } target.MergeWith(source); return(target); }
private void ScanTemplates(ConfigEcfAccess config, EcfBlock templateRootBlock, Dictionary <int, int> ressList) { 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 && config.FlatConfigTemplatesByName.TryGetValue(C.Name.ToString(), out var recipe)) { bool.TryParse(recipe.Attr.FirstOrDefault(A => A.Name == "BaseItem")?.Value.ToString(), out var isSubBaseItem); if (!isSubBaseItem) { ScanTemplates(config, recipe, ressList); return; } } if (!config.FlatConfigBlockByName.TryGetValue(C.Name.ToString(), out var ressource)) { return; } if (!int.TryParse(ressource.Attr.FirstOrDefault(A => A.Name == "Id")?.Value.ToString(), out var ressId)) { return; } if (ressList.TryGetValue(ressId, out var count)) { ressList[ressId] = count + (int)C.Value; } else { ressList.Add(ressId, (int)C.Value); } }); }