ExtractableItems.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.isPlayer())
  38. {
  39. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  40. return false;
  41. }
  42. final L2PcInstance activeChar = playable.getActingPlayer();
  43. final L2EtcItem etcitem = (L2EtcItem) item.getItem();
  44. final List<L2ExtractableProduct> exitem = etcitem.getExtractableItems();
  45. if (exitem == null)
  46. {
  47. _log.info("No extractable data defined for " + etcitem);
  48. return false;
  49. }
  50. // destroy item
  51. if (!activeChar.destroyItem("Extract", item.getObjectId(), 1, activeChar, true))
  52. {
  53. return false;
  54. }
  55. boolean created = false;
  56. // calculate extraction
  57. int min;
  58. int max;
  59. int createitemAmount;
  60. for (L2ExtractableProduct expi : exitem)
  61. {
  62. if (Rnd.get(100000) <= expi.getChance())
  63. {
  64. min = (int) (expi.getMin() * Config.RATE_EXTRACTABLE);
  65. max = (int) (expi.getMax() * Config.RATE_EXTRACTABLE);
  66. createitemAmount = (max == min) ? min : (Rnd.get(max - min + 1) + min);
  67. activeChar.addItem("Extract", expi.getId(), createitemAmount, activeChar, true);
  68. created = true;
  69. }
  70. }
  71. if (!created)
  72. {
  73. activeChar.sendPacket(SystemMessageId.NOTHING_INSIDE_THAT);
  74. }
  75. return true;
  76. }
  77. }