2
0

RequestRestartPoint.java 9.1 KB

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