2
0

TvTEventTeleporter.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.model.entity;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.ThreadPoolManager;
  18. import com.l2jserver.gameserver.model.actor.L2Summon;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.util.Rnd;
  21. public class TvTEventTeleporter implements Runnable
  22. {
  23. /** The instance of the player to teleport */
  24. private L2PcInstance _playerInstance = null;
  25. /** Coordinates of the spot to teleport to */
  26. private int[] _coordinates = new int[3];
  27. /** Admin removed this player from event */
  28. private boolean _adminRemove = false;
  29. /**
  30. * Initialize the teleporter and start the delayed task<br><br>
  31. *
  32. * @param playerInstance as L2PcInstance<br>
  33. * @param coordinates as int[]<br>
  34. * @param fastShedule as boolean<br>
  35. * @param adminRemove as boolean<br>
  36. */
  37. public TvTEventTeleporter(L2PcInstance playerInstance, int[] coordinates, boolean fastSchedule, boolean adminRemove)
  38. {
  39. _playerInstance = playerInstance;
  40. _coordinates = coordinates;
  41. _adminRemove = adminRemove;
  42. long delay = (TvTEvent.isStarted() ? Config.TVT_EVENT_RESPAWN_TELEPORT_DELAY : Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY) * 1000;
  43. ThreadPoolManager.getInstance().scheduleGeneral(this, fastSchedule ? 0 : delay);
  44. }
  45. /**
  46. * The task method to teleport the player<br>
  47. * 1. Unsummon pet if there is one<br>
  48. * 2. Remove all effects<br>
  49. * 3. Revive and full heal the player<br>
  50. * 4. Teleport the player<br>
  51. * 5. Broadcast status and user info<br><br>
  52. *
  53. * @see java.lang.Runnable#run()<br>
  54. */
  55. public void run()
  56. {
  57. if (_playerInstance == null)
  58. return;
  59. L2Summon summon = _playerInstance.getPet();
  60. if (summon != null)
  61. summon.unSummon(_playerInstance);
  62. if (Config.TVT_EVENT_EFFECTS_REMOVAL == 0
  63. || (Config.TVT_EVENT_EFFECTS_REMOVAL == 1 && (_playerInstance.getTeam() == 0 || (_playerInstance.isInDuel() && _playerInstance.getDuelState() != Duel.DUELSTATE_INTERRUPTED))))
  64. _playerInstance.stopAllEffectsExceptThoseThatLastThroughDeath();
  65. if (_playerInstance.isInDuel())
  66. _playerInstance.setDuelState(Duel.DUELSTATE_INTERRUPTED);
  67. int TvTInstance = TvTEvent.getTvTEventInstance();
  68. if (TvTInstance != 0)
  69. {
  70. if (TvTEvent.isStarted() && !_adminRemove)
  71. {
  72. _playerInstance.setInstanceId(TvTInstance);
  73. }
  74. else
  75. {
  76. _playerInstance.setInstanceId(0);
  77. }
  78. }
  79. else
  80. {
  81. _playerInstance.setInstanceId(0);
  82. }
  83. _playerInstance.doRevive();
  84. _playerInstance.teleToLocation( _coordinates[ 0 ] + Rnd.get(101)-50, _coordinates[ 1 ] + Rnd.get(101)-50, _coordinates[ 2 ], false );
  85. if (TvTEvent.isStarted() && !_adminRemove)
  86. _playerInstance.setTeam(TvTEvent.getParticipantTeamId(_playerInstance.getObjectId()) + 1);
  87. else
  88. _playerInstance.setTeam(0);
  89. _playerInstance.setCurrentCp(_playerInstance.getMaxCp());
  90. _playerInstance.setCurrentHp(_playerInstance.getMaxHp());
  91. _playerInstance.setCurrentMp(_playerInstance.getMaxMp());
  92. _playerInstance.broadcastStatusUpdate();
  93. _playerInstance.broadcastUserInfo();
  94. }
  95. }