InstantJump.java 4.1 KB

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