EffectSignetMDam.java 6.3 KB

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