final int level = Integer.parseInt(element.attributeValue("level"));
final int mpConsume = element.attributeValue("mp_consume") == null ? 0 : Integer.parseInt(element.attributeValue("mp_consume"));
final int successRate = Integer.parseInt(element.attributeValue("success_rate"));
final int itemId = Integer.parseInt(element.attributeValue("item_id"));
final boolean isDwarven = element.attributeValue("is_dwarven") == null ? false : Boolean.parseBoolean(element.attributeValue("is_dwarven"));
RecipeTemplate recipe = new RecipeTemplate(id, level, mpConsume, successRate, itemId, isDwarven);
for (Iterator<Element> subIterator = element.elementIterator(); subIterator.hasNext();)
{
Element subElement = subIterator.next();
if ("materials".equalsIgnoreCase(subElement.getName()))
{
for (Element e : subElement.elements())
{
if ("item".equalsIgnoreCase(e.getName()))
{
int item_id = Integer.parseInt(e.attributeValue("id"));
long count = Long.parseLong(e.attributeValue("count"));
recipe.addMaterial(new RecipeComponent(item_id, count));
}
}
}
else if ("products".equalsIgnoreCase(subElement.getName()))
{
for (Element e : subElement.elements())
{
if ("item".equalsIgnoreCase(e.getName()))
{
int item_id = Integer.parseInt(e.attributeValue("id"));
long count = Long.parseLong(e.attributeValue("count"));
int chance = Integer.parseInt(e.attributeValue("chance"));
recipe.addProduct(new RecipeComponent(item_id, count, chance));
}
}
}
else if ("npc_fee".equalsIgnoreCase(subElement.getName()))
{
for (Element e : subElement.elements())
{
if ("item".equalsIgnoreCase(e.getName()))
{
int item_id = Integer.parseInt(e.attributeValue("id"));
long count = Long.parseLong(e.attributeValue("count"));
recipe.addNpcFee(new RecipeComponent(item_id, count));
}
}
}
}
getHolder().addRecipe(recipe);