RequestRestartPoint.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.gameserver.ThreadPoolManager;
  18. import com.l2jserver.gameserver.datatables.MapRegionTable;
  19. import com.l2jserver.gameserver.instancemanager.CastleManager;
  20. import com.l2jserver.gameserver.instancemanager.ClanHallManager;
  21. import com.l2jserver.gameserver.instancemanager.FortManager;
  22. import com.l2jserver.gameserver.model.L2SiegeClan;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.entity.Castle;
  26. import com.l2jserver.gameserver.model.entity.ClanHall;
  27. import com.l2jserver.gameserver.model.entity.Fort;
  28. import com.l2jserver.gameserver.model.entity.TvTEvent;
  29. /**
  30. * This class ...
  31. *
  32. * @version $Revision: 1.7.2.3.2.6 $ $Date: 2005/03/27 15:29:30 $
  33. */
  34. public final class RequestRestartPoint extends L2GameClientPacket
  35. {
  36. private static final String _C__6d_REQUESTRESTARTPOINT = "[C] 6d RequestRestartPoint";
  37. private static Logger _log = Logger.getLogger(RequestRestartPoint.class.getName());
  38. protected int _requestedPointType;
  39. protected boolean _continuation;
  40. @Override
  41. protected void readImpl()
  42. {
  43. _requestedPointType = readD();
  44. }
  45. class DeathTask implements Runnable
  46. {
  47. final L2PcInstance activeChar;
  48. DeathTask (L2PcInstance _activeChar)
  49. {
  50. activeChar = _activeChar;
  51. }
  52. @SuppressWarnings("synthetic-access")
  53. public void run()
  54. {
  55. Location loc = null;
  56. Castle castle = null;
  57. Fort fort = null;
  58. Boolean isInDefense = false;
  59. int instanceId = 0;
  60. // force jail
  61. if (activeChar.isInJail())
  62. {
  63. _requestedPointType = 27;
  64. }
  65. else if (activeChar.isFestivalParticipant())
  66. {
  67. _requestedPointType = 5;
  68. }
  69. switch (_requestedPointType)
  70. {
  71. case 1: // to clanhall
  72. if (activeChar.getClan() == null || activeChar.getClan().getHasHideout() == 0)
  73. {
  74. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Clanhall and he doesn't have Clanhall!");
  75. return;
  76. }
  77. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.ClanHall);
  78. if (ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan())!= null &&
  79. ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP) != null)
  80. {
  81. activeChar.restoreExp(ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP).getLvl());
  82. }
  83. break;
  84. case 2: // to castle
  85. castle = CastleManager.getInstance().getCastle(activeChar);
  86. if (castle != null && castle.getSiege().getIsInProgress())
  87. {
  88. // Siege in progress
  89. if (castle.getSiege().checkIsDefender(activeChar.getClan()))
  90. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Castle);
  91. // Just in case you lost castle while being dead.. Port to nearest Town.
  92. else if (castle.getSiege().checkIsAttacker(activeChar.getClan()))
  93. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Town);
  94. else
  95. {
  96. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Castle and he doesn't have Castle!");
  97. return;
  98. }
  99. }
  100. else
  101. {
  102. if (activeChar.getClan() == null || activeChar.getClan().getHasCastle() == 0)
  103. return;
  104. else
  105. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Castle);
  106. }
  107. if (CastleManager.getInstance().getCastleByOwner(activeChar.getClan())!= null &&
  108. CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).getFunction(Castle.FUNC_RESTORE_EXP) != null)
  109. {
  110. activeChar.restoreExp(CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).getFunction(Castle.FUNC_RESTORE_EXP).getLvl());
  111. }
  112. break;
  113. case 3: // to fortress
  114. fort = FortManager.getInstance().getFort(activeChar);
  115. if ((activeChar.getClan() == null || activeChar.getClan().getHasFort() == 0) && !isInDefense)
  116. {
  117. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Fortress and he doesn't have Fortress!");
  118. return;
  119. }
  120. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Fortress);
  121. if (FortManager.getInstance().getFortByOwner(activeChar.getClan())!= null &&
  122. FortManager.getInstance().getFortByOwner(activeChar.getClan()).getFunction(Fort.FUNC_RESTORE_EXP) != null)
  123. {
  124. activeChar.restoreExp(FortManager.getInstance().getFortByOwner(activeChar.getClan()).getFunction(Fort.FUNC_RESTORE_EXP).getLvl());
  125. }
  126. break;
  127. case 4: // to siege HQ
  128. L2SiegeClan siegeClan = null;
  129. castle = CastleManager.getInstance().getCastle(activeChar);
  130. fort = FortManager.getInstance().getFort(activeChar);
  131. if (castle != null && castle.getSiege().getIsInProgress())
  132. siegeClan = castle.getSiege().getAttackerClan(activeChar.getClan());
  133. else if (fort != null && fort.getSiege().getIsInProgress())
  134. siegeClan = fort.getSiege().getAttackerClan(activeChar.getClan());
  135. if (siegeClan == null || siegeClan.getFlag().isEmpty())
  136. {
  137. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Siege HQ and he doesn't have Siege HQ!");
  138. return;
  139. }
  140. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.SiegeFlag);
  141. break;
  142. case 5: // Fixed or Player is a festival participant
  143. if (!activeChar.isGM() && !activeChar.isFestivalParticipant())
  144. {
  145. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - Fixed and he isn't festival participant!");
  146. return;
  147. }
  148. instanceId = activeChar.getInstanceId();
  149. loc = new Location(activeChar.getX(), activeChar.getY(), activeChar.getZ()); // spawn them where they died
  150. break;
  151. case 27: // to jail
  152. if (!activeChar.isInJail()) return;
  153. loc = new Location(-114356, -249645, -2984);
  154. break;
  155. default:
  156. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Town);
  157. break;
  158. }
  159. // Teleport and revive
  160. activeChar.setInstanceId(instanceId);
  161. activeChar.setIsIn7sDungeon(false);
  162. activeChar.setIsPendingRevive(true);
  163. activeChar.teleToLocation(loc, true);
  164. }
  165. }
  166. @Override
  167. protected void runImpl()
  168. {
  169. L2PcInstance activeChar = getClient().getActiveChar();
  170. if (activeChar == null)
  171. return;
  172. if (TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  173. return;
  174. //SystemMessage sm2 = new SystemMessage(SystemMessage.S1_S2);
  175. //sm2.addString("type:"+requestedPointType);
  176. //activeChar.sendPacket(sm2);
  177. if (activeChar.isFakeDeath())
  178. {
  179. activeChar.stopFakeDeath(null);
  180. return;
  181. }
  182. else if(!activeChar.isDead())
  183. {
  184. _log.warning("Living player ["+activeChar.getName()+"] called RestartPointPacket! Ban this player!");
  185. return;
  186. }
  187. Castle castle = CastleManager.getInstance().getCastle(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  188. if (castle != null && castle.getSiege().getIsInProgress())
  189. {
  190. if (activeChar.getClan() != null && castle.getSiege().checkIsAttacker(activeChar.getClan()))
  191. {
  192. // Schedule respawn delay for attacker
  193. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), castle.getSiege().getAttackerRespawnDelay());
  194. if (castle.getSiege().getAttackerRespawnDelay() > 0)
  195. activeChar.sendMessage("You will be re-spawned in " + castle.getSiege().getAttackerRespawnDelay()/1000 + " seconds");
  196. return;
  197. }
  198. }
  199. // run immediately (no need to schedule)
  200. new DeathTask(activeChar).run();
  201. }
  202. /* (non-Javadoc)
  203. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  204. */
  205. @Override
  206. public String getType()
  207. {
  208. return _C__6d_REQUESTRESTARTPOINT;
  209. }
  210. }