EffectEnemyCharge.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.serverpackets.FlyToLocation;
  21. import net.sf.l2j.gameserver.serverpackets.ValidateLocation;
  22. import net.sf.l2j.gameserver.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. @Override
  32. public EffectType getEffectType()
  33. {
  34. return EffectType.BUFF;
  35. }
  36. @Override
  37. public void onStart()
  38. {
  39. // Get current position of the L2Character
  40. final int curX = getEffector().getX();
  41. final int curY = getEffector().getY();
  42. final int curZ = getEffector().getZ();
  43. // Calculate distance (dx,dy) between current position and destination
  44. double dx = getEffected().getX() - curX;
  45. double dy = getEffected().getY() - curY;
  46. double dz = getEffected().getZ() - curZ;
  47. double distance = Math.sqrt(dx*dx + dy*dy);
  48. int offset = Math.max((int)distance-getSkill().getFlyRadius(), 30);
  49. double cos;
  50. double sin;
  51. // approximation for moving closer when z coordinates are different
  52. // TODO: handle Z axis movement better
  53. offset -= Math.abs(dz);
  54. if (offset < 5) offset = 5;
  55. // If no distance
  56. if (distance < 1 || distance - offset <= 0)
  57. return;
  58. // Calculate movement angles needed
  59. sin = dy/distance;
  60. cos = dx/distance;
  61. // Calculate the new destination with offset included
  62. _x = curX + (int)((distance-offset) * cos);
  63. _y = curY + (int)((distance-offset) * sin);
  64. _z = getEffected().getZ();
  65. if (Config.GEODATA > 0)
  66. {
  67. Location destiny = GeoData.getInstance().moveCheck(getEffector().getX(), getEffector().getY(), getEffector().getZ(), _x, _y, _z);
  68. _x = destiny.getX();
  69. _y = destiny.getY();
  70. }
  71. getEffector().broadcastPacket(new FlyToLocation(getEffector(), _x, _y, _z, FlyType.CHARGE));
  72. //getEffector().abortAttack();
  73. //getEffector().abortCast();
  74. }
  75. @Override
  76. public void onExit()
  77. {
  78. // maybe is need force set X,Y,Z
  79. getEffector().setXYZ(_x, _y, _z);
  80. getEffector().broadcastPacket(new ValidateLocation(getEffector()));
  81. }
  82. @Override
  83. public boolean onActionTime()
  84. {
  85. return false;
  86. }
  87. }