CharmOfCourage.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.handler.IItemHandler;
  21. import com.l2jserver.gameserver.model.actor.L2Playable;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.EtcStatusUpdate;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * Charm Of Courage Handler
  29. * @author Zealar
  30. */
  31. public class CharmOfCourage implements IItemHandler
  32. {
  33. @Override
  34. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  35. {
  36. if (!playable.isPlayer())
  37. {
  38. return false;
  39. }
  40. final L2PcInstance activeChar = playable.getActingPlayer();
  41. int level = activeChar.getLevel();
  42. final int itemLevel = item.getItem().getItemGrade().getId();
  43. if (level < 20)
  44. {
  45. level = 0;
  46. }
  47. else if (level < 40)
  48. {
  49. level = 1;
  50. }
  51. else if (level < 52)
  52. {
  53. level = 2;
  54. }
  55. else if (level < 61)
  56. {
  57. level = 3;
  58. }
  59. else if (level < 76)
  60. {
  61. level = 4;
  62. }
  63. else
  64. {
  65. level = 5;
  66. }
  67. if (itemLevel < level)
  68. {
  69. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  70. sm.addItemName(item.getId());
  71. activeChar.sendPacket(sm);
  72. return false;
  73. }
  74. if (activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), 1, null, false))
  75. {
  76. activeChar.setCharmOfCourage(true);
  77. activeChar.sendPacket(new EtcStatusUpdate(activeChar));
  78. return true;
  79. }
  80. return false;
  81. }
  82. }