SignetMDam.java 5.7 KB

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