EffectThrowUp.java 3.9 KB

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