Recipes.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.RecipeController;
  17. import net.sf.l2j.gameserver.handler.IItemHandler;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.L2RecipeList;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * This class ...
  26. *
  27. * @version $Revision: 1.1.2.5.2.5 $ $Date: 2005/04/06 16:13:51 $
  28. */
  29. public class Recipes implements IItemHandler
  30. {
  31. private final int[] ITEM_IDS;
  32. public Recipes()
  33. {
  34. RecipeController rc = RecipeController.getInstance();
  35. ITEM_IDS = new int[rc.getRecipesCount()];
  36. for (int i = 0; i < rc.getRecipesCount(); i++)
  37. {
  38. ITEM_IDS[i] = rc.getRecipeList(i).getRecipeId();
  39. }
  40. }
  41. /**
  42. *
  43. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  44. */
  45. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  46. {
  47. if (!(playable instanceof L2PcInstance))
  48. return;
  49. L2PcInstance activeChar = (L2PcInstance) playable;
  50. L2RecipeList rp = RecipeController.getInstance().getRecipeByItemId(item.getItemId());
  51. if (activeChar.hasRecipeList(rp.getId()))
  52. {
  53. SystemMessage sm = new SystemMessage(SystemMessageId.RECIPE_ALREADY_REGISTERED);
  54. activeChar.sendPacket(sm);
  55. }
  56. else
  57. {
  58. if (rp.isDwarvenRecipe())
  59. {
  60. if (activeChar.hasDwarvenCraft())
  61. {
  62. if (rp.getLevel() > activeChar.getDwarvenCraft())
  63. {
  64. //can't add recipe, becouse create item level too low
  65. SystemMessage sm = new SystemMessage(SystemMessageId.CREATE_LVL_TOO_LOW_TO_REGISTER);
  66. activeChar.sendPacket(sm);
  67. }
  68. else if (activeChar.getDwarvenRecipeBook().length >= activeChar.getDwarfRecipeLimit())
  69. {
  70. //Up to $s1 recipes can be registered.
  71. SystemMessage sm = new SystemMessage(SystemMessageId.UP_TO_S1_RECIPES_CAN_REGISTER);
  72. sm.addNumber(activeChar.getDwarfRecipeLimit());
  73. activeChar.sendPacket(sm);
  74. }
  75. else
  76. {
  77. activeChar.registerDwarvenRecipeList(rp);
  78. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  79. activeChar.sendMessage("Added recipe \"" + rp.getRecipeName() + "\" to Dwarven RecipeBook");
  80. }
  81. }
  82. else
  83. {
  84. SystemMessage sm = new SystemMessage(SystemMessageId.CANT_REGISTER_NO_ABILITY_TO_CRAFT);
  85. activeChar.sendPacket(sm);
  86. }
  87. }
  88. else
  89. {
  90. if (activeChar.hasCommonCraft())
  91. {
  92. if (rp.getLevel() > activeChar.getCommonCraft())
  93. {
  94. //can't add recipe, becouse create item level too low
  95. SystemMessage sm = new SystemMessage(SystemMessageId.CREATE_LVL_TOO_LOW_TO_REGISTER);
  96. activeChar.sendPacket(sm);
  97. }
  98. else if (activeChar.getCommonRecipeBook().length >= activeChar.getCommonRecipeLimit())
  99. {
  100. //Up to $s1 recipes can be registered.
  101. SystemMessage sm = new SystemMessage(SystemMessageId.UP_TO_S1_RECIPES_CAN_REGISTER);
  102. sm.addNumber(activeChar.getCommonRecipeLimit());
  103. activeChar.sendPacket(sm);
  104. }
  105. else
  106. {
  107. activeChar.registerCommonRecipeList(rp);
  108. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  109. activeChar.sendMessage("Added recipe \"" + rp.getRecipeName() + "\" to Common RecipeBook");
  110. }
  111. }
  112. else
  113. {
  114. SystemMessage sm = new SystemMessage(SystemMessageId.CANT_REGISTER_NO_ABILITY_TO_CRAFT);
  115. activeChar.sendPacket(sm);
  116. }
  117. }
  118. }
  119. }
  120. /**
  121. *
  122. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  123. */
  124. public int[] getItemIds()
  125. {
  126. return ITEM_IDS;
  127. }
  128. }