Trap.java 3.5 KB

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