EffectWarp.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.L2Effect;
  20. import net.sf.l2j.gameserver.model.Location;
  21. import net.sf.l2j.gameserver.model.actor.L2Character;
  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.templates.effects.EffectTemplate;
  27. import net.sf.l2j.gameserver.templates.skills.L2EffectType;
  28. import net.sf.l2j.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 net.sf.l2j.gameserver.model.L2Effect#getEffectType()
  60. */
  61. @Override
  62. public L2EffectType getEffectType()
  63. {
  64. return L2EffectType.WARP;
  65. }
  66. /**
  67. *
  68. * @see net.sf.l2j.gameserver.model.L2Effect#onStart()
  69. */
  70. @Override
  71. public boolean onStart()
  72. {
  73. if (isSelfEffect())
  74. _actor = getEffector();
  75. else
  76. _actor = getEffected();
  77. int _radius = getSkill().getFlyRadius();
  78. double angle = Util.convertHeadingToDegree(_actor.getHeading());
  79. double radian = Math.toRadians(angle);
  80. double course = Math.toRadians(getSkill().getFlyCourse());
  81. int x1 = (int) (Math.cos(Math.PI + radian + course) * _radius);
  82. int y1 = (int) (Math.sin(Math.PI + radian + course) * _radius);
  83. x = _actor.getX() + x1;
  84. y = _actor.getY() + y1;
  85. z = _actor.getZ();
  86. if (Config.GEODATA > 0)
  87. {
  88. Location destiny = GeoData.getInstance().moveCheck(_actor.getX(), _actor.getY(), _actor.getZ(), x, y, z, _actor.getInstanceId());
  89. x = destiny.getX();
  90. y = destiny.getY();
  91. z = destiny.getZ();
  92. }
  93. // TODO: check if this AI intention is retail-like. This stops player's
  94. // previous movement
  95. _actor.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  96. _actor.broadcastPacket(new FlyToLocation(_actor, x, y, z, FlyType.DUMMY));
  97. _actor.abortAttack();
  98. _actor.abortCast();
  99. return true;
  100. }
  101. /**
  102. *
  103. * @see net.sf.l2j.gameserver.model.L2Effect#onExit()
  104. */
  105. @Override
  106. public void onExit()
  107. {
  108. _actor.setXYZ(x, y, z);
  109. _actor.broadcastPacket(new ValidateLocation(_actor));
  110. }
  111. /**
  112. *
  113. * @see net.sf.l2j.gameserver.model.L2Effect#onActionTime()
  114. */
  115. @Override
  116. public boolean onActionTime()
  117. {
  118. return false;
  119. }
  120. }