EffectEnemyCharge.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 net.sf.l2j.gameserver.skills.effects;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.GeoData;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  19. import net.sf.l2j.gameserver.model.Location;
  20. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation;
  21. import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
  22. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation.FlyType;
  23. import net.sf.l2j.gameserver.skills.Env;
  24. public class EffectEnemyCharge extends L2Effect
  25. {
  26. private int _x, _y, _z;
  27. public EffectEnemyCharge(Env env, EffectTemplate template)
  28. {
  29. super(env, template);
  30. }
  31. /**
  32. *
  33. * @see net.sf.l2j.gameserver.model.L2Effect#getEffectType()
  34. */
  35. @Override
  36. public EffectType getEffectType()
  37. {
  38. return EffectType.BUFF;
  39. }
  40. /**
  41. *
  42. * @see net.sf.l2j.gameserver.model.L2Effect#onStart()
  43. */
  44. @Override
  45. public void onStart()
  46. {
  47. // Get current position of the L2Character
  48. final int curX = getEffector().getX();
  49. final int curY = getEffector().getY();
  50. final int curZ = getEffector().getZ();
  51. // Calculate distance (dx,dy) between current position and destination
  52. double dx = getEffected().getX() - curX;
  53. double dy = getEffected().getY() - curY;
  54. double dz = getEffected().getZ() - curZ;
  55. double distance = Math.sqrt(dx * dx + dy * dy);
  56. int offset = Math.max((int) distance - getSkill().getFlyRadius(), 30);
  57. double cos;
  58. double sin;
  59. // approximation for moving closer when z coordinates are different
  60. // TODO: handle Z axis movement better
  61. offset -= Math.abs(dz);
  62. if (offset < 5)
  63. offset = 5;
  64. // If no distance
  65. if (distance < 1 || distance - offset <= 0)
  66. return;
  67. // Calculate movement angles needed
  68. sin = dy / distance;
  69. cos = dx / distance;
  70. // Calculate the new destination with offset included
  71. _x = curX + (int) ((distance - offset) * cos);
  72. _y = curY + (int) ((distance - offset) * sin);
  73. _z = getEffected().getZ();
  74. if (Config.GEODATA > 0)
  75. {
  76. Location destiny = GeoData.getInstance().moveCheck(getEffector().getX(), getEffector().getY(), getEffector().getZ(), _x, _y, _z);
  77. _x = destiny.getX();
  78. _y = destiny.getY();
  79. }
  80. getEffector().broadcastPacket(new FlyToLocation(getEffector(), _x, _y, _z, FlyType.CHARGE));
  81. // getEffector().abortAttack();
  82. // getEffector().abortCast();
  83. }
  84. /**
  85. *
  86. * @see net.sf.l2j.gameserver.model.L2Effect#onExit()
  87. */
  88. @Override
  89. public void onExit()
  90. {
  91. // maybe is need force set X,Y,Z
  92. getEffector().setXYZ(_x, _y, _z);
  93. getEffector().broadcastPacket(new ValidateLocation(getEffector()));
  94. }
  95. /**
  96. *
  97. * @see net.sf.l2j.gameserver.model.L2Effect#onActionTime()
  98. */
  99. @Override
  100. public boolean onActionTime()
  101. {
  102. return false;
  103. }
  104. }