EffectSignetAntiSummon.java 3.2 KB

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