ThrowUp.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import java.util.logging.Logger;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.GeoData;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.effects.EffectFlag;
  25. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  26. import com.l2jserver.gameserver.model.effects.L2Effect;
  27. import com.l2jserver.gameserver.model.effects.L2EffectType;
  28. import com.l2jserver.gameserver.model.stats.Env;
  29. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  30. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  31. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  32. public class ThrowUp extends L2Effect
  33. {
  34. private static final Logger _log = Logger.getLogger(ThrowUp.class.getName());
  35. private int _x, _y, _z;
  36. public ThrowUp(Env env, EffectTemplate template)
  37. {
  38. super(env, template);
  39. }
  40. @Override
  41. public L2EffectType getEffectType()
  42. {
  43. return L2EffectType.THROW_UP;
  44. }
  45. @Override
  46. public boolean onStart()
  47. {
  48. // Get current position of the L2Character
  49. final int curX = getEffected().getX();
  50. final int curY = getEffected().getY();
  51. final int curZ = getEffected().getZ();
  52. // Calculate distance between effector and effected current position
  53. double dx = getEffector().getX() - curX;
  54. double dy = getEffector().getY() - curY;
  55. double dz = getEffector().getZ() - curZ;
  56. double distance = Math.sqrt((dx * dx) + (dy * dy));
  57. if (distance > 2000)
  58. {
  59. _log.info("EffectThrow was going to use invalid coordinates for characters, getEffected: " + curX + "," + curY + " and getEffector: " + getEffector().getX() + "," + getEffector().getY());
  60. return false;
  61. }
  62. int offset = Math.min((int) distance + getSkill().getFlyRadius(), 1400);
  63. double cos;
  64. double sin;
  65. // approximation for moving futher when z coordinates are different
  66. // TODO: handle Z axis movement better
  67. offset += Math.abs(dz);
  68. if (offset < 5)
  69. {
  70. offset = 5;
  71. }
  72. // If no distance
  73. if (distance < 1)
  74. {
  75. return false;
  76. }
  77. // Calculate movement angles needed
  78. sin = dy / distance;
  79. cos = dx / distance;
  80. // Calculate the new destination with offset included
  81. _x = getEffector().getX() - (int) (offset * cos);
  82. _y = getEffector().getY() - (int) (offset * sin);
  83. _z = getEffected().getZ();
  84. if (Config.GEODATA > 0)
  85. {
  86. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), _x, _y, _z, getEffected().getInstanceId());
  87. _x = destiny.getX();
  88. _y = destiny.getY();
  89. }
  90. getEffected().startStunning();
  91. getEffected().broadcastPacket(new FlyToLocation(getEffected(), _x, _y, _z, FlyType.THROW_UP));
  92. return true;
  93. }
  94. @Override
  95. public boolean onActionTime()
  96. {
  97. return false;
  98. }
  99. @Override
  100. public void onExit()
  101. {
  102. getEffected().stopStunning(false);
  103. getEffected().setXYZ(_x, _y, _z);
  104. getEffected().broadcastPacket(new ValidateLocation(getEffected()));
  105. }
  106. @Override
  107. public int getEffectFlags()
  108. {
  109. return EffectFlag.STUNNED.getMask();
  110. }
  111. }