2
0

EffectThrowUp.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.CharEffectList;
  20. import com.l2jserver.gameserver.model.L2Effect;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  23. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  24. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  25. import com.l2jserver.gameserver.skills.Env;
  26. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  27. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  28. public class EffectThrowUp extends L2Effect
  29. {
  30. static final Logger _log = Logger.getLogger(EffectThrowUp.class.getName());
  31. private int _x, _y, _z;
  32. public EffectThrowUp(Env env, EffectTemplate template)
  33. {
  34. super(env, template);
  35. }
  36. /**
  37. *
  38. * @see com.l2jserver.gameserver.model.L2Effect#getEffectType()
  39. */
  40. @Override
  41. public L2EffectType getEffectType()
  42. {
  43. return L2EffectType.THROW_UP;
  44. }
  45. /**
  46. *
  47. * @see com.l2jserver.gameserver.model.L2Effect#onStart()
  48. */
  49. @Override
  50. public boolean onStart()
  51. {
  52. // Get current position of the L2Character
  53. final int curX = getEffected().getX();
  54. final int curY = getEffected().getY();
  55. final int curZ = getEffected().getZ();
  56. // Calculate distance between effector and effected current position
  57. double dx = getEffector().getX() - curX;
  58. double dy = getEffector().getY() - curY;
  59. double dz = getEffector().getZ() - curZ;
  60. double distance = Math.sqrt(dx * dx + dy * dy);
  61. if (distance > 2000)
  62. {
  63. _log.info("EffectThrow was going to use invalid coordinates for characters, getEffected: "+curX+","+curY+" and getEffector: "+getEffector().getX()+","+getEffector().getY());
  64. return false;
  65. }
  66. int offset = Math.min((int) distance + getSkill().getFlyRadius(), 1400);
  67. double cos;
  68. double sin;
  69. // approximation for moving futher when z coordinates are different
  70. // TODO: handle Z axis movement better
  71. offset += Math.abs(dz);
  72. if (offset < 5)
  73. offset = 5;
  74. // If no distance
  75. if (distance < 1)
  76. return false;
  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. /**
  95. *
  96. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  97. */
  98. @Override
  99. public boolean onActionTime()
  100. {
  101. return false;
  102. }
  103. /**
  104. *
  105. * @see com.l2jserver.gameserver.model.L2Effect#onExit()
  106. */
  107. @Override
  108. public void onExit()
  109. {
  110. getEffected().stopStunning(false);
  111. getEffected().setXYZ(_x, _y, _z);
  112. getEffected().broadcastPacket(new ValidateLocation(getEffected()));
  113. }
  114. /* (non-Javadoc)
  115. * @see com.l2jserver.gameserver.model.L2Effect#getEffectFlags()
  116. */
  117. @Override
  118. public int getEffectFlags()
  119. {
  120. return CharEffectList.EFFECT_FLAG_STUNNED;
  121. }
  122. }