Blink.java 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2004-2014 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.effecthandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.StatsSet;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.conditions.Condition;
  27. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  28. import com.l2jserver.gameserver.model.skills.BuffInfo;
  29. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  30. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  31. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  32. import com.l2jserver.gameserver.util.Util;
  33. /**
  34. * Blink effect implementation.<br>
  35. * This class handles warp effects, disappear and quickly turn up in a near location.<br>
  36. * If geodata enabled and an object is between initial and final point, flight is stopped just before colliding with object.<br>
  37. * Flight course and radius are set as skill properties (flyCourse and flyRadius):
  38. * <ul>
  39. * <li>Fly Radius means the distance between starting point and final point, it must be an integer.</li>
  40. * <li>Fly Course means the movement direction: imagine a compass above player's head, making north player's heading. So if fly course is 180, player will go backwards (good for blink, e.g.).</li>
  41. * </ul>
  42. * By the way, if flyCourse = 360 or 0, player will be moved in in front of him. <br>
  43. * If target is effector, put in XML self="1", this will make _actor = getEffector(). This, combined with target type, allows more complex actions like flying target's backwards or player's backwards.
  44. * @author DrHouse
  45. */
  46. public final class Blink extends AbstractEffect
  47. {
  48. public Blink(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  49. {
  50. super(attachCond, applyCond, set, params);
  51. }
  52. @Override
  53. public boolean isInstant()
  54. {
  55. return true;
  56. }
  57. @Override
  58. public void onStart(BuffInfo info)
  59. {
  60. final L2Character effected = info.getEffected();
  61. final int radius = info.getSkill().getFlyRadius();
  62. final double angle = Util.convertHeadingToDegree(effected.getHeading());
  63. final double radian = Math.toRadians(angle);
  64. final double course = Math.toRadians(info.getSkill().getFlyCourse());
  65. final int x1 = (int) (Math.cos(Math.PI + radian + course) * radius);
  66. final int y1 = (int) (Math.sin(Math.PI + radian + course) * radius);
  67. int x = effected.getX() + x1;
  68. int y = effected.getY() + y1;
  69. int z = effected.getZ();
  70. Location loc = new Location(x, y, z);
  71. if (Config.GEODATA > 0)
  72. {
  73. loc = GeoData.getInstance().moveCheck(effected.getX(), effected.getY(), effected.getZ(), x, y, z, effected.getInstanceId());
  74. }
  75. effected.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  76. effected.broadcastPacket(new FlyToLocation(effected, loc.getX(), loc.getY(), loc.getZ(), FlyType.DUMMY));
  77. effected.abortAttack();
  78. effected.abortCast();
  79. effected.setXYZ(loc);
  80. effected.broadcastPacket(new ValidateLocation(effected));
  81. }
  82. }