use of delta.games.lotro.lore.crafting.recipes.ItemReference in project lotro-tools by dmorcellet.
the class RecipePageParser method parseRecipeSummary.
private void parseRecipeSummary(Element summarySection) {
List<Element> divs = summarySection.getAllElements(HTMLElementName.DIV);
for (Element div : divs) {
String contents = CharacterReference.decodeCollapseWhiteSpace(div.getContent());
if (contents.contains("Recipe for")) {
// Profession
String profession = null;
Element a = JerichoHtmlUtils.findElementByTagName(div, HTMLElementName.A);
if (a != null) {
profession = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
_recipe.setProfession(profession);
}
} else if (contents.contains("One time use")) {
_recipe.setOneTimeUse(true);
} else if (contents.contains("Learned from")) {
Element a = JerichoHtmlUtils.findElementByTagName(div, HTMLElementName.A);
String itemURL = a.getAttributeValue("href");
String itemId = extractItemIdentifier(itemURL);
if (itemId != null) {
ItemReference scroll = new ItemReference();
String scrollName = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
scroll.setName(scrollName);
scroll.setItemKey(itemId);
_recipe.setRecipeScroll(scroll);
}
}
}
// Recipe name
String recipeName = null;
Element recipeNameElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(summarySection, HTMLElementName.DIV, "class", "lorebooktitle");
if (recipeNameElement != null) {
recipeName = CharacterReference.decodeCollapseWhiteSpace(recipeNameElement.getContent());
if (recipeName != null) {
if (recipeName.startsWith(RECIPE_SEED)) {
recipeName = recipeName.substring(RECIPE_SEED.length()).trim();
}
}
}
_recipe.setName(recipeName);
// _recipe.setIdentifier(identifier);
// _recipe.setTier(tier);
}
use of delta.games.lotro.lore.crafting.recipes.ItemReference in project lotro-tools by dmorcellet.
the class RecipePageParser method parseIngredient.
private Ingredient parseIngredient(Element ingredientRow, boolean optional) {
Ingredient ingredient = new Ingredient();
ingredient.setOptional(optional);
ItemReference itemRef = new ItemReference();
ingredient.setItem(itemRef);
Element ingredientIcon = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingicon");
if (ingredientIcon != null) {
Element img = JerichoHtmlUtils.findElementByTagName(ingredientIcon, HTMLElementName.IMG);
if (img != null) {
String itemIcon = img.getAttributeValue("src");
itemRef.setIcon(itemIcon);
// System.out.println("Icon: "+itemIcon);
}
}
Element ingredientQuantity = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingquan");
if (ingredientQuantity != null) {
String quantityStr = CharacterReference.decodeCollapseWhiteSpace(ingredientQuantity.getContent());
int quantity = parseQuantityString(quantityStr);
ingredient.setQuantity(quantity);
// System.out.println("Quantity: "+quantity);
}
Element ingredientName = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(ingredientRow, HTMLElementName.TD, "class", "ingname");
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);
}
return ingredient;
}
use of delta.games.lotro.lore.crafting.recipes.ItemReference 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());
}
}
use of delta.games.lotro.lore.crafting.recipes.ItemReference 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;
}
Aggregations