Signet.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import javolution.util.FastList;
  21. import com.l2jserver.gameserver.datatables.SkillTable;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2EffectPointInstance;
  24. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  25. import com.l2jserver.gameserver.model.effects.L2Effect;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.skills.L2Skill;
  28. import com.l2jserver.gameserver.model.skills.l2skills.L2SkillSignet;
  29. import com.l2jserver.gameserver.model.skills.l2skills.L2SkillSignetCasttime;
  30. import com.l2jserver.gameserver.model.stats.Env;
  31. import com.l2jserver.gameserver.model.zone.ZoneId;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  34. /**
  35. * @author Forsaiken, Sami
  36. */
  37. public class Signet extends L2Effect
  38. {
  39. private L2Skill _skill;
  40. private L2EffectPointInstance _actor;
  41. private boolean _srcInArena;
  42. public Signet(Env env, EffectTemplate template)
  43. {
  44. super(env, template);
  45. }
  46. @Override
  47. public L2EffectType getEffectType()
  48. {
  49. return L2EffectType.SIGNET_EFFECT;
  50. }
  51. @Override
  52. public boolean onStart()
  53. {
  54. if (getSkill() instanceof L2SkillSignet)
  55. {
  56. _skill = SkillTable.getInstance().getInfo(getSkill().getEffectId(), getLevel());
  57. }
  58. else if (getSkill() instanceof L2SkillSignetCasttime)
  59. {
  60. _skill = SkillTable.getInstance().getInfo(getSkill().getEffectId(), getLevel());
  61. }
  62. _actor = (L2EffectPointInstance) getEffected();
  63. _srcInArena = (getEffector().isInsideZone(ZoneId.PVP) && !getEffector().isInsideZone(ZoneId.SIEGE));
  64. return true;
  65. }
  66. @Override
  67. public boolean onActionTime()
  68. {
  69. if (_skill == null)
  70. {
  71. return true;
  72. }
  73. int mpConsume = _skill.getMpConsume();
  74. if (mpConsume > getEffector().getCurrentMp())
  75. {
  76. getEffector().sendPacket(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  77. return false;
  78. }
  79. getEffector().reduceCurrentMp(mpConsume);
  80. FastList<L2Character> targets = FastList.newInstance();
  81. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getAffectRange()))
  82. {
  83. if (cha == null)
  84. {
  85. continue;
  86. }
  87. if (_skill.isOffensive() && !L2Skill.checkForAreaOffensiveSkills(getEffector(), cha, _skill, _srcInArena))
  88. {
  89. continue;
  90. }
  91. // there doesn't seem to be a visible effect with MagicSkillLaunched packet...
  92. _actor.broadcastPacket(new MagicSkillUse(_actor, cha, _skill.getId(), _skill.getLevel(), 0, 0));
  93. targets.add(cha);
  94. }
  95. if (!targets.isEmpty())
  96. {
  97. getEffector().callSkill(_skill, targets.toArray(new L2Character[targets.size()]));
  98. }
  99. FastList.recycle(targets);
  100. return true;
  101. }
  102. @Override
  103. public void onExit()
  104. {
  105. if (_actor != null)
  106. {
  107. _actor.deleteMe();
  108. }
  109. }
  110. }