EventItem.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2004-2015 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.instancemanager.HandysBlockCheckerManager;
  22. import com.l2jserver.gameserver.model.ArenaParticipantsHolder;
  23. import com.l2jserver.gameserver.model.actor.L2Playable;
  24. import com.l2jserver.gameserver.model.actor.instance.L2BlockInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  27. import com.l2jserver.gameserver.model.skills.Skill;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. public class EventItem implements IItemHandler
  31. {
  32. @Override
  33. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  34. {
  35. if (!playable.isPlayer())
  36. {
  37. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  38. return false;
  39. }
  40. boolean used = false;
  41. final L2PcInstance activeChar = playable.getActingPlayer();
  42. final int itemId = item.getId();
  43. switch (itemId)
  44. {
  45. case 13787: // Handy's Block Checker Bond
  46. used = useBlockCheckerItem(activeChar, item);
  47. break;
  48. case 13788: // Handy's Block Checker Land Mine
  49. used = useBlockCheckerItem(activeChar, item);
  50. break;
  51. default:
  52. _log.warning("EventItemHandler: Item with id: " + itemId + " is not handled");
  53. }
  54. return used;
  55. }
  56. private final boolean useBlockCheckerItem(final L2PcInstance castor, L2ItemInstance item)
  57. {
  58. final int blockCheckerArena = castor.getBlockCheckerArena();
  59. if (blockCheckerArena == -1)
  60. {
  61. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  62. msg.addItemName(item);
  63. castor.sendPacket(msg);
  64. return false;
  65. }
  66. final Skill sk = item.getEtcItem().getSkills()[0].getSkill();
  67. if (sk == null)
  68. {
  69. return false;
  70. }
  71. if (!castor.destroyItem("Consume", item, 1, castor, true))
  72. {
  73. return false;
  74. }
  75. final L2BlockInstance block = (L2BlockInstance) castor.getTarget();
  76. final ArenaParticipantsHolder holder = HandysBlockCheckerManager.getInstance().getHolder(blockCheckerArena);
  77. if (holder != null)
  78. {
  79. final int team = holder.getPlayerTeam(castor);
  80. for (final L2PcInstance pc : block.getKnownList().getKnownPlayersInRadius(sk.getEffectRange()))
  81. {
  82. final int enemyTeam = holder.getPlayerTeam(pc);
  83. if ((enemyTeam != -1) && (enemyTeam != team))
  84. {
  85. sk.applyEffects(castor, pc);
  86. }
  87. }
  88. return true;
  89. }
  90. _log.warning("Char: " + castor.getName() + "[" + castor.getObjectId() + "] has unknown block checker arena");
  91. return false;
  92. }
  93. }