RequestRestartPoint.java 8.8 KB

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