ThrowUp.java 3.8 KB

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