TeleportToTarget.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2004-2015 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.gameserver.GeoData;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.StatsSet;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.conditions.Condition;
  26. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  27. import com.l2jserver.gameserver.model.effects.L2EffectType;
  28. import com.l2jserver.gameserver.model.skills.BuffInfo;
  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. * Teleport To Target effect implementation.
  35. * @author Didldak, Adry_85
  36. */
  37. public final class TeleportToTarget extends AbstractEffect
  38. {
  39. public TeleportToTarget(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  40. {
  41. super(attachCond, applyCond, set, params);
  42. }
  43. @Override
  44. public L2EffectType getEffectType()
  45. {
  46. return L2EffectType.TELEPORT_TO_TARGET;
  47. }
  48. @Override
  49. public boolean isInstant()
  50. {
  51. return true;
  52. }
  53. @Override
  54. public void onStart(BuffInfo info)
  55. {
  56. L2Character activeChar = info.getEffector();
  57. L2Character target = info.getEffected();
  58. if (target == null)
  59. {
  60. return;
  61. }
  62. int px = target.getX();
  63. int py = target.getY();
  64. double ph = Util.convertHeadingToDegree(target.getHeading());
  65. ph += 180;
  66. if (ph > 360)
  67. {
  68. ph -= 360;
  69. }
  70. ph = (Math.PI * ph) / 180;
  71. int x = (int) (px + (25 * Math.cos(ph)));
  72. int y = (int) (py + (25 * Math.sin(ph)));
  73. int z = target.getZ();
  74. final Location loc = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), x, y, z, activeChar.getInstanceId());
  75. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  76. activeChar.broadcastPacket(new FlyToLocation(activeChar, loc.getX(), loc.getY(), loc.getZ(), FlyType.DUMMY));
  77. activeChar.abortAttack();
  78. activeChar.abortCast();
  79. activeChar.setXYZ(loc);
  80. activeChar.broadcastPacket(new ValidateLocation(activeChar));
  81. }
  82. }