RequestRestartPoint.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.ThreadPoolManager;
  21. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  22. import com.l2jserver.gameserver.instancemanager.CastleManager;
  23. import com.l2jserver.gameserver.instancemanager.ClanHallManager;
  24. import com.l2jserver.gameserver.instancemanager.FortManager;
  25. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  26. import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
  27. import com.l2jserver.gameserver.model.L2SiegeClan;
  28. import com.l2jserver.gameserver.model.Location;
  29. import com.l2jserver.gameserver.model.TeleportWhereType;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  32. import com.l2jserver.gameserver.model.entity.Castle;
  33. import com.l2jserver.gameserver.model.entity.ClanHall;
  34. import com.l2jserver.gameserver.model.entity.Fort;
  35. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  36. /**
  37. * This class ...
  38. * @version $Revision: 1.7.2.3.2.6 $ $Date: 2005/03/27 15:29:30 $
  39. */
  40. public final class RequestRestartPoint extends L2GameClientPacket
  41. {
  42. private static final String _C__7D_REQUESTRESTARTPOINT = "[C] 7D RequestRestartPoint";
  43. protected int _requestedPointType;
  44. protected boolean _continuation;
  45. @Override
  46. protected void readImpl()
  47. {
  48. _requestedPointType = readD();
  49. }
  50. class DeathTask implements Runnable
  51. {
  52. final L2PcInstance activeChar;
  53. DeathTask(L2PcInstance _activeChar)
  54. {
  55. activeChar = _activeChar;
  56. }
  57. @Override
  58. public void run()
  59. {
  60. portPlayer(activeChar);
  61. }
  62. }
  63. @Override
  64. protected void runImpl()
  65. {
  66. L2PcInstance activeChar = getClient().getActiveChar();
  67. if (activeChar == null)
  68. {
  69. return;
  70. }
  71. if (!activeChar.canRevive())
  72. {
  73. return;
  74. }
  75. if (activeChar.isFakeDeath())
  76. {
  77. activeChar.stopFakeDeath(true);
  78. return;
  79. }
  80. else if (!activeChar.isDead())
  81. {
  82. _log.warning("Living player [" + activeChar.getName() + "] called RestartPointPacket! Ban this player!");
  83. return;
  84. }
  85. Castle castle = CastleManager.getInstance().getCastle(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  86. if ((castle != null) && castle.getSiege().isInProgress())
  87. {
  88. if ((activeChar.getClan() != null) && castle.getSiege().checkIsAttacker(activeChar.getClan()))
  89. {
  90. // Schedule respawn delay for attacker
  91. ThreadPoolManager.getInstance().scheduleGeneral(new DeathTask(activeChar), castle.getSiege().getAttackerRespawnDelay());
  92. if (castle.getSiege().getAttackerRespawnDelay() > 0)
  93. {
  94. activeChar.sendMessage("You will be re-spawned in " + (castle.getSiege().getAttackerRespawnDelay() / 1000) + " seconds");
  95. }
  96. return;
  97. }
  98. }
  99. portPlayer(activeChar);
  100. }
  101. protected final void portPlayer(final L2PcInstance activeChar)
  102. {
  103. Location loc = null;
  104. Castle castle = null;
  105. Fort fort = null;
  106. SiegableHall hall = null;
  107. boolean isInDefense = false;
  108. int instanceId = 0;
  109. // force jail
  110. if (activeChar.isJailed())
  111. {
  112. _requestedPointType = 27;
  113. }
  114. else if (activeChar.isFestivalParticipant())
  115. {
  116. _requestedPointType = 5;
  117. }
  118. switch (_requestedPointType)
  119. {
  120. case 1: // to clanhall
  121. {
  122. if ((activeChar.getClan() == null) || (activeChar.getClan().getHideoutId() == 0))
  123. {
  124. _log.warning("Player [" + activeChar.getName() + "] called RestartPointPacket - To Clanhall and he doesn't have Clanhall!");
  125. return;
  126. }
  127. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.CLANHALL);
  128. if ((ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()) != null) && (ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP) != null))
  129. {
  130. activeChar.restoreExp(ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()).getFunction(ClanHall.FUNC_RESTORE_EXP).getLvl());
  131. }
  132. break;
  133. }
  134. case 2: // to castle
  135. {
  136. castle = CastleManager.getInstance().getCastle(activeChar);
  137. if ((castle != null) && castle.getSiege().isInProgress())
  138. {
  139. // Siege in progress
  140. if (castle.getSiege().checkIsDefender(activeChar.getClan()))
  141. {
  142. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.CASTLE);
  143. }
  144. else if (castle.getSiege().checkIsAttacker(activeChar.getClan()))
  145. {
  146. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.TOWN);
  147. }
  148. else
  149. {
  150. _log.warning("Player [" + activeChar.getName() + "] called RestartPointPacket - To Castle and he doesn't have Castle!");
  151. return;
  152. }
  153. }
  154. else
  155. {
  156. if ((activeChar.getClan() == null) || (activeChar.getClan().getCastleId() == 0))
  157. {
  158. return;
  159. }
  160. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.CASTLE);
  161. }
  162. if ((CastleManager.getInstance().getCastleByOwner(activeChar.getClan()) != null) && (CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).getFunction(Castle.FUNC_RESTORE_EXP) != null))
  163. {
  164. activeChar.restoreExp(CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).getFunction(Castle.FUNC_RESTORE_EXP).getLvl());
  165. }
  166. break;
  167. }
  168. case 3: // to fortress
  169. {
  170. if (((activeChar.getClan() == null) || (activeChar.getClan().getFortId() == 0)) && !isInDefense)
  171. {
  172. _log.warning("Player [" + activeChar.getName() + "] called RestartPointPacket - To Fortress and he doesn't have Fortress!");
  173. return;
  174. }
  175. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.FORTRESS);
  176. if ((FortManager.getInstance().getFortByOwner(activeChar.getClan()) != null) && (FortManager.getInstance().getFortByOwner(activeChar.getClan()).getFunction(Fort.FUNC_RESTORE_EXP) != null))
  177. {
  178. activeChar.restoreExp(FortManager.getInstance().getFortByOwner(activeChar.getClan()).getFunction(Fort.FUNC_RESTORE_EXP).getLvl());
  179. }
  180. break;
  181. }
  182. case 4: // to siege HQ
  183. {
  184. L2SiegeClan siegeClan = null;
  185. castle = CastleManager.getInstance().getCastle(activeChar);
  186. fort = FortManager.getInstance().getFort(activeChar);
  187. hall = CHSiegeManager.getInstance().getNearbyClanHall(activeChar);
  188. L2SiegeFlagInstance flag = TerritoryWarManager.getInstance().getHQForClan(activeChar.getClan());
  189. if ((castle != null) && castle.getSiege().isInProgress())
  190. {
  191. siegeClan = castle.getSiege().getAttackerClan(activeChar.getClan());
  192. }
  193. else if ((fort != null) && fort.getSiege().isInProgress())
  194. {
  195. siegeClan = fort.getSiege().getAttackerClan(activeChar.getClan());
  196. }
  197. else if ((hall != null) && hall.isInSiege())
  198. {
  199. siegeClan = hall.getSiege().getAttackerClan(activeChar.getClan());
  200. }
  201. if (((siegeClan == null) || siegeClan.getFlag().isEmpty()) && (flag == null))
  202. {
  203. // Check if clan hall has inner spawns loc
  204. if (hall != null)
  205. {
  206. loc = hall.getSiege().getInnerSpawnLoc(activeChar);
  207. if (loc != null)
  208. {
  209. break;
  210. }
  211. }
  212. _log.warning("Player [" + activeChar.getName() + "] called RestartPointPacket - To Siege HQ and he doesn't have Siege HQ!");
  213. return;
  214. }
  215. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.SIEGEFLAG);
  216. break;
  217. }
  218. case 5: // Fixed or Player is a festival participant
  219. {
  220. if (!activeChar.isGM() && !activeChar.isFestivalParticipant() && !activeChar.getInventory().haveItemForSelfResurrection())
  221. {
  222. _log.warning("Player [" + activeChar.getName() + "] called RestartPointPacket - Fixed and he isn't festival participant!");
  223. return;
  224. }
  225. if (activeChar.isGM() || activeChar.destroyItemByItemId("Feather", 10649, 1, activeChar, false) || activeChar.destroyItemByItemId("Feather", 13300, 1, activeChar, false) || activeChar.destroyItemByItemId("Feather", 13128, 1, activeChar, false))
  226. {
  227. activeChar.doRevive(100.00);
  228. }
  229. else
  230. // Festival Participant
  231. {
  232. instanceId = activeChar.getInstanceId();
  233. loc = new Location(activeChar);
  234. }
  235. break;
  236. }
  237. case 6: // TODO: agathion ress
  238. {
  239. break;
  240. }
  241. case 27: // to jail
  242. {
  243. if (!activeChar.isJailed())
  244. {
  245. return;
  246. }
  247. loc = new Location(-114356, -249645, -2984);
  248. break;
  249. }
  250. default:
  251. {
  252. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.TOWN);
  253. break;
  254. }
  255. }
  256. // Teleport and revive
  257. if (loc != null)
  258. {
  259. activeChar.setInstanceId(instanceId);
  260. activeChar.setIsIn7sDungeon(false);
  261. activeChar.setIsPendingRevive(true);
  262. activeChar.teleToLocation(loc, true);
  263. }
  264. }
  265. @Override
  266. public String getType()
  267. {
  268. return _C__7D_REQUESTRESTARTPOINT;
  269. }
  270. }