SignetMDam.java 5.7 KB

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