PreparedEntry.java 3.1 KB

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