EffectEnemyCharge.java 3.6 KB

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