SignetAntiSummon.java 2.9 KB

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