Recipes.java 3.2 KB

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