EffectWarp.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 com.l2jserver.gameserver.skills.effects;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.model.L2Effect;
  20. import com.l2jserver.gameserver.model.Location;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  23. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  24. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  25. import com.l2jserver.gameserver.skills.Env;
  26. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  27. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  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 EffectWarp extends L2Effect
  50. {
  51. private int x, y, z;
  52. private L2Character _actor;
  53. public EffectWarp(Env env, EffectTemplate template)
  54. {
  55. super(env, template);
  56. }
  57. /**
  58. *
  59. * @see com.l2jserver.gameserver.model.L2Effect#getEffectType()
  60. */
  61. @Override
  62. public L2EffectType getEffectType()
  63. {
  64. return L2EffectType.WARP;
  65. }
  66. /**
  67. *
  68. * @see com.l2jserver.gameserver.model.L2Effect#onStart()
  69. */
  70. @Override
  71. public boolean onStart()
  72. {
  73. _actor = isSelfEffect() ? getEffector() : getEffected();
  74. if (_actor.isMovementDisabled())
  75. return false;
  76. int _radius = getSkill().getFlyRadius();
  77. double angle = Util.convertHeadingToDegree(_actor.getHeading());
  78. double radian = Math.toRadians(angle);
  79. double course = Math.toRadians(getSkill().getFlyCourse());
  80. int x1 = (int) (Math.cos(Math.PI + radian + course) * _radius);
  81. int y1 = (int) (Math.sin(Math.PI + radian + course) * _radius);
  82. x = _actor.getX() + x1;
  83. y = _actor.getY() + y1;
  84. z = _actor.getZ();
  85. if (Config.GEODATA > 0)
  86. {
  87. Location destiny = GeoData.getInstance().moveCheck(_actor.getX(), _actor.getY(), _actor.getZ(), x, y, z, _actor.getInstanceId());
  88. x = destiny.getX();
  89. y = destiny.getY();
  90. z = destiny.getZ();
  91. }
  92. // TODO: check if this AI intention is retail-like. This stops player's
  93. // previous movement
  94. _actor.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  95. _actor.broadcastPacket(new FlyToLocation(_actor, x, y, z, FlyType.DUMMY));
  96. _actor.abortAttack();
  97. _actor.abortCast();
  98. _actor.setXYZ(x, y, z);
  99. _actor.broadcastPacket(new ValidateLocation(_actor));
  100. return true;
  101. }
  102. /**
  103. *
  104. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  105. */
  106. @Override
  107. public boolean onActionTime()
  108. {
  109. return false;
  110. }
  111. }