TeleportToTarget.java 3.1 KB

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