boolean hasIngredient = false;
for (MultiSellIngredient ing : templateEntry.getIngredients())
{
// Load the ingredient from the template
MultiSellIngredient newIngredient = new MultiSellIngredient(ing);
if (newIngredient.getItemId() == 57 && newIngredient.isTaxIngredient())
{
double taxRate = 0.0;
if (applyTaxes)
{
if (merchant != null && merchant.getIsInTown())
{
taxRate = merchant.getCastle().getTaxRate();
}
}
_transactionTax = (int) Math.round(newIngredient.getItemCount() * taxRate);
totalAdenaCount += _transactionTax;
continue; // Do not yet add this adena amount to the list as non-taxIngredient adena might be entered later (order not guaranteed)
}
else if (ing.getItemId() == 57) // && !ing.isTaxIngredient()
{
totalAdenaCount += newIngredient.getItemCount();
continue; // Do not yet add this adena amount to the list as taxIngredient adena might be entered later (order not guaranteed)
}
// If it is an armor/weapon, modify the enchantment level appropriately, if necessary
else if (maintainEnchantment)
{
L2Item tempItem = ItemTable.getInstance().createDummyItem(newIngredient.getItemId()).getItem();
if (tempItem instanceof L2Armor || tempItem instanceof L2Weapon)
{
newIngredient.setEnchantmentLevel(enchantLevel);
hasIngredient = true;
}
}
// finally, add this ingredient to the entry
newEntry.addIngredient(newIngredient);
}
// Next add the adena amount, if any
if (totalAdenaCount > 0)
{
newEntry.addIngredient(new MultiSellIngredient(57, totalAdenaCount, false, false));
}
// Now modify the enchantment level of products, if necessary
for (MultiSellIngredient ing : templateEntry.getProducts())
{
// Load the ingredient from the template
MultiSellIngredient newIngredient = new MultiSellIngredient(ing);
if (maintainEnchantment && hasIngredient)
{
// If it is an armor/weapon, modify the enchantment level appropriately
// (note, if maintain enchantment is "false" this modification will result to a +0)
L2Item tempItem = ItemTable.getInstance().createDummyItem(newIngredient.getItemId()).getItem();
if (tempItem instanceof L2Armor || tempItem instanceof L2Weapon)
{
if (enchantLevel==0 && maintainEnchantment)
enchantLevel = ing.getEnchantmentLevel();
newIngredient.setEnchantmentLevel(enchantLevel);
}
}
newEntry.addProduct(newIngredient);
}
return newEntry;