EffectWarp.java 4.0 KB

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