ThrowUp.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2004-2015 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.gameserver.GeoData;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.StatsSet;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.effects.EffectFlag;
  26. import com.l2jserver.gameserver.model.skills.BuffInfo;
  27. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  28. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  29. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  30. /**
  31. * Throw Up effect implementation.
  32. */
  33. public final class ThrowUp extends AbstractEffect
  34. {
  35. public ThrowUp(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  36. {
  37. super(attachCond, applyCond, set, params);
  38. }
  39. @Override
  40. public int getEffectFlags()
  41. {
  42. return EffectFlag.STUNNED.getMask();
  43. }
  44. @Override
  45. public boolean isInstant()
  46. {
  47. return true;
  48. }
  49. @Override
  50. public void onStart(BuffInfo info)
  51. {
  52. // Get current position of the L2Character
  53. final int curX = info.getEffected().getX();
  54. final int curY = info.getEffected().getY();
  55. final int curZ = info.getEffected().getZ();
  56. // Calculate distance between effector and effected current position
  57. double dx = info.getEffector().getX() - curX;
  58. double dy = info.getEffector().getY() - curY;
  59. double dz = info.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: " + info.getEffector().getX() + "," + info.getEffector().getY());
  64. return;
  65. }
  66. int offset = Math.min((int) distance + info.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. {
  74. offset = 5;
  75. }
  76. // If no distance
  77. if (distance < 1)
  78. {
  79. return;
  80. }
  81. // Calculate movement angles needed
  82. sin = dy / distance;
  83. cos = dx / distance;
  84. // Calculate the new destination with offset included
  85. int x = info.getEffector().getX() - (int) (offset * cos);
  86. int y = info.getEffector().getY() - (int) (offset * sin);
  87. int z = info.getEffected().getZ();
  88. final Location destination = GeoData.getInstance().moveCheck(info.getEffected().getX(), info.getEffected().getY(), info.getEffected().getZ(), x, y, z, info.getEffected().getInstanceId());
  89. info.getEffected().broadcastPacket(new FlyToLocation(info.getEffected(), destination, FlyType.THROW_UP));
  90. // TODO: Review.
  91. info.getEffected().setXYZ(destination);
  92. info.getEffected().broadcastPacket(new ValidateLocation(info.getEffected()));
  93. }
  94. }