Guest User

Untitled

a guest
Aug 2nd, 2017
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. /*
  2. * L2jFrozen Project - www.l2jfrozen.com
  3. *
  4. * This program is free software: you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License as published by the Free Software
  6. * Foundation, either version 3 of the License, or (at your option) any later
  7. * version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. * details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package com.l2jfrozen.gameserver.model.zone.type;
  18.  
  19. import java.util.List;
  20. import java.util.Map;
  21.  
  22. import javolution.util.FastMap;
  23.  
  24. import com.l2jfrozen.Config;
  25. import com.l2jfrozen.gameserver.GameServer;
  26. import com.l2jfrozen.gameserver.datatables.csv.MapRegionTable;
  27. import com.l2jfrozen.gameserver.model.L2Character;
  28. import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  29. import com.l2jfrozen.gameserver.model.actor.instance.L2NpcInstance;
  30. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jfrozen.gameserver.model.zone.L2ZoneType;
  32. import com.l2jfrozen.util.L2FastList;
  33.  
  34. /**
  35. * @author DaRkRaGe
  36. */
  37. public class L2BossZone extends L2ZoneType
  38. {
  39. private String _zoneName;
  40. private int _timeInvade;
  41. private boolean _enabled = true; // default value, unless overridden by xml...
  42. private boolean _IsFlyingEnable = true; // default value, unless overridden by xml...
  43.  
  44. // track the times that players got disconnected. Players are allowed
  45. // to LOGGER back into the zone as long as their LOGGER-out was within _timeInvade
  46. // time...
  47. // <player objectId, expiration time in milliseconds>
  48. private final FastMap<Integer, Long> _playerAllowedReEntryTimes;
  49.  
  50. // track the players admitted to the zone who should be allowed back in
  51. // after reboot/server downtime (outside of their control), within 30
  52. // of server restart
  53. private List<Integer> _playersAllowed;
  54.  
  55. private final int _bossId;
  56.  
  57. public L2BossZone(final int id, final int boss_id)
  58. {
  59. super(id);
  60. _bossId = boss_id;
  61. _playerAllowedReEntryTimes = new FastMap<>();
  62. _playersAllowed = new L2FastList<>();
  63. }
  64.  
  65. @Override
  66. public void setParameter(final String name, final String value)
  67. {
  68. if (name.equals("name"))
  69. {
  70. _zoneName = value;
  71. }
  72. else if (name.equals("InvadeTime"))
  73. {
  74. _timeInvade = Integer.parseInt(value);
  75. }
  76. else if (name.equals("EnabledByDefault"))
  77. {
  78. _enabled = Boolean.parseBoolean(value);
  79. }
  80. else if (name.equals("flying"))
  81. {
  82. _IsFlyingEnable = Boolean.parseBoolean(value);
  83. }
  84. else
  85. {
  86. super.setParameter(name, value);
  87. }
  88. }
  89.  
  90. @Override
  91. /**
  92. * Boss zones have special behaviors for player characters. Players are
  93. * automatically teleported out when the attempt to enter these zones,
  94. * except if the time at which they enter the zone is prior to the entry
  95. * expiration time set for that player. Entry expiration times are set by
  96. * any one of the following: 1) A player logs out while in a zone
  97. * (Expiration gets set to logoutTime + _timeInvade) 2) An external source
  98. * (such as a quest or AI of NPC) set up the player for entry.
  99. *
  100. * There exists one more case in which the player will be allowed to enter.
  101. * That is if the server recently rebooted (boot-up time more recent than
  102. * currentTime - _timeInvade) AND the player was in the zone prior to reboot.
  103. */
  104. protected void onEnter(final L2Character character)
  105. {
  106. if (_enabled)
  107. {
  108. if (character instanceof L2PcInstance)
  109. {
  110. // Thread.dumpStack();
  111. L2PcInstance player = (L2PcInstance) character;
  112.  
  113. if (player.isGM() || Config.ALLOW_DIRECT_TP_TO_BOSS_ROOM)
  114. {
  115. player.sendMessage("You entered " + _zoneName);
  116. return;
  117. }
  118. if(player.getPvpFlag()==0)
  119. {
  120. player.setPvpFlag(1);
  121. }
  122. // Ignore the check for Van Halter zone id 12014 if player got marks
  123. if (getId() == 12014)
  124. {
  125. final L2ItemInstance VisitorsMark = player.getInventory().getItemByItemId(8064);
  126. final L2ItemInstance FadedVisitorsMark = player.getInventory().getItemByItemId(8065);
  127. final L2ItemInstance PagansMark = player.getInventory().getItemByItemId(8067);
  128.  
  129. final long mark1 = VisitorsMark == null ? 0 : VisitorsMark.getCount();
  130. final long mark2 = FadedVisitorsMark == null ? 0 : FadedVisitorsMark.getCount();
  131. final long mark3 = PagansMark == null ? 0 : PagansMark.getCount();
  132.  
  133. if (mark1 != 0 || mark2 != 0 || mark3 != 0)
  134. return;
  135. }
  136.  
  137. if (!player.isGM() && player.isFlying() && !_IsFlyingEnable)
  138. {
  139. player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  140. return;
  141. }
  142.  
  143. // if player has been (previously) cleared by npc/ai for entry and the zone is
  144. // set to receive players (aka not waiting for boss to respawn)
  145. if (_playersAllowed.contains(character.getObjectId()))
  146. {
  147. // Get the information about this player's last logout-exit from this zone.
  148. final Long expirationTime = _playerAllowedReEntryTimes.get(character.getObjectId());
  149.  
  150. // with legal entries, do nothing.
  151. if (expirationTime == null) // legal null expirationTime entries
  152. {
  153. final long serverStartTime = GameServer.dateTimeServerStarted.getTimeInMillis();
  154.  
  155. if (serverStartTime > System.currentTimeMillis() - _timeInvade)
  156. return;
  157. }
  158. else
  159. {
  160. // legal non-null logoutTime entries
  161. _playerAllowedReEntryTimes.remove(character.getObjectId());
  162.  
  163. if (expirationTime.longValue() > System.currentTimeMillis())
  164. return;
  165. }
  166. _playersAllowed.remove(_playersAllowed.indexOf(character.getObjectId()));
  167. }
  168.  
  169. // teleport out all players who attempt "illegal" (re-)entry
  170. player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  171. player = null;
  172. }
  173. }
  174. }
  175.  
  176. /**
  177. * Some GrandBosses send all players in zone to a specific part of the zone, rather than just removing them all. If this is the case, this command should be used. If this is no the case, then use oustAllPlayers().
  178. * @param x
  179. * @param y
  180. * @param z
  181. */
  182.  
  183. public void movePlayersTo(final int x, final int y, final int z)
  184. {
  185. if (_characterList.isEmpty())
  186. return;
  187.  
  188. for (final L2Character character : _characterList.values())
  189. {
  190. if (character instanceof L2PcInstance)
  191. {
  192. final L2PcInstance player = (L2PcInstance) character;
  193. if (player.isOnline() == 1)
  194. player.teleToLocation(x, y, z);
  195. }
  196. }
  197. }
  198.  
  199. @Override
  200. protected void onExit(final L2Character character)
  201. {
  202. if (_enabled)
  203. {
  204. if (character instanceof L2PcInstance)
  205. {
  206. // Thread.dumpStack();
  207. L2PcInstance player = (L2PcInstance) character;
  208.  
  209. if (player.isGM())
  210. {
  211. player.sendMessage("You left " + _zoneName);
  212. return;
  213. }
  214. if(player.getPvpFlag()==1)
  215. {
  216. player.setPvpFlag(0);
  217. player.broadcastUserInfo();
  218. }
  219. // if the player just got disconnected/logged out, store the dc time so that
  220. // decisions can be made later about allowing or not the player to LOGGER into the zone
  221. if (player.isOnline() == 0 && _playersAllowed.contains(character.getObjectId()))
  222. {
  223. // mark the time that the player left the zone
  224. _playerAllowedReEntryTimes.put(character.getObjectId(), System.currentTimeMillis() + _timeInvade);
  225. }
  226.  
  227. player = null;
  228. }
  229. }
  230. }
  231.  
  232. public void setZoneEnabled(final boolean flag)
  233. {
  234. if (_enabled != flag)
  235. {
  236. oustAllPlayers();
  237. }
  238.  
  239. _enabled = flag;
  240. }
  241.  
  242. public String getZoneName()
  243. {
  244. return _zoneName;
  245. }
  246.  
  247. public int getTimeInvade()
  248. {
  249. return _timeInvade;
  250. }
  251.  
  252. public void setAllowedPlayers(final List<Integer> list)
  253. {
  254. if (list != null)
  255. {
  256. _playersAllowed = list;
  257. }
  258. }
  259.  
  260. public List<Integer> getAllowedPlayers()
  261. {
  262. return _playersAllowed;
  263. }
  264.  
  265. public boolean isPlayerAllowed(final L2PcInstance player)
  266. {
  267. if (player.isGM())
  268. return true;
  269. else if (_playersAllowed.contains(player.getObjectId()))
  270. return true;
  271. else
  272. {
  273. player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  274. return false;
  275. }
  276. }
  277.  
  278. /**
  279. * Occasionally, all players need to be sent out of the zone (for example, if the players are just running around without fighting for too long, or if all players die, etc). This call sends all online players to town and marks offline players to be teleported (by clearing their relog expiration
  280. * times) when they LOGGER back in (no real need for off-line teleport).
  281. */
  282. public void oustAllPlayers()
  283. {
  284. if (_characterList == null)
  285. return;
  286.  
  287. if (_characterList.isEmpty())
  288. return;
  289.  
  290. for (final L2Character character : _characterList.values())
  291. {
  292. if (character == null)
  293. {
  294. continue;
  295. }
  296.  
  297. if (character instanceof L2PcInstance)
  298. {
  299. L2PcInstance player = (L2PcInstance) character;
  300.  
  301. if (player.isOnline() == 1)
  302. {
  303. player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  304. }
  305.  
  306. player = null;
  307. }
  308. }
  309. _playerAllowedReEntryTimes.clear();
  310. _playersAllowed.clear();
  311. }
  312.  
  313. /**
  314. * This function is to be used by external sources, such as quests and AI in order to allow a player for entry into the zone for some time. Naturally if the player does not enter within the allowed time, he/she will be teleported out again...
  315. * @param player reference to the player we wish to allow
  316. * @param durationInSec amount of time in seconds during which entry is valid.
  317. */
  318. public void allowPlayerEntry(final L2PcInstance player, final int durationInSec)
  319. {
  320. if (!player.isGM())
  321. {
  322. if (!_playersAllowed.contains(player.getObjectId()))
  323. {
  324. _playersAllowed.add(player.getObjectId());
  325. }
  326. _playerAllowedReEntryTimes.put(player.getObjectId(), System.currentTimeMillis() + durationInSec * 1000);
  327. }
  328. }
  329.  
  330. @Override
  331. protected void onDieInside(final L2Character character)
  332. {
  333. }
  334.  
  335. @Override
  336. protected void onReviveInside(final L2Character character)
  337. {
  338. }
  339.  
  340. public void updateKnownList(final L2NpcInstance npc)
  341. {
  342. if (_characterList == null || _characterList.isEmpty())
  343. return;
  344.  
  345. final Map<Integer, L2PcInstance> npcKnownPlayers = npc.getKnownList().getKnownPlayers();
  346. for (final L2Character character : _characterList.values())
  347. {
  348. if (character == null)
  349. continue;
  350. if (character instanceof L2PcInstance)
  351. {
  352. final L2PcInstance player = (L2PcInstance) character;
  353. if (player.isOnline() == 1 || player.isInOfflineMode()) // online players must be all taken into account, also offliner
  354. npcKnownPlayers.put(player.getObjectId(), player);
  355. }
  356. }
  357. return;
  358. }
  359.  
  360. public int getBossId()
  361. {
  362. return _bossId;
  363. }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment