Advertisement
Guest User

Request restart

a guest
Apr 29th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  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.l2jhellas.gameserver.network.clientpackets;
  16.  
  17. import java.util.logging.Logger;
  18.  
  19. import Extensions.RaidEvent.L2RaidEvent;
  20.  
  21. import com.l2jhellas.Config;
  22. import com.l2jhellas.gameserver.ThreadPoolManager;
  23. import com.l2jhellas.gameserver.datatables.sql.MapRegionTable;
  24. import com.l2jhellas.gameserver.instancemanager.CastleManager;
  25. import com.l2jhellas.gameserver.instancemanager.ClanHallManager;
  26. import com.l2jhellas.gameserver.model.L2SiegeClan;
  27. import com.l2jhellas.gameserver.model.Location;
  28. import com.l2jhellas.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jhellas.gameserver.model.entity.Castle;
  30. import com.l2jhellas.gameserver.model.entity.ClanHall;
  31. import com.l2jhellas.gameserver.network.SystemMessageId;
  32. import com.l2jhellas.gameserver.network.serverpackets.Revive;
  33. import com.l2jhellas.gameserver.network.serverpackets.SystemMessage;
  34. import com.l2jhellas.util.IllegalPlayerAction;
  35. import com.l2jhellas.util.Util;
  36.  
  37. public final class RequestRestartPoint extends L2GameClientPacket
  38. {
  39. private static Logger _log = Logger.getLogger(RequestRestartPoint.class.getName());
  40. private static final String _C__6d_REQUESTRESTARTPOINT = "[C] 6d RequestRestartPoint";
  41.  
  42. protected int _requestedPointType;
  43. protected boolean _continuation;
  44.  
  45. @Override
  46. protected void readImpl()
  47. {
  48. _requestedPointType = readD();
  49. }
  50.  
  51. class DeathTask implements Runnable
  52. {
  53. L2PcInstance activeChar;
  54.  
  55. DeathTask(L2PcInstance _activeChar)
  56. {
  57. activeChar = _activeChar;
  58. }
  59.  
  60. @Override
  61. public void run()
  62. {
  63. try
  64. {
  65. Location loc = null;
  66. Castle castle = null;
  67.  
  68. if (activeChar.isInJail())
  69. _requestedPointType = 27;
  70. else if (activeChar.isFestivalParticipant())
  71. _requestedPointType = 4;
  72.  
  73. if (activeChar.getKarma() > 0)
  74. loc = new Location(17836, 170178, -3507); //Should teleport to floran vilage
  75. else
  76. {
  77. switch (_requestedPointType)
  78. {
  79. case 1: // to clanhall
  80. if (activeChar.getClan().hasHideout() == 0)
  81. {
  82. // cheater
  83. activeChar.sendMessage("You may not use this respawn point!");
  84. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " used respawn cheat.", IllegalPlayerAction.PUNISH_KICK);
  85. return;
  86. }
  87. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.ClanHall);
  88.  
  89. if (ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()) != null && ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP) != null)
  90. {
  91. activeChar.restoreExp(ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP).getLvl());
  92. }
  93. break;
  94.  
  95. case 2: // to castle
  96. Boolean isInDefense = false;
  97. castle = CastleManager.getInstance().getCastle(activeChar);
  98. if (castle != null && castle.getSiege().getIsInProgress())
  99. {
  100. // siege in progress
  101. if (castle.getSiege().checkIsDefender(activeChar.getClan()))
  102. isInDefense = true;
  103. }
  104. if (activeChar.getClan().hasCastle() == 0 && !isInDefense)
  105. {
  106. // cheater
  107. activeChar.sendMessage("You may not use this respawn point!");
  108. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " used respawn cheat.", IllegalPlayerAction.PUNISH_KICK);
  109. return;
  110. }
  111. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Castle);
  112. break;
  113.  
  114. case 3: // to siege HQ
  115. L2SiegeClan siegeClan = null;
  116. castle = CastleManager.getInstance().getCastle(activeChar);
  117.  
  118. if (castle != null && castle.getSiege().getIsInProgress())
  119. siegeClan = castle.getSiege().getAttackerClan(activeChar.getClan());
  120.  
  121. if (siegeClan == null || siegeClan.getFlag().size() == 0)
  122. {
  123. // cheater
  124. activeChar.sendMessage("You may not use this respawn point!");
  125. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " used respawn cheat.", IllegalPlayerAction.PUNISH_KICK);
  126. return;
  127. }
  128. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.SiegeFlag);
  129. break;
  130.  
  131. case 4: // Fixed or Player is a festival participant
  132. if (!activeChar.isGM() && !activeChar.isFestivalParticipant())
  133. {
  134. // cheater
  135. activeChar.sendMessage("You may not use this respawn point!");
  136. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " used respawn cheat.", IllegalPlayerAction.PUNISH_KICK);
  137. return;
  138. }
  139. loc = new Location(activeChar.getX(), activeChar.getY(), activeChar.getZ()); // spawn them where they died
  140. break;
  141.  
  142. case 27: // to jail
  143. if (!activeChar.isInJail())
  144. return;
  145. loc = new Location(-114356, -249645, -2984);
  146. break;
  147.  
  148. default:
  149. if (Config.ALT_RESPAWN_POINT)
  150. loc = new Location(Config.ALT_RESPAWN_POINT_X, Config.ALT_RESPAWN_POINT_Y, Config.ALT_RESPAWN_POINT_Z);
  151. else
  152. loc = MapRegionTable.getInstance().getTeleToLocation(activeChar, MapRegionTable.TeleportWhereType.Town);
  153. break;
  154. }
  155. }
  156. // Stand up and teleport, proof dvp video.
  157. activeChar.setIsIn7sDungeon(false);
  158. activeChar.setIsPendingRevive(true);
  159. activeChar.teleToLocation(loc, true);
  160.  
  161. }
  162. catch (Throwable e)
  163. {
  164. // _log.log(Level.SEVERE, "", e);
  165. }
  166. }
  167. }
  168.  
  169. @Override
  170. protected void runImpl()
  171. {
  172. L2PcInstance activeChar = getClient().getActiveChar();
  173.  
  174. if (activeChar == null)
  175. return;
  176.  
  177. // SystemMessage sm2 = SystemMessage.getSystemMessage(SystemMessage.S1_S2);
  178. // sm2.addString("type:"+requestedPointType);
  179. // activeChar.sendPacket(sm2);
  180.  
  181. if (activeChar.isFakeDeath())
  182. {
  183. activeChar.stopFakeDeath(null);
  184. activeChar.broadcastPacket(new Revive(activeChar));
  185. return;
  186. }
  187. else if (!activeChar.isAlikeDead())
  188. {
  189. _log.warning("Living player [" + activeChar.getName() + "] called RestartPointPacket! Ban this player!");
  190. return;
  191. }
  192.  
  193. if (activeChar.inClanEvent || activeChar.inPartyEvent || activeChar.inSoloEvent)
  194. {
  195. activeChar.inClanEvent = false;
  196. activeChar.inPartyEvent = false;
  197. activeChar.inSoloEvent = false;
  198. if (L2RaidEvent._eventType == 2)
  199. {
  200. if (L2RaidEvent._participatingPlayers.contains(activeChar))
  201. // Clear player from Event.
  202. L2RaidEvent._participatingPlayers.remove(activeChar);
  203. }
  204. if (L2RaidEvent._eventType == 3)
  205. {
  206. if (activeChar.getParty() != null)
  207. activeChar.leaveParty();
  208. activeChar.sendMessage("You have been kicked from the party.");
  209. }
  210. activeChar.sendMessage("You've been erased from the event!");
  211. int num = L2RaidEvent._participatingPlayers.size();
  212. if (num > 0 && num != 1)
  213. num -= 1;
  214. else
  215. L2RaidEvent.hardFinish();
  216. }
  217.  
  218. Castle castle = CastleManager.getInstance().getCastle(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  219. if (castle != null && castle.getSiege().getIsInProgress())
  220. {
  221. // DeathFinalizer df = new DeathFinalizer(10000);
  222. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2);
  223. if (activeChar.getClan() != null && castle.getSiege().checkIsAttacker(activeChar.getClan()))
  224. {
  225. // Schedule respawn delay for attacker
  226. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), castle.getSiege().getAttackerRespawnDelay());
  227. sm.addString("You will be re-spawned in " + castle.getSiege().getAttackerRespawnDelay() / 1000 + " seconds.");
  228. activeChar.sendPacket(sm);
  229. }
  230. else
  231. {
  232. // Schedule respawn delay for defender with penalty for CT lose
  233. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), castle.getSiege().getDefenderRespawnDelay());
  234. sm.addString("You will be re-spawned in " + castle.getSiege().getDefenderRespawnDelay() / 1000 + " seconds.");
  235. activeChar.sendPacket(sm);
  236. }
  237. sm = null;
  238. return;
  239. }
  240.  
  241. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), 1);
  242. }
  243.  
  244. @Override
  245. public String getType()
  246. {
  247. return _C__6d_REQUESTRESTARTPOINT;
  248. }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement