Search in sources :

Example 1 with CraftingResult

use of delta.games.lotro.lore.crafting.recipes.CraftingResult 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 CraftingResult

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

the class RecipePageParser method parseResultItem.

private CraftingResult parseResultItem(Element resultRow, boolean critical) {
    CraftingResult result = new CraftingResult();
    result.setCriticalResult(critical);
    ItemReference itemRef = new ItemReference();
    result.setItem(itemRef);
    Element ingredientIcon = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(resultRow, HTMLElementName.TD, "class", "resicon");
    if (ingredientIcon != null) {
        Element img = JerichoHtmlUtils.findElementByTagName(ingredientIcon, HTMLElementName.IMG);
        if (img != null) {
            String itemIcon = img.getAttributeValue("src");
            // System.out.println("Icon: "+itemIcon);
            itemRef.setIcon(itemIcon);
        }
    }
    Element ingredientQuantity = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(resultRow, HTMLElementName.TD, "class", "resquan");
    if (ingredientQuantity != null) {
        String quantityStr = CharacterReference.decodeCollapseWhiteSpace(ingredientQuantity.getContent());
        int quantity = parseQuantityString(quantityStr);
        // System.out.println("Quantity: "+quantity);
        result.setQuantity(quantity);
    }
    Element ingredientName = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(resultRow, HTMLElementName.TD, "class", "resname");
    if (ingredientName != null) {
        Element a = JerichoHtmlUtils.findElementByTagName(ingredientName, HTMLElementName.A);
        String itemURL = a.getAttributeValue("href");
        String itemId = extractItemIdentifier(itemURL);
        itemRef.setItemKey(itemId);
        String itemName = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
        itemRef.setName(itemName);
    }
    // System.out.println(critical?"Critical result":"Regular result");
    return result;
}
Also used : ItemReference(delta.games.lotro.lore.crafting.recipes.ItemReference) Element(net.htmlparser.jericho.Element) CraftingResult(delta.games.lotro.lore.crafting.recipes.CraftingResult)

Example 3 with CraftingResult

use of delta.games.lotro.lore.crafting.recipes.CraftingResult 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

CraftingResult (delta.games.lotro.lore.crafting.recipes.CraftingResult)3 ItemReference (delta.games.lotro.lore.crafting.recipes.ItemReference)2 RecipeVersion (delta.games.lotro.lore.crafting.recipes.RecipeVersion)2 ArrayList (java.util.ArrayList)2 Element (net.htmlparser.jericho.Element)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 Ingredient (delta.games.lotro.lore.crafting.recipes.Ingredient)1 Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)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