RequestRestartPoint.java 8.3 KB

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