PreparedEntry.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.multisell;
  16. import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.ADENA_ID;
  17. import java.util.ArrayList;
  18. import com.l2jserver.gameserver.model.L2ItemInstance;
  19. /**
  20. *
  21. * @author DS
  22. *
  23. */
  24. public class PreparedEntry extends Entry
  25. {
  26. private long _taxAmount = 0;
  27. public PreparedEntry(Entry template, L2ItemInstance item, boolean applyTaxes, boolean maintainEnchantment, double taxRate)
  28. {
  29. _entryId = template.getEntryId() * 100000;
  30. if (maintainEnchantment && item != null)
  31. _entryId += item.getEnchantLevel();
  32. ItemInfo info = null;
  33. long adenaAmount = 0;
  34. _ingredients = new ArrayList<Ingredient>(template.getIngredients().size());
  35. for (Ingredient ing : template.getIngredients())
  36. {
  37. if (ing.getItemId() == ADENA_ID)
  38. {
  39. // Tax ingredients added only if taxes enabled
  40. if (ing.isTaxIngredient())
  41. {
  42. // if taxes are to be applied, modify/add the adena count based on the template adena/ancient adena count
  43. if (applyTaxes)
  44. _taxAmount += Math.round(ing.getItemCount() * taxRate);
  45. }
  46. else
  47. adenaAmount += ing.getItemCount();
  48. continue; // do not yet add this adena amount to the list as non-taxIngredient adena might be entered later (order not guaranteed)
  49. }
  50. else if (maintainEnchantment
  51. && item != null
  52. && ing.isArmorOrWeapon())
  53. {
  54. info = new ItemInfo(item);
  55. final Ingredient newIngredient = ing.clone();
  56. newIngredient.setItemInfo(info);
  57. _ingredients.add(newIngredient);
  58. }
  59. else
  60. _ingredients.add(ing);
  61. }
  62. // now add the adena, if any.
  63. adenaAmount += _taxAmount; // do not forget tax
  64. if (adenaAmount > 0)
  65. _ingredients.add(new Ingredient(ADENA_ID, adenaAmount, false, false));
  66. // now copy products
  67. _products = new ArrayList<Ingredient>(template.getProducts().size());
  68. for (Ingredient ing : template.getProducts())
  69. {
  70. if (!ing.isStackable())
  71. _stackable = false;
  72. if (maintainEnchantment && ing.isArmorOrWeapon())
  73. {
  74. final Ingredient newProduct = ing.clone();
  75. newProduct.setItemInfo(info);
  76. _products.add(newProduct);
  77. }
  78. else
  79. _products.add(ing);
  80. }
  81. }
  82. @Override
  83. public final long getTaxAmount()
  84. {
  85. return _taxAmount;
  86. }
  87. }