Search in sources :

Example 1 with RecipeVersion

use of delta.games.lotro.lore.crafting.recipes.RecipeVersion in project lotro-tools by dmorcellet.

the class ResolveItemLinksInRecipes method handleRecipes.

private void handleRecipes(ItemsResolver resolver) {
    // Load recipes
    RecipesManager rMgr = RecipesManager.getInstance();
    File recipesDir = LotroCoreConfig.getInstance().getRecipesDir();
    FileFilter fileFilter = new ExtensionPredicate("xml");
    File[] recipeFiles = recipesDir.listFiles(fileFilter);
    if (recipeFiles != null) {
        Set<String> missingKeys = new HashSet<String>();
        for (File recipeFile : recipeFiles) {
            String idStr = recipeFile.getName();
            idStr = idStr.substring(0, idStr.length() - 4);
            int id = NumericTools.parseInt(idStr, -1);
            if (id != -1) {
                Recipe recipe = rMgr.getRecipe(Integer.valueOf(id));
                List<Ingredient> ingredients = recipe.getIngredients();
                for (Ingredient ingredient : ingredients) {
                    ItemReference itemRef = ingredient.getItem();
                    handleItemRef(resolver, missingKeys, itemRef);
                }
                /*
          ItemReference scroll=recipe.getRecipeScroll();
          if (scroll!=null)
          {
            handleItemRef(ids,missingKeys,scroll);
          }
          */
                List<RecipeVersion> versions = recipe.getVersions();
                for (RecipeVersion version : versions) {
                    CraftingResult regular = version.getRegular();
                    if (regular != null) {
                        ItemReference ref = regular.getItem();
                        handleItemRef(resolver, missingKeys, ref);
                    }
                    CraftingResult critical = version.getCritical();
                    if (critical != null) {
                        ItemReference ref = critical.getItem();
                        handleItemRef(resolver, missingKeys, ref);
                    }
                }
            }
        }
        List<String> sortedKeys = new ArrayList<String>(missingKeys);
        Collections.sort(sortedKeys);
        for (String missingKey : sortedKeys) {
            System.out.println("Missing : " + missingKey);
        }
        System.out.println("Missing : " + sortedKeys.size());
    }
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) ArrayList(java.util.ArrayList) ExtensionPredicate(delta.common.utils.files.filter.ExtensionPredicate) RecipesManager(delta.games.lotro.lore.crafting.recipes.RecipesManager) ItemReference(delta.games.lotro.lore.crafting.recipes.ItemReference) Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) RecipeVersion(delta.games.lotro.lore.crafting.recipes.RecipeVersion) FileFilter(java.io.FileFilter) File(java.io.File) CraftingResult(delta.games.lotro.lore.crafting.recipes.CraftingResult) HashSet(java.util.HashSet)

Example 2 with RecipeVersion

use of delta.games.lotro.lore.crafting.recipes.RecipeVersion in project lotro-tools by dmorcellet.

the class RecipePageParser method parseRecipeSection.

private Recipe parseRecipeSection(Element recipeSection) {
    Recipe ret = null;
    try {
        _recipe = new Recipe();
        // Element mainIconElement=JerichoHtmlUtils.findElementByTagNameAndAttributeValue(recipeSection,HTMLElementName.DIV,"class","mainicon");
        List<Element> officialSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(recipeSection, HTMLElementName.DIV, "class", "officialsection");
        // 1 - summary
        // 2 - ingredients
        // 3 - results
        int nbSections = officialSections.size();
        if (nbSections != 3) {
            System.out.println("Warning: found " + nbSections + " sections!");
        }
        Element summarySection = officialSections.get(0);
        parseRecipeSummary(summarySection);
        // System.out.println("Ingredients:");
        Element ingredientsSection = officialSections.get(1);
        List<Ingredient> ingredients = parseIngredients(ingredientsSection);
        _recipe.setIngredients(ingredients);
        // System.out.println("Results:");
        Element resultsSection = officialSections.get(2);
        List<RecipeVersion> results = parseResults(resultsSection);
        _recipe.setVersions(results);
        ret = _recipe;
        _recipe = null;
    } catch (Exception e) {
        ret = null;
        _logger.error("Recipe [" + _key + "]. Cannot parse recipe section!", e);
    }
    return ret;
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) Ingredient(delta.games.lotro.lore.crafting.recipes.Ingredient) Element(net.htmlparser.jericho.Element) RecipeVersion(delta.games.lotro.lore.crafting.recipes.RecipeVersion)

Example 3 with RecipeVersion

use of delta.games.lotro.lore.crafting.recipes.RecipeVersion in project lotro-tools by dmorcellet.

the class RecipePageParser method parseResults.

private List<RecipeVersion> parseResults(Element resultsSection) {
    /*
<tr class="resultrow"> // or "resultrow critical"
<td class="resicon"><a href="/wiki/Tool:Ancient_Steel_Scholar's_Glass"><img class="icon" rel="" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/item/tool/eq_craft_tool_rare_scholars_glass_tier5.png"></img></a></td>
<td class="restype">regular success</td>  // or critical success
<td class="resquan">x1</td>
<td class="resname"><a href="/wiki/Tool:Ancient_Steel_Scholar's_Glass"></a></td></tr>
     */
    List<RecipeVersion> versions = new ArrayList<RecipeVersion>();
    RecipeVersion version = new RecipeVersion();
    versions.add(version);
    List<Element> rows = resultsSection.getAllElements(HTMLElementName.TR);
    for (Element row : rows) {
        StartTag tag = row.getStartTag();
        String value = tag.getAttributeValue("class");
        if ("resultrow".equals(value)) {
            Element header = JerichoHtmlUtils.findElementByTagName(row, HTMLElementName.TH);
            if (header != null) {
                version = new RecipeVersion();
                versions.add(version);
            // System.out.println("OR");
            } else {
                CraftingResult regular = parseResultItem(row, false);
                version.setRegular(regular);
            }
        } else if ("resultrow critical".equals(value)) {
            CraftingResult critical = parseResultItem(row, true);
            version.setCritical(critical);
        }
    }
    return versions;
}
Also used : Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList) RecipeVersion(delta.games.lotro.lore.crafting.recipes.RecipeVersion) CraftingResult(delta.games.lotro.lore.crafting.recipes.CraftingResult) StartTag(net.htmlparser.jericho.StartTag)

Aggregations

RecipeVersion (delta.games.lotro.lore.crafting.recipes.RecipeVersion)3 CraftingResult (delta.games.lotro.lore.crafting.recipes.CraftingResult)2 Ingredient (delta.games.lotro.lore.crafting.recipes.Ingredient)2 Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)2 ArrayList (java.util.ArrayList)2 Element (net.htmlparser.jericho.Element)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 ItemReference (delta.games.lotro.lore.crafting.recipes.ItemReference)1 RecipesManager (delta.games.lotro.lore.crafting.recipes.RecipesManager)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 HashSet (java.util.HashSet)1 StartTag (net.htmlparser.jericho.StartTag)1