Blink.java 3.7 KB

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