Recipes.java 3.5 KB

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