Blink.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2004-2013 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.Config;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  26. import com.l2jserver.gameserver.model.effects.L2Effect;
  27. import com.l2jserver.gameserver.model.effects.L2EffectType;
  28. import com.l2jserver.gameserver.model.stats.Env;
  29. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation;
  30. import com.l2jserver.gameserver.network.serverpackets.FlyToLocation.FlyType;
  31. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  32. import com.l2jserver.gameserver.util.Util;
  33. /**
  34. * Blink effect implementation.<br>
  35. * This class handles warp effects, disappear and quickly turn up in a near location. If geodata enabled and an object is between initial and final point, flight is stopped just before colliding with object. Flight course and radius are set as skill properties (flyCourse and flyRadius):
  36. * <ul>
  37. * <li>Fly Radius means the distance between starting point and final point, it must be an integer.</li>
  38. * <li>Fly Course means the movement direction: imagine a compass above player's head, making north player's heading. So if fly course is 180, player will go backwards (good for blink, e.g.).</li>
  39. * </ul>
  40. * By the way, if flyCourse = 360 or 0, player will be moved in in front of him. <br>
  41. * <br>
  42. * If target is effector, put in XML self = "1". This will make _actor = getEffector(). This, combined with target type, allows more complex actions like flying target's backwards or player's backwards.<br>
  43. * <br>
  44. * @author House
  45. */
  46. public class Blink extends L2Effect
  47. {
  48. private L2Character _actor;
  49. private int x, y, z;
  50. public Blink(Env env, EffectTemplate template)
  51. {
  52. super(env, template);
  53. }
  54. @Override
  55. public L2EffectType getEffectType()
  56. {
  57. return L2EffectType.NONE;
  58. }
  59. @Override
  60. public boolean isInstant()
  61. {
  62. return true;
  63. }
  64. @Override
  65. public boolean onStart()
  66. {
  67. _actor = isSelfEffect() ? getEffector() : getEffected();
  68. int _radius = getSkill().getFlyRadius();
  69. double angle = Util.convertHeadingToDegree(_actor.getHeading());
  70. double radian = Math.toRadians(angle);
  71. double course = Math.toRadians(getSkill().getFlyCourse());
  72. int x1 = (int) (Math.cos(Math.PI + radian + course) * _radius);
  73. int y1 = (int) (Math.sin(Math.PI + radian + course) * _radius);
  74. x = _actor.getX() + x1;
  75. y = _actor.getY() + y1;
  76. z = _actor.getZ();
  77. if (Config.GEODATA > 0)
  78. {
  79. Location destiny = GeoData.getInstance().moveCheck(_actor.getX(), _actor.getY(), _actor.getZ(), x, y, z, _actor.getInstanceId());
  80. x = destiny.getX();
  81. y = destiny.getY();
  82. z = destiny.getZ();
  83. }
  84. // TODO: check if this AI intention is retail-like. This stops player's previous movement
  85. _actor.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  86. _actor.broadcastPacket(new FlyToLocation(_actor, x, y, z, FlyType.DUMMY));
  87. _actor.abortAttack();
  88. _actor.abortCast();
  89. _actor.setXYZ(x, y, z);
  90. _actor.broadcastPacket(new ValidateLocation(_actor));
  91. return true;
  92. }
  93. }