Trap.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Object;
  19. import net.sf.l2j.gameserver.model.L2Skill;
  20. import net.sf.l2j.gameserver.model.L2Trap;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2TrapInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.templates.L2SkillType;
  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. /**
  34. *
  35. * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
  36. */
  37. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  38. {
  39. if (activeChar == null || skill == null)
  40. return;
  41. switch (skill.getSkillType())
  42. {
  43. case DETECT_TRAP:
  44. {
  45. for (int index = 0; index < targets.length; index++)
  46. {
  47. L2Character target = (L2Character) targets[index];
  48. if (!(target instanceof L2TrapInstance))
  49. continue;
  50. if (target.isAlikeDead())
  51. continue;
  52. if (((L2Trap) target).getLevel() <= skill.getPower())
  53. {
  54. (((L2Trap) target)).setDetected();
  55. if (activeChar instanceof L2PcInstance)
  56. activeChar.sendMessage("A Trap has been detected!");
  57. }
  58. }
  59. break;
  60. }
  61. case REMOVE_TRAP:
  62. {
  63. for (int index = 0; index < targets.length; index++)
  64. {
  65. L2Character target = (L2Character) targets[index];
  66. if (!(target instanceof L2Trap))
  67. continue;
  68. if (!((L2Trap) target).isDetected())
  69. continue;
  70. if (((L2Trap) target).getLevel() > skill.getPower())
  71. continue;
  72. L2PcInstance trapOwner = null;
  73. L2Trap trap = null;
  74. trapOwner = ((L2Trap) target).getOwner();
  75. trap = trapOwner.getTrap();
  76. trap.unSummon(trapOwner);
  77. if (activeChar instanceof L2PcInstance)
  78. ((L2PcInstance) activeChar).sendPacket(new SystemMessage(SystemMessageId.A_TRAP_DEVICE_HAS_BEEN_STOPPED));
  79. }
  80. }
  81. }
  82. }
  83. /**
  84. *
  85. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  86. */
  87. public L2SkillType[] getSkillIds()
  88. {
  89. return SKILL_IDS;
  90. }
  91. }