SignetMDam.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. /**
  20. * @author Forsaiken
  21. */
  22. package handlers.effecthandlers;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import com.l2jserver.gameserver.ai.CtrlEvent;
  26. import com.l2jserver.gameserver.datatables.NpcTable;
  27. import com.l2jserver.gameserver.enums.ShotType;
  28. import com.l2jserver.gameserver.idfactory.IdFactory;
  29. import com.l2jserver.gameserver.model.actor.L2Character;
  30. import com.l2jserver.gameserver.model.actor.instance.L2EffectPointInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  33. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  34. import com.l2jserver.gameserver.model.effects.L2Effect;
  35. import com.l2jserver.gameserver.model.effects.L2EffectType;
  36. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  37. import com.l2jserver.gameserver.model.stats.Env;
  38. import com.l2jserver.gameserver.model.stats.Formulas;
  39. import com.l2jserver.gameserver.network.SystemMessageId;
  40. import com.l2jserver.gameserver.network.serverpackets.MagicSkillLaunched;
  41. import com.l2jserver.gameserver.util.Point3D;
  42. /**
  43. * Signet MDam effect implementation.
  44. */
  45. public class SignetMDam extends L2Effect
  46. {
  47. private L2EffectPointInstance _actor;
  48. public SignetMDam(Env env, EffectTemplate template)
  49. {
  50. super(env, template);
  51. }
  52. @Override
  53. public L2EffectType getEffectType()
  54. {
  55. return L2EffectType.SIGNET_GROUND;
  56. }
  57. @Override
  58. public boolean onActionTime()
  59. {
  60. if (_actor == null)
  61. {
  62. return false;
  63. }
  64. final int mpConsume = getSkill().getMpConsume();
  65. final L2PcInstance activeChar = getEffector().getActingPlayer();
  66. activeChar.rechargeShots(getSkill().useSoulShot(), getSkill().useSpiritShot());
  67. boolean sps = getSkill().useSpiritShot() && getEffector().isChargedShot(ShotType.SPIRITSHOTS);
  68. boolean bss = getSkill().useSpiritShot() && getEffector().isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  69. final List<L2Character> targets = new ArrayList<>();
  70. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getAffectRange()))
  71. {
  72. if ((cha == null) || (cha == activeChar))
  73. {
  74. continue;
  75. }
  76. if (cha.isL2Attackable() || cha.isPlayable())
  77. {
  78. if (cha.isAlikeDead())
  79. {
  80. continue;
  81. }
  82. if (mpConsume > activeChar.getCurrentMp())
  83. {
  84. activeChar.sendPacket(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  85. return false;
  86. }
  87. activeChar.reduceCurrentMp(mpConsume);
  88. if (cha.isPlayable())
  89. {
  90. if (activeChar.canAttackCharacter(cha))
  91. {
  92. targets.add(cha);
  93. activeChar.updatePvPStatus(cha);
  94. }
  95. }
  96. else
  97. {
  98. targets.add(cha);
  99. }
  100. }
  101. }
  102. if (!targets.isEmpty())
  103. {
  104. activeChar.broadcastPacket(new MagicSkillLaunched(activeChar, getSkill().getId(), getSkill().getLevel(), targets.toArray(new L2Character[targets.size()])));
  105. for (L2Character target : targets)
  106. {
  107. final boolean mcrit = Formulas.calcMCrit(activeChar.getMCriticalHit(target, getSkill()));
  108. final byte shld = Formulas.calcShldUse(activeChar, target, getSkill());
  109. final int mdam = (int) Formulas.calcMagicDam(activeChar, target, getSkill(), shld, sps, bss, mcrit);
  110. if (target.isSummon())
  111. {
  112. target.broadcastStatusUpdate();
  113. }
  114. if (mdam > 0)
  115. {
  116. if (!target.isRaid() && Formulas.calcAtkBreak(target, mdam))
  117. {
  118. target.breakAttack();
  119. target.breakCast();
  120. }
  121. activeChar.sendDamageMessage(target, mdam, mcrit, false, false);
  122. target.reduceCurrentHp(mdam, activeChar, getSkill());
  123. target.notifyDamageReceived(mdam, activeChar, getSkill(), mcrit);
  124. }
  125. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  126. }
  127. }
  128. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  129. return false;
  130. }
  131. @Override
  132. public void onExit()
  133. {
  134. if (_actor != null)
  135. {
  136. _actor.deleteMe();
  137. }
  138. }
  139. @Override
  140. public boolean onStart()
  141. {
  142. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(getSkill().getNpcId());
  143. _actor = new L2EffectPointInstance(IdFactory.getInstance().getNextId(), template, getEffector());
  144. _actor.setCurrentHp(_actor.getMaxHp());
  145. _actor.setCurrentMp(_actor.getMaxMp());
  146. int x = getEffector().getX();
  147. int y = getEffector().getY();
  148. int z = getEffector().getZ();
  149. if (getEffector().isPlayer() && (getSkill().getTargetType() == L2TargetType.GROUND))
  150. {
  151. final Point3D wordPosition = getEffector().getActingPlayer().getCurrentSkillWorldPosition();
  152. if (wordPosition != null)
  153. {
  154. x = wordPosition.getX();
  155. y = wordPosition.getY();
  156. z = wordPosition.getZ();
  157. }
  158. }
  159. _actor.setIsInvul(true);
  160. _actor.spawnMe(x, y, z);
  161. return true;
  162. }
  163. }