EffectSignet.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 com.l2jserver.gameserver.skills.effects;
  16. import javolution.util.FastList;
  17. import com.l2jserver.gameserver.datatables.SkillTable;
  18. import com.l2jserver.gameserver.model.L2Effect;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2EffectPointInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.skills.Env;
  26. import com.l2jserver.gameserver.skills.l2skills.L2SkillSignet;
  27. import com.l2jserver.gameserver.skills.l2skills.L2SkillSignetCasttime;
  28. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  29. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  30. /**
  31. * @authors Forsaiken, Sami
  32. */
  33. public class EffectSignet extends L2Effect
  34. {
  35. private L2Skill _skill;
  36. private L2EffectPointInstance _actor;
  37. private boolean _srcInArena;
  38. public EffectSignet(Env env, EffectTemplate template)
  39. {
  40. super(env, template);
  41. }
  42. /**
  43. *
  44. * @see com.l2jserver.gameserver.model.L2Effect#getEffectType()
  45. */
  46. @Override
  47. public L2EffectType getEffectType()
  48. {
  49. return L2EffectType.SIGNET_EFFECT;
  50. }
  51. /**
  52. *
  53. * @see com.l2jserver.gameserver.model.L2Effect#onStart()
  54. */
  55. @Override
  56. public boolean onStart()
  57. {
  58. if (getSkill() instanceof L2SkillSignet)
  59. _skill = SkillTable.getInstance().getInfo(((L2SkillSignet) getSkill()).effectId, getLevel());
  60. else if (getSkill() instanceof L2SkillSignetCasttime)
  61. _skill = SkillTable.getInstance().getInfo(((L2SkillSignetCasttime) getSkill()).effectId, getLevel());
  62. _actor = (L2EffectPointInstance) getEffected();
  63. _srcInArena = (getEffector().isInsideZone(L2Character.ZONE_PVP) && !getEffector().isInsideZone(L2Character.ZONE_SIEGE));
  64. return true;
  65. }
  66. /**
  67. *
  68. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  69. */
  70. @Override
  71. public boolean onActionTime()
  72. {
  73. if (_skill == null)
  74. return true;
  75. int mpConsume = _skill.getMpConsume();
  76. if (mpConsume > getEffector().getCurrentMp())
  77. {
  78. getEffector().sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP));
  79. return false;
  80. }
  81. getEffector().reduceCurrentMp(mpConsume);
  82. FastList<L2Character> targets = FastList.newInstance();
  83. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getSkillRadius()))
  84. {
  85. if (cha == null)
  86. continue;
  87. if (_skill.isOffensive() && !L2Skill.checkForAreaOffensiveSkills(getEffector(), cha, _skill, _srcInArena))
  88. continue;
  89. // there doesn't seem to be a visible effect with MagicSkillLaunched packet...
  90. _actor.broadcastPacket(new MagicSkillUse(_actor, cha, _skill.getId(), _skill.getLevel(), 0, 0));
  91. targets.add(cha);
  92. }
  93. if (!targets.isEmpty())
  94. getEffector().callSkill(_skill, targets.toArray(new L2Character[targets.size()]));
  95. FastList.recycle(targets);
  96. return true;
  97. }
  98. /**
  99. *
  100. * @see com.l2jserver.gameserver.model.L2Effect#onExit()
  101. */
  102. @Override
  103. public void onExit()
  104. {
  105. if (_actor != null)
  106. _actor.deleteMe();
  107. }
  108. }