Trap.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2004-2013 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.skillhandlers;
  20. import com.l2jserver.gameserver.handler.ISkillHandler;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.Quest.TrapAction;
  26. import com.l2jserver.gameserver.model.skills.L2Skill;
  27. import com.l2jserver.gameserver.model.skills.L2SkillType;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. public class Trap implements ISkillHandler
  30. {
  31. private static final L2SkillType[] SKILL_IDS =
  32. {
  33. L2SkillType.DETECT_TRAP,
  34. L2SkillType.REMOVE_TRAP
  35. };
  36. @Override
  37. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  38. {
  39. if ((activeChar == null) || (skill == null))
  40. {
  41. return;
  42. }
  43. switch (skill.getSkillType())
  44. {
  45. case DETECT_TRAP:
  46. {
  47. for (L2Character target : activeChar.getKnownList().getKnownCharactersInRadius(skill.getAffectRange()))
  48. {
  49. if (!target.isTrap())
  50. {
  51. continue;
  52. }
  53. if (target.isAlikeDead())
  54. {
  55. continue;
  56. }
  57. final L2TrapInstance trap = (L2TrapInstance) target;
  58. if (trap.getLevel() <= skill.getPower())
  59. {
  60. trap.setDetected(activeChar);
  61. }
  62. }
  63. break;
  64. }
  65. case REMOVE_TRAP:
  66. {
  67. for (L2Character target : (L2Character[]) targets)
  68. {
  69. if (!target.isTrap())
  70. {
  71. continue;
  72. }
  73. if (target.isAlikeDead())
  74. {
  75. continue;
  76. }
  77. final L2TrapInstance trap = (L2TrapInstance) target;
  78. if (!trap.canBeSeen(activeChar))
  79. {
  80. if (activeChar.isPlayer())
  81. {
  82. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  83. }
  84. continue;
  85. }
  86. if (trap.getLevel() > skill.getPower())
  87. {
  88. continue;
  89. }
  90. if (trap.getTemplate().getEventQuests(Quest.QuestEventType.ON_TRAP_ACTION) != null)
  91. {
  92. for (Quest quest : trap.getTemplate().getEventQuests(Quest.QuestEventType.ON_TRAP_ACTION))
  93. {
  94. quest.notifyTrapAction(trap, activeChar, TrapAction.TRAP_DISARMED);
  95. }
  96. }
  97. trap.unSummon();
  98. if (activeChar.isPlayer())
  99. {
  100. activeChar.sendPacket(SystemMessageId.A_TRAP_DEVICE_HAS_BEEN_STOPPED);
  101. }
  102. }
  103. }
  104. }
  105. }
  106. @Override
  107. public L2SkillType[] getSkillIds()
  108. {
  109. return SKILL_IDS;
  110. }
  111. }