RequestRestartPoint.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 beeing 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. break;
  106. case 3: // to fortress
  107. fort = FortManager.getInstance().getFort(activeChar);
  108. if (fort != null && fort.getSiege().getIsInProgress())
  109. {
  110. //siege in progress
  111. if (fort.getSiege().checkIsDefender(activeChar.getClan()))
  112. isInDefense = true;
  113. }
  114. if ((activeChar.getClan() == null || activeChar.getClan().getHasFort() == 0) && !isInDefense)
  115. {
  116. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Fortress and he doesn't have Fortress!");
  117. return;
  118. }
  119. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Fortress);
  120. break;
  121. case 4: // to siege HQ
  122. L2SiegeClan siegeClan = null;
  123. castle = CastleManager.getInstance().getCastle(activeChar);
  124. fort = FortManager.getInstance().getFort(activeChar);
  125. if (castle != null && castle.getSiege().getIsInProgress())
  126. siegeClan = castle.getSiege().getAttackerClan(activeChar.getClan());
  127. else if (fort != null && fort.getSiege().getIsInProgress())
  128. siegeClan = fort.getSiege().getAttackerClan(activeChar.getClan());
  129. if (siegeClan == null || siegeClan.getFlag().size() == 0)
  130. {
  131. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - To Siege HQ and he doesn't have Siege HQ!");
  132. return;
  133. }
  134. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.SiegeFlag);
  135. break;
  136. case 5: // Fixed or Player is a festival participant
  137. if (!activeChar.isGM() && !activeChar.isFestivalParticipant())
  138. {
  139. _log.warning("Player ["+activeChar.getName()+"] called RestartPointPacket - Fixed and he isn't festival participant!");
  140. return;
  141. }
  142. loc = new Location(activeChar.getX(), activeChar.getY(), activeChar.getZ()); // spawn them where they died
  143. break;
  144. case 27: // to jail
  145. if (!activeChar.isInJail()) return;
  146. loc = new Location(-114356, -249645, -2984);
  147. default:
  148. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Town);
  149. break;
  150. }
  151. //Teleport and revive
  152. activeChar.setIsPendingRevive(true);
  153. activeChar.teleToLocation(loc, true);
  154. }
  155. }
  156. @Override
  157. protected void runImpl()
  158. {
  159. L2PcInstance activeChar = getClient().getActiveChar();
  160. if (activeChar == null)
  161. return;
  162. //SystemMessage sm2 = new SystemMessage(SystemMessage.S1_S2);
  163. //sm2.addString("type:"+requestedPointType);
  164. //activeChar.sendPacket(sm2);
  165. if (activeChar.isFakeDeath())
  166. {
  167. activeChar.stopFakeDeath(null);
  168. return;
  169. }
  170. else if(!activeChar.isDead())
  171. {
  172. _log.warning("Living player ["+activeChar.getName()+"] called RestartPointPacket! Ban this player!");
  173. return;
  174. }
  175. Castle castle = CastleManager.getInstance().getCastle(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  176. if (castle != null && castle.getSiege().getIsInProgress())
  177. {
  178. //DeathFinalizer df = new DeathFinalizer(10000);
  179. if (activeChar.getClan() != null && castle.getSiege().checkIsAttacker(activeChar.getClan()))
  180. {
  181. // Schedule respawn delay for attacker
  182. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), castle.getSiege().getAttackerRespawnDelay());
  183. if (castle.getSiege().getAttackerRespawnDelay() > 0)
  184. activeChar.sendMessage("You will be re-spawned in " + castle.getSiege().getAttackerRespawnDelay()/1000 + " seconds");
  185. return;
  186. }
  187. }
  188. // run immediatelly (no need to schedule)
  189. new DeathTask(activeChar).run();
  190. }
  191. /* (non-Javadoc)
  192. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  193. */
  194. @Override
  195. public String getType()
  196. {
  197. return _C__6d_REQUESTRESTARTPOINT;
  198. }
  199. }