RequestRestartPoint.java 10 KB

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