SignetAntiSummon.java 2.8 KB

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