SignetMDam.java 5.5 KB

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