EffectSignetAntiSummon.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.network.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. /**
  37. *
  38. * @see net.sf.l2j.gameserver.model.L2Effect#getEffectType()
  39. */
  40. @Override
  41. public EffectType getEffectType()
  42. {
  43. return EffectType.SIGNET_GROUND;
  44. }
  45. /**
  46. *
  47. * @see net.sf.l2j.gameserver.model.L2Effect#onStart()
  48. */
  49. @Override
  50. public void onStart()
  51. {
  52. _actor = (L2EffectPointInstance) getEffected();
  53. }
  54. /**
  55. *
  56. * @see net.sf.l2j.gameserver.model.L2Effect#onActionTime()
  57. */
  58. @Override
  59. public boolean onActionTime()
  60. {
  61. if (getCount() == getTotalCount() - 1)
  62. return true; // do nothing first time
  63. int mpConsume = getSkill().getMpConsume();
  64. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getSkillRadius()))
  65. {
  66. if (cha == null)
  67. continue;
  68. if (cha instanceof L2PlayableInstance)
  69. {
  70. L2PcInstance owner = null;
  71. if (cha instanceof L2Summon)
  72. owner = ((L2Summon) cha).getOwner();
  73. else
  74. owner = (L2PcInstance) cha;
  75. if (owner != null && owner.getPet() != null)
  76. {
  77. if (mpConsume > getEffector().getCurrentMp())
  78. {
  79. getEffector().sendPacket(new SystemMessage(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP));
  80. return false;
  81. }
  82. else
  83. getEffector().reduceCurrentMp(mpConsume);
  84. owner.getPet().unSummon(owner);
  85. owner.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, getEffector());
  86. }
  87. }
  88. }
  89. return true;
  90. }
  91. /**
  92. *
  93. * @see net.sf.l2j.gameserver.model.L2Effect#onExit()
  94. */
  95. @Override
  96. public void onExit()
  97. {
  98. if (_actor != null)
  99. {
  100. _actor.deleteMe();
  101. }
  102. }
  103. }