PreparedEntry.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.items.instance.L2ItemInstance;
  19. /**
  20. * @author DS
  21. */
  22. public class PreparedEntry extends Entry
  23. {
  24. private long _taxAmount = 0;
  25. public PreparedEntry(Entry template, L2ItemInstance item, boolean applyTaxes, boolean maintainEnchantment, double taxRate)
  26. {
  27. _entryId = template.getEntryId() * 100000;
  28. if (maintainEnchantment && (item != null))
  29. {
  30. _entryId += item.getEnchantLevel();
  31. }
  32. ItemInfo info = null;
  33. long adenaAmount = 0;
  34. _ingredients = new ArrayList<>(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. {
  45. _taxAmount += Math.round(ing.getItemCount() * taxRate);
  46. }
  47. }
  48. else
  49. {
  50. adenaAmount += ing.getItemCount();
  51. }
  52. // do not yet add this adena amount to the list as non-taxIngredient adena might be entered later (order not guaranteed)
  53. continue;
  54. }
  55. else if (maintainEnchantment && (item != null) && ing.isArmorOrWeapon())
  56. {
  57. info = new ItemInfo(item);
  58. final Ingredient newIngredient = ing.getCopy();
  59. newIngredient.setItemInfo(info);
  60. _ingredients.add(newIngredient);
  61. }
  62. else
  63. {
  64. final Ingredient newIngredient = ing.getCopy();
  65. _ingredients.add(newIngredient);
  66. }
  67. }
  68. // now add the adena, if any.
  69. adenaAmount += _taxAmount; // do not forget tax
  70. if (adenaAmount > 0)
  71. {
  72. _ingredients.add(new Ingredient(ADENA_ID, adenaAmount, false, false));
  73. }
  74. // now copy products
  75. _products = new ArrayList<>(template.getProducts().size());
  76. for (Ingredient ing : template.getProducts())
  77. {
  78. if (!ing.isStackable())
  79. {
  80. _stackable = false;
  81. }
  82. final Ingredient newProduct = ing.getCopy();
  83. if (maintainEnchantment && ing.isArmorOrWeapon())
  84. {
  85. newProduct.setItemInfo(info);
  86. }
  87. _products.add(newProduct);
  88. }
  89. }
  90. @Override
  91. public final long getTaxAmount()
  92. {
  93. return _taxAmount;
  94. }
  95. }