Trap.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 handlers.skillhandlers;
  16. import com.l2jserver.gameserver.handler.ISkillHandler;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.L2Trap;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.quest.Quest;
  22. import com.l2jserver.gameserver.model.quest.Quest.TrapAction;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.skills.L2SkillType;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. public class Trap implements ISkillHandler
  27. {
  28. private static final L2SkillType[] SKILL_IDS =
  29. {
  30. L2SkillType.DETECT_TRAP,
  31. L2SkillType.REMOVE_TRAP
  32. };
  33. @Override
  34. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  35. {
  36. if (activeChar == null || skill == null)
  37. return;
  38. switch (skill.getSkillType())
  39. {
  40. case DETECT_TRAP:
  41. {
  42. for (L2Character target: activeChar.getKnownList().getKnownCharactersInRadius(skill.getSkillRadius()))
  43. {
  44. if (!(target instanceof L2Trap))
  45. continue;
  46. if (target.isAlikeDead())
  47. continue;
  48. final L2Trap trap = (L2Trap)target;
  49. if (trap.getLevel() <= skill.getPower())
  50. trap.setDetected(activeChar);
  51. }
  52. break;
  53. }
  54. case REMOVE_TRAP:
  55. {
  56. for (L2Character target: (L2Character[]) targets)
  57. {
  58. if (!(target instanceof L2Trap))
  59. continue;
  60. if (target.isAlikeDead())
  61. continue;
  62. final L2Trap trap = (L2Trap)target;
  63. if (!trap.canSee(activeChar))
  64. {
  65. if (activeChar instanceof L2PcInstance)
  66. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  67. continue;
  68. }
  69. if (trap.getLevel() > skill.getPower())
  70. continue;
  71. if (trap.getTemplate().getEventQuests(Quest.QuestEventType.ON_TRAP_ACTION) != null)
  72. for (Quest quest : trap.getTemplate().getEventQuests(Quest.QuestEventType.ON_TRAP_ACTION))
  73. quest.notifyTrapAction(trap, activeChar, TrapAction.TRAP_DISARMED);
  74. trap.unSummon();
  75. if (activeChar instanceof L2PcInstance)
  76. activeChar.sendPacket(SystemMessageId.A_TRAP_DEVICE_HAS_BEEN_STOPPED);
  77. }
  78. }
  79. }
  80. }
  81. @Override
  82. public L2SkillType[] getSkillIds()
  83. {
  84. return SKILL_IDS;
  85. }
  86. }