ThrowUp.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.GeoData;
  19. import com.l2jserver.gameserver.model.CharEffectList;
  20. import com.l2jserver.gameserver.model.Location;
  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. public class ThrowUp extends L2Effect
  29. {
  30. private static final Logger _log = Logger.getLogger(ThrowUp.class.getName());
  31. private int _x, _y, _z;
  32. public ThrowUp(Env env, EffectTemplate template)
  33. {
  34. super(env, template);
  35. }
  36. @Override
  37. public L2EffectType getEffectType()
  38. {
  39. return L2EffectType.THROW_UP;
  40. }
  41. @Override
  42. public boolean onStart()
  43. {
  44. // Get current position of the L2Character
  45. final int curX = getEffected().getX();
  46. final int curY = getEffected().getY();
  47. final int curZ = getEffected().getZ();
  48. // Calculate distance between effector and effected current position
  49. double dx = getEffector().getX() - curX;
  50. double dy = getEffector().getY() - curY;
  51. double dz = getEffector().getZ() - curZ;
  52. double distance = Math.sqrt(dx * dx + dy * dy);
  53. if (distance > 2000)
  54. {
  55. _log.info("EffectThrow was going to use invalid coordinates for characters, getEffected: "+curX+","+curY+" and getEffector: "+getEffector().getX()+","+getEffector().getY());
  56. return false;
  57. }
  58. int offset = Math.min((int) distance + getSkill().getFlyRadius(), 1400);
  59. double cos;
  60. double sin;
  61. // approximation for moving futher when z coordinates are different
  62. // TODO: handle Z axis movement better
  63. offset += Math.abs(dz);
  64. if (offset < 5)
  65. offset = 5;
  66. // If no distance
  67. if (distance < 1)
  68. return false;
  69. // Calculate movement angles needed
  70. sin = dy / distance;
  71. cos = dx / distance;
  72. // Calculate the new destination with offset included
  73. _x = getEffector().getX() - (int) (offset * cos);
  74. _y = getEffector().getY() - (int) (offset * sin);
  75. _z = getEffected().getZ();
  76. if (Config.GEODATA > 0)
  77. {
  78. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), _x, _y, _z, getEffected().getInstanceId());
  79. _x = destiny.getX();
  80. _y = destiny.getY();
  81. }
  82. getEffected().startStunning();
  83. getEffected().broadcastPacket(new FlyToLocation(getEffected(), _x, _y, _z, FlyType.THROW_UP));
  84. return true;
  85. }
  86. @Override
  87. public boolean onActionTime()
  88. {
  89. return false;
  90. }
  91. @Override
  92. public void onExit()
  93. {
  94. getEffected().stopStunning(false);
  95. getEffected().setXYZ(_x, _y, _z);
  96. getEffected().broadcastPacket(new ValidateLocation(getEffected()));
  97. }
  98. @Override
  99. public int getEffectFlags()
  100. {
  101. return CharEffectList.EFFECT_FLAG_STUNNED;
  102. }
  103. }