TrapRemove.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.effecthandlers;
  20. import com.l2jserver.gameserver.enums.TrapAction;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
  24. import com.l2jserver.gameserver.model.conditions.Condition;
  25. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  26. import com.l2jserver.gameserver.model.events.EventDispatcher;
  27. import com.l2jserver.gameserver.model.events.impl.character.trap.OnTrapAction;
  28. import com.l2jserver.gameserver.model.skills.BuffInfo;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. /**
  31. * Trap Remove effect implementation.
  32. * @author UnAfraid
  33. */
  34. public final class TrapRemove extends AbstractEffect
  35. {
  36. private final int _power;
  37. public TrapRemove(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  38. {
  39. super(attachCond, applyCond, set, params);
  40. if (params.isEmpty())
  41. {
  42. throw new IllegalArgumentException(getClass().getSimpleName() + ": effect without power!");
  43. }
  44. _power = params.getInt("power");
  45. }
  46. @Override
  47. public boolean isInstant()
  48. {
  49. return true;
  50. }
  51. @Override
  52. public void onStart(BuffInfo info)
  53. {
  54. final L2Character target = info.getEffected();
  55. if (!target.isTrap())
  56. {
  57. return;
  58. }
  59. if (target.isAlikeDead())
  60. {
  61. return;
  62. }
  63. final L2TrapInstance trap = (L2TrapInstance) target;
  64. if (!trap.canBeSeen(info.getEffector()))
  65. {
  66. if (info.getEffector().isPlayer())
  67. {
  68. info.getEffector().sendPacket(SystemMessageId.INCORRECT_TARGET);
  69. }
  70. return;
  71. }
  72. if (trap.getLevel() > _power)
  73. {
  74. return;
  75. }
  76. // Notify to scripts
  77. EventDispatcher.getInstance().notifyEventAsync(new OnTrapAction(trap, info.getEffector(), TrapAction.TRAP_DISARMED), trap);
  78. trap.unSummon();
  79. if (info.getEffector().isPlayer())
  80. {
  81. info.getEffector().sendPacket(SystemMessageId.A_TRAP_DEVICE_HAS_BEEN_STOPPED);
  82. }
  83. }
  84. }