Signet.java 3.5 KB

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