Warp.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.effecthandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.model.Location;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  22. import com.l2jserver.gameserver.model.effects.L2Effect;
  23. import com.l2jserver.gameserver.model.effects.L2EffectType;
  24. import com.l2jserver.gameserver.model.stats.Env;
  25. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  26. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  27. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * This class handles warp effects, disappear and quickly turn up in a near
  31. * location. If geodata enabled and an object is between initial and final
  32. * point, flight is stopped just before colliding with object. Flight course and
  33. * radius are set as skill properties (flyCourse and flyRadius):
  34. *
  35. * <li>Fly Radius means the distance between starting point and final point, it
  36. * must be an integer.</li> <li>Fly Course means the movement direction: imagine
  37. * a compass above player's head, making north player's heading. So if fly
  38. * course is 180, player will go backwards (good for blink, e.g.). By the way,
  39. * if flyCourse = 360 or 0, player will be moved in in front of him. <br>
  40. * <br>
  41. *
  42. * If target is effector, put in XML self = "1". This will make _actor =
  43. * getEffector(). This, combined with target type, allows more complex actions
  44. * like flying target's backwards or player's backwards.<br>
  45. * <br>
  46. *
  47. * @author House
  48. */
  49. public class Warp extends L2Effect
  50. {
  51. private int x, y, z;
  52. private L2Character _actor;
  53. public Warp(Env env, EffectTemplate template)
  54. {
  55. super(env, template);
  56. }
  57. @Override
  58. public L2EffectType getEffectType()
  59. {
  60. return L2EffectType.WARP;
  61. }
  62. @Override
  63. public boolean onStart()
  64. {
  65. _actor = isSelfEffect() ? getEffector() : getEffected();
  66. /*if (_actor.isMovementDisabled()) This is removed because in retail you can use Warp while movement is disabled.
  67. return false;*/
  68. int _radius = getSkill().getFlyRadius();
  69. double angle = Util.convertHeadingToDegree(_actor.getHeading());
  70. double radian = Math.toRadians(angle);
  71. double course = Math.toRadians(getSkill().getFlyCourse());
  72. int x1 = (int) (Math.cos(Math.PI + radian + course) * _radius);
  73. int y1 = (int) (Math.sin(Math.PI + radian + course) * _radius);
  74. x = _actor.getX() + x1;
  75. y = _actor.getY() + y1;
  76. z = _actor.getZ();
  77. if (Config.GEODATA > 0)
  78. {
  79. Location destiny = GeoData.getInstance().moveCheck(_actor.getX(), _actor.getY(), _actor.getZ(), x, y, z, _actor.getInstanceId());
  80. x = destiny.getX();
  81. y = destiny.getY();
  82. z = destiny.getZ();
  83. }
  84. // TODO: check if this AI intention is retail-like. This stops player's
  85. // previous movement
  86. _actor.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  87. _actor.broadcastPacket(new FlyToLocation(_actor, x, y, z, FlyType.DUMMY));
  88. _actor.abortAttack();
  89. _actor.abortCast();
  90. _actor.setXYZ(x, y, z);
  91. _actor.broadcastPacket(new ValidateLocation(_actor));
  92. return true;
  93. }
  94. @Override
  95. public boolean onActionTime()
  96. {
  97. return false;
  98. }
  99. }