TvTEventTeleporter.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model.entity;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.ThreadPoolManager;
  22. import com.l2jserver.gameserver.enums.Team;
  23. import com.l2jserver.gameserver.model.actor.L2Summon;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.util.Rnd;
  26. public class TvTEventTeleporter implements Runnable
  27. {
  28. /** The instance of the player to teleport */
  29. private L2PcInstance _playerInstance = null;
  30. /** Coordinates of the spot to teleport to */
  31. private int[] _coordinates = new int[3];
  32. /** Admin removed this player from event */
  33. private boolean _adminRemove = false;
  34. /**
  35. * Initialize the teleporter and start the delayed task.
  36. * @param playerInstance
  37. * @param coordinates
  38. * @param fastSchedule
  39. * @param adminRemove
  40. */
  41. public TvTEventTeleporter(L2PcInstance playerInstance, int[] coordinates, boolean fastSchedule, boolean adminRemove)
  42. {
  43. _playerInstance = playerInstance;
  44. _coordinates = coordinates;
  45. _adminRemove = adminRemove;
  46. long delay = (TvTEvent.isStarted() ? Config.TVT_EVENT_RESPAWN_TELEPORT_DELAY : Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY) * 1000;
  47. ThreadPoolManager.getInstance().scheduleGeneral(this, fastSchedule ? 0 : delay);
  48. }
  49. /**
  50. * The task method to teleport the player<br>
  51. * 1. Unsummon pet if there is one<br>
  52. * 2. Remove all effects<br>
  53. * 3. Revive and full heal the player<br>
  54. * 4. Teleport the player<br>
  55. * 5. Broadcast status and user info
  56. */
  57. @Override
  58. public void run()
  59. {
  60. if (_playerInstance == null)
  61. {
  62. return;
  63. }
  64. L2Summon summon = _playerInstance.getSummon();
  65. if (summon != null)
  66. {
  67. summon.unSummon(_playerInstance);
  68. }
  69. if ((Config.TVT_EVENT_EFFECTS_REMOVAL == 0) || ((Config.TVT_EVENT_EFFECTS_REMOVAL == 1) && ((_playerInstance.getTeam() == Team.NONE) || (_playerInstance.isInDuel() && (_playerInstance.getDuelState() != Duel.DUELSTATE_INTERRUPTED)))))
  70. {
  71. _playerInstance.stopAllEffectsExceptThoseThatLastThroughDeath();
  72. }
  73. if (_playerInstance.isInDuel())
  74. {
  75. _playerInstance.setDuelState(Duel.DUELSTATE_INTERRUPTED);
  76. }
  77. int TvTInstance = TvTEvent.getTvTEventInstance();
  78. if (TvTInstance != 0)
  79. {
  80. if (TvTEvent.isStarted() && !_adminRemove)
  81. {
  82. _playerInstance.setInstanceId(TvTInstance);
  83. }
  84. else
  85. {
  86. _playerInstance.setInstanceId(0);
  87. }
  88. }
  89. else
  90. {
  91. _playerInstance.setInstanceId(0);
  92. }
  93. _playerInstance.doRevive();
  94. _playerInstance.teleToLocation((_coordinates[0] + Rnd.get(101)) - 50, (_coordinates[1] + Rnd.get(101)) - 50, _coordinates[2], false);
  95. if (TvTEvent.isStarted() && !_adminRemove)
  96. {
  97. int teamId = TvTEvent.getParticipantTeamId(_playerInstance.getObjectId()) + 1;
  98. switch (teamId)
  99. {
  100. case 0:
  101. _playerInstance.setTeam(Team.NONE);
  102. break;
  103. case 1:
  104. _playerInstance.setTeam(Team.BLUE);
  105. break;
  106. case 2:
  107. _playerInstance.setTeam(Team.RED);
  108. break;
  109. }
  110. }
  111. else
  112. {
  113. _playerInstance.setTeam(Team.NONE);
  114. }
  115. _playerInstance.setCurrentCp(_playerInstance.getMaxCp());
  116. _playerInstance.setCurrentHp(_playerInstance.getMaxHp());
  117. _playerInstance.setCurrentMp(_playerInstance.getMaxMp());
  118. _playerInstance.broadcastStatusUpdate();
  119. _playerInstance.broadcastUserInfo();
  120. }
  121. }