InstantJump.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. package handlers.skillhandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.handler.ISkillHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Skill;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  27. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  30. import com.l2jserver.gameserver.skills.Formulas;
  31. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  32. import com.l2jserver.gameserver.util.Util;
  33. /**
  34. *
  35. * @author Didldak
  36. * Some parts taken from EffectWarp, which cannot be used for this case.
  37. */
  38. public class InstantJump implements ISkillHandler
  39. {
  40. private static final L2SkillType[] SKILL_IDS =
  41. {
  42. L2SkillType.INSTANT_JUMP
  43. };
  44. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  45. {
  46. L2Character target = (L2Character) targets[0];
  47. if (Formulas.calcPhysicalSkillEvasion(target, skill))
  48. {
  49. if (activeChar instanceof L2PcInstance)
  50. {
  51. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DODGES_ATTACK);
  52. sm.addString(target.getName());
  53. ((L2PcInstance) activeChar).sendPacket(sm);
  54. }
  55. if (target instanceof L2PcInstance)
  56. {
  57. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  58. sm.addString(activeChar.getName());
  59. ((L2PcInstance) target).sendPacket(sm);
  60. }
  61. return;
  62. }
  63. int x = 0, y = 0, z = 0;
  64. int px = target.getX();
  65. int py = target.getY();
  66. double ph = Util.convertHeadingToDegree(target.getHeading());
  67. ph += 180;
  68. if (ph > 360)
  69. ph -= 360;
  70. ph = (Math.PI * ph) / 180;
  71. x = (int) (px + (25 * Math.cos(ph)));
  72. y = (int) (py + (25 * Math.sin(ph)));
  73. z = target.getZ();
  74. Location loc = new Location(x, y, z);
  75. if (Config.GEODATA > 0)
  76. loc = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), x, y, z, activeChar.getInstanceId());
  77. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  78. activeChar.broadcastPacket(new FlyToLocation(activeChar, loc.getX(), loc.getY(), loc.getZ(), FlyType.DUMMY));
  79. activeChar.abortAttack();
  80. activeChar.abortCast();
  81. activeChar.setXYZ(loc.getX(), loc.getY(), loc.getZ());
  82. activeChar.broadcastPacket(new ValidateLocation(activeChar));
  83. if (skill.hasEffects())
  84. {
  85. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  86. {
  87. activeChar.stopSkillEffects(skill.getId());
  88. skill.getEffects(target, activeChar);
  89. //SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  90. //sm.addSkillName(skill);
  91. //activeChar.sendPacket(sm);
  92. }
  93. else
  94. {
  95. // activate attacked effects, if any
  96. target.stopSkillEffects(skill.getId());
  97. skill.getEffects(activeChar, target);
  98. }
  99. }
  100. }
  101. /**
  102. *
  103. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  104. */
  105. public L2SkillType[] getSkillIds()
  106. {
  107. return SKILL_IDS;
  108. }
  109. }