ExtractableItems.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 handlers.itemhandlers;
  16. import java.util.List;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.datatables.ItemTable;
  20. import com.l2jserver.gameserver.handler.IItemHandler;
  21. import com.l2jserver.gameserver.model.L2ExtractableProduct;
  22. import com.l2jserver.gameserver.model.actor.L2Playable;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.items.L2EtcItem;
  25. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.util.Rnd;
  28. /**
  29. * @author FBIagent 11/12/2006
  30. */
  31. public class ExtractableItems implements IItemHandler
  32. {
  33. private static Logger _log = Logger.getLogger(ItemTable.class.getName());
  34. @Override
  35. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  36. {
  37. if (!(playable instanceof L2PcInstance))
  38. {
  39. return false;
  40. }
  41. final L2PcInstance activeChar = playable.getActingPlayer();
  42. final L2EtcItem etcitem = (L2EtcItem) item.getItem();
  43. final List<L2ExtractableProduct> exitem = etcitem.getExtractableItems();
  44. if (exitem == null)
  45. {
  46. _log.info("No extractable data defined for " + etcitem);
  47. return false;
  48. }
  49. //destroy item
  50. if (!activeChar.destroyItem("Extract", item.getObjectId(), 1, activeChar, true))
  51. {
  52. return false;
  53. }
  54. boolean created = false;
  55. // calculate extraction
  56. int min;
  57. int max;
  58. int createitemAmount;
  59. for (L2ExtractableProduct expi : exitem)
  60. {
  61. if (Rnd.get(100000) <= expi.getChance())
  62. {
  63. min = (int) (expi.getMin() * Config.RATE_EXTRACTABLE);
  64. max = (int) (expi.getMax() * Config.RATE_EXTRACTABLE);
  65. createitemAmount = (max == min) ? min : (Rnd.get(max - min + 1) + min);
  66. activeChar.addItem("Extract", expi.getId(), createitemAmount, activeChar, true);
  67. created = true;
  68. }
  69. }
  70. if (!created)
  71. {
  72. activeChar.sendPacket(SystemMessageId.NOTHING_INSIDE_THAT);
  73. }
  74. return true;
  75. }
  76. }