int totalAdenaCount = 0;
for (MultiSellIngredient ing : templateEntry.getIngredients())
{
// load the ingredient from the template
MultiSellIngredient newIngredient = L2Multisell.getInstance().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);
}
// finally, add this ingredient to the entry
newEntry.addIngredient(newIngredient);
}
// Next add the adena amount, if any
if (totalAdenaCount > 0)
newEntry.addIngredient(L2Multisell.getInstance().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 = L2Multisell.getInstance().new MultiSellIngredient(ing);
if (maintainEnchantment)
{
// 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))
newIngredient.setEnchantmentLevel(enchantLevel);
}
newEntry.addProduct(newIngredient);
}
return newEntry;
}