SignetMDam.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.actor.L2Attackable;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.L2Playable;
  26. import com.l2jserver.gameserver.model.actor.L2Summon;
  27. import com.l2jserver.gameserver.model.actor.instance.L2EffectPointInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  30. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  31. import com.l2jserver.gameserver.model.effects.L2Effect;
  32. import com.l2jserver.gameserver.model.effects.L2EffectType;
  33. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  34. import com.l2jserver.gameserver.model.skills.l2skills.L2SkillSignetCasttime;
  35. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  36. import com.l2jserver.gameserver.model.stats.Env;
  37. import com.l2jserver.gameserver.model.stats.Formulas;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.network.serverpackets.MagicSkillLaunched;
  40. import com.l2jserver.gameserver.util.Point3D;
  41. public class SignetMDam extends L2Effect
  42. {
  43. private L2EffectPointInstance _actor;
  44. public SignetMDam(Env env, EffectTemplate template)
  45. {
  46. super(env, template);
  47. }
  48. @Override
  49. public L2EffectType getEffectType()
  50. {
  51. return L2EffectType.SIGNET_GROUND;
  52. }
  53. @Override
  54. public boolean onStart()
  55. {
  56. L2NpcTemplate template;
  57. if (getSkill() instanceof L2SkillSignetCasttime)
  58. template = NpcTable.getInstance().getTemplate(((L2SkillSignetCasttime) getSkill())._effectNpcId);
  59. else
  60. return false;
  61. L2EffectPointInstance effectPoint = new L2EffectPointInstance(IdFactory.getInstance().getNextId(), template, getEffector());
  62. effectPoint.setCurrentHp(effectPoint.getMaxHp());
  63. effectPoint.setCurrentMp(effectPoint.getMaxMp());
  64. //L2World.getInstance().storeObject(effectPoint);
  65. int x = getEffector().getX();
  66. int y = getEffector().getY();
  67. int z = getEffector().getZ();
  68. if (getEffector() instanceof L2PcInstance
  69. && getSkill().getTargetType() == L2TargetType.TARGET_GROUND)
  70. {
  71. Point3D wordPosition = ((L2PcInstance) getEffector()).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. return true; // do nothing first 2 times
  89. int mpConsume = getSkill().getMpConsume();
  90. L2PcInstance caster = (L2PcInstance) getEffector();
  91. boolean ss = false;
  92. boolean bss = false;
  93. L2ItemInstance weaponInst = caster.getActiveWeaponInstance();
  94. if (weaponInst != null)
  95. {
  96. switch (weaponInst.getChargedSpiritshot())
  97. {
  98. case L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT:
  99. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  100. bss = true;
  101. break;
  102. case L2ItemInstance.CHARGED_SPIRITSHOT:
  103. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  104. ss = true;
  105. break;
  106. }
  107. }
  108. FastList<L2Character> targets = new FastList<L2Character>();
  109. for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(getSkill().getSkillRadius()))
  110. {
  111. if (cha == null || cha == caster)
  112. continue;
  113. if (cha instanceof L2Attackable || cha instanceof L2Playable)
  114. {
  115. if (cha.isAlikeDead())
  116. continue;
  117. if (mpConsume > caster.getCurrentMp())
  118. {
  119. caster.sendPacket(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  120. return false;
  121. }
  122. caster.reduceCurrentMp(mpConsume);
  123. if (cha instanceof L2Playable)
  124. {
  125. if (caster.canAttackCharacter(cha))
  126. {
  127. targets.add(cha);
  128. caster.updatePvPStatus(cha);
  129. }
  130. }
  131. else
  132. targets.add(cha);
  133. }
  134. }
  135. if (!targets.isEmpty())
  136. {
  137. caster.broadcastPacket(new MagicSkillLaunched(caster, getSkill().getId(), getSkill().getLevel(), targets.toArray(new L2Character[targets.size()])));
  138. for (L2Character target : targets)
  139. {
  140. boolean mcrit = Formulas.calcMCrit(caster.getMCriticalHit(target, getSkill()));
  141. byte shld = Formulas.calcShldUse(caster, target, getSkill());
  142. int mdam = (int) Formulas.calcMagicDam(caster, target, getSkill(), shld, ss, bss, mcrit);
  143. if (target instanceof L2Summon)
  144. target.broadcastStatusUpdate();
  145. if (mdam > 0)
  146. {
  147. if (!target.isRaid()
  148. && Formulas.calcAtkBreak(target, mdam))
  149. {
  150. target.breakAttack();
  151. target.breakCast();
  152. }
  153. caster.sendDamageMessage(target, mdam, mcrit, false, false);
  154. target.reduceCurrentHp(mdam, caster, getSkill());
  155. }
  156. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, caster);
  157. }
  158. }
  159. return true;
  160. }
  161. @Override
  162. public void onExit()
  163. {
  164. if (_actor != null)
  165. _actor.deleteMe();
  166. }
  167. }