Recipes.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 com.l2jserver.gameserver.datatables.RecipeData;
  17. import com.l2jserver.gameserver.handler.IItemHandler;
  18. import com.l2jserver.gameserver.model.L2RecipeList;
  19. import com.l2jserver.gameserver.model.actor.L2Playable;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * @author Zoey76
  26. */
  27. public class Recipes implements IItemHandler
  28. {
  29. @Override
  30. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  31. {
  32. if (!playable.isPlayer())
  33. {
  34. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  35. return false;
  36. }
  37. final L2PcInstance activeChar = playable.getActingPlayer();
  38. if (activeChar.isInCraftMode())
  39. {
  40. activeChar.sendPacket(SystemMessageId.CANT_ALTER_RECIPEBOOK_WHILE_CRAFTING);
  41. return false;
  42. }
  43. final L2RecipeList rp = RecipeData.getInstance().getRecipeByItemId(item.getItemId());
  44. if (rp == null)
  45. {
  46. return false;
  47. }
  48. if (activeChar.hasRecipeList(rp.getId()))
  49. {
  50. activeChar.sendPacket(SystemMessageId.RECIPE_ALREADY_REGISTERED);
  51. return false;
  52. }
  53. boolean canCraft = false;
  54. boolean recipeLevel = false;
  55. boolean recipeLimit = false;
  56. if (rp.isDwarvenRecipe())
  57. {
  58. canCraft = activeChar.hasDwarvenCraft();
  59. recipeLevel = (rp.getLevel() > activeChar.getDwarvenCraft());
  60. recipeLimit = (activeChar.getDwarvenRecipeBook().length >= activeChar.getDwarfRecipeLimit());
  61. }
  62. else
  63. {
  64. canCraft = activeChar.hasCommonCraft();
  65. recipeLevel = (rp.getLevel() > activeChar.getCommonCraft());
  66. recipeLimit = (activeChar.getCommonRecipeBook().length >= activeChar.getCommonRecipeLimit());
  67. }
  68. if (!canCraft)
  69. {
  70. activeChar.sendPacket(SystemMessageId.CANT_REGISTER_NO_ABILITY_TO_CRAFT);
  71. return false;
  72. }
  73. if (recipeLevel)
  74. {
  75. activeChar.sendPacket(SystemMessageId.CREATE_LVL_TOO_LOW_TO_REGISTER);
  76. return false;
  77. }
  78. if (recipeLimit)
  79. {
  80. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.UP_TO_S1_RECIPES_CAN_REGISTER);
  81. sm.addNumber(rp.isDwarvenRecipe() ? activeChar.getDwarfRecipeLimit() : activeChar.getCommonRecipeLimit());
  82. activeChar.sendPacket(sm);
  83. return false;
  84. }
  85. if (rp.isDwarvenRecipe())
  86. {
  87. activeChar.registerDwarvenRecipeList(rp, true);
  88. }
  89. else
  90. {
  91. activeChar.registerCommonRecipeList(rp, true);
  92. }
  93. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  94. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_ADDED);
  95. sm.addItemName(item);
  96. activeChar.sendPacket(sm);
  97. return true;
  98. }
  99. }