Trap.java 3.2 KB

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