EffectEnemyCharge.java 3.9 KB

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