EffectSignetAntiSummon.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.skills.effects;
  16. import net.sf.l2j.gameserver.ai.CtrlEvent;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  19. import net.sf.l2j.gameserver.model.L2Summon;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2EffectPointInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.skills.Env;
  26. /**
  27. * @author Forsaiken
  28. */
  29. final class EffectSignetAntiSummon extends L2Effect
  30. {
  31. private L2EffectPointInstance _actor;
  32. public EffectSignetAntiSummon(Env env, EffectTemplate template)
  33. {
  34. super(env, template);
  35. }
  36. @Override
  37. public EffectType getEffectType()
  38. {
  39. return EffectType.SIGNET_GROUND;
  40. }
  41. @Override
  42. public void onStart()
  43. {
  44. _actor = (L2EffectPointInstance)getEffected();
  45. }
  46. @Override
  47. public boolean onActionTime()
  48. {
  49. if (getCount() == getTotalCount() - 1) return true; // do nothing first time
  50. int mpConsume = getSkill().getMpConsume();
  51. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getSkillRadius()))
  52. {
  53. if (cha == null)
  54. continue;
  55. if (cha instanceof L2PlayableInstance)
  56. {
  57. L2PcInstance owner = null;
  58. if (cha instanceof L2Summon)
  59. owner = ((L2Summon)cha).getOwner();
  60. else
  61. owner = (L2PcInstance)cha;
  62. if (owner != null && owner.getPet() != null)
  63. {
  64. if (mpConsume > getEffector().getCurrentMp())
  65. {
  66. getEffector().sendPacket(new SystemMessage(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP));
  67. return false;
  68. }
  69. else
  70. getEffector().reduceCurrentMp(mpConsume);
  71. owner.getPet().unSummon(owner);
  72. owner.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, getEffector());
  73. }
  74. }
  75. }
  76. return true;
  77. }
  78. @Override
  79. public void onExit()
  80. {
  81. if (_actor != null)
  82. {
  83. _actor.deleteMe();
  84. }
  85. }
  86. }