BlockCheckerEngine.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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.l2jserver.gameserver.model.entity;
  16. import java.util.Map.Entry;
  17. import java.util.concurrent.ScheduledFuture;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javolution.util.FastList;
  21. import javolution.util.FastMap;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.ThreadPoolManager;
  24. import com.l2jserver.gameserver.datatables.NpcTable;
  25. import com.l2jserver.gameserver.datatables.SkillTable;
  26. import com.l2jserver.gameserver.datatables.SpawnTable;
  27. import com.l2jserver.gameserver.instancemanager.HandysBlockCheckerManager;
  28. import com.l2jserver.gameserver.instancemanager.HandysBlockCheckerManager.ArenaParticipantsHolder;
  29. import com.l2jserver.gameserver.model.L2ItemInstance;
  30. import com.l2jserver.gameserver.model.L2Skill;
  31. import com.l2jserver.gameserver.model.L2Spawn;
  32. import com.l2jserver.gameserver.model.L2World;
  33. import com.l2jserver.gameserver.model.actor.L2Character;
  34. import com.l2jserver.gameserver.model.actor.instance.L2BlockInstance;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  37. import com.l2jserver.gameserver.network.SystemMessageId;
  38. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  39. import com.l2jserver.gameserver.network.serverpackets.ExBasicActionList;
  40. import com.l2jserver.gameserver.network.serverpackets.ExCubeGameChangePoints;
  41. import com.l2jserver.gameserver.network.serverpackets.ExCubeGameCloseUI;
  42. import com.l2jserver.gameserver.network.serverpackets.ExCubeGameEnd;
  43. import com.l2jserver.gameserver.network.serverpackets.ExCubeGameExtendedChangePoints;
  44. import com.l2jserver.gameserver.network.serverpackets.RelationChanged;
  45. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  46. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  47. import com.l2jserver.util.Rnd;
  48. /**
  49. * @author BiggBoss
  50. */
  51. public final class BlockCheckerEngine
  52. {
  53. private static final Logger _log = Logger.getLogger(BlockCheckerEngine.class.getName());
  54. // The object which holds all basic members info
  55. private HandysBlockCheckerManager.ArenaParticipantsHolder _holder;
  56. // Maps to hold player of each team and his points
  57. private FastMap<L2PcInstance, Integer> _redTeamPoints = new FastMap<L2PcInstance, Integer>();
  58. private FastMap<L2PcInstance, Integer> _blueTeamPoints = new FastMap<L2PcInstance, Integer>();
  59. // The initial points of the event
  60. private int _redPoints = 15;
  61. private int _bluePoints = 15;
  62. // Current used arena
  63. private int _arena = -1;
  64. // All blocks
  65. private FastList<L2Spawn> _spawns = new FastList<L2Spawn>();
  66. // Sets if the red team won the event at the end of this (used for packets)
  67. private boolean _isRedWinner;
  68. // Time when the event starts. Used on packet sending
  69. private long _startedTime;
  70. // The needed arena coordinates
  71. // Arena X: team1X, team1Y, team2X, team2Y, ArenaCenterX, ArenaCenterY
  72. private static final int[][] _arenaCoordinates =
  73. {
  74. // Arena 0 - Team 1 XY, Team 2 XY - CENTER XY
  75. { -58368, -62745, -57751, -62131, -58053, -62417 },
  76. // Arena 1 - Team 1 XY, Team 2 XY - CENTER XY
  77. { -58350, -63853, -57756, -63266, -58053, -63551 },
  78. // Arena 2 - Team 1 XY, Team 2 XY - CENTER XY
  79. { -57194, -63861, -56580, -63249, -56886, -63551 },
  80. // Arena 3 - Team 1 XY, Team 2 XY - CENTER XY
  81. { -57200, -62727, -56584, -62115, -56850, -62391 }
  82. };
  83. // Common z coordinate
  84. private static final int _zCoord = -2405;
  85. // List of dropped items in event (for later deletion)
  86. private FastList<L2ItemInstance> _drops = new FastList<L2ItemInstance>();
  87. // Default arena
  88. private static final byte DEFAULT_ARENA = -1;
  89. // Event is started
  90. private boolean _isStarted = false;
  91. // Event end
  92. private ScheduledFuture<?> _task;
  93. // Preserve from exploit reward by logging out
  94. private boolean _abnormalEnd = false;
  95. public BlockCheckerEngine(HandysBlockCheckerManager.ArenaParticipantsHolder holder, int arena)
  96. {
  97. _holder = holder;
  98. if(arena > -1 && arena < 4)
  99. _arena = arena;
  100. for(L2PcInstance player : holder.getRedPlayers())
  101. _redTeamPoints.put(player, 0);
  102. for(L2PcInstance player : holder.getBluePlayers())
  103. _blueTeamPoints.put(player, 0);
  104. }
  105. /**
  106. * Updates the player holder before the event starts
  107. * to synchronize all info
  108. * @param holder
  109. */
  110. public void updatePlayersOnStart(ArenaParticipantsHolder holder)
  111. {
  112. _holder = holder;
  113. }
  114. /**
  115. * Returns the current holder object of this
  116. * object engine
  117. * @return HandysBlockCheckerManager.ArenaParticipantsHolder
  118. */
  119. public ArenaParticipantsHolder getHolder()
  120. {
  121. return _holder;
  122. }
  123. /**
  124. * Will return the id of the arena used
  125. * by this event
  126. * @return false;
  127. */
  128. public int getArena()
  129. {
  130. return _arena;
  131. }
  132. /**
  133. * Returns the time when the event
  134. * started
  135. * @return long
  136. */
  137. public long getStarterTime()
  138. {
  139. return _startedTime;
  140. }
  141. /**
  142. * Returns the current red team points
  143. * @return int
  144. */
  145. public int getRedPoints()
  146. {
  147. synchronized(this)
  148. {
  149. return _redPoints;
  150. }
  151. }
  152. /**
  153. * Returns the current blue team points
  154. * @return int
  155. */
  156. public int getBluePoints()
  157. {
  158. synchronized(this)
  159. {
  160. return _bluePoints;
  161. }
  162. }
  163. /**
  164. * Returns the player points
  165. * @param player
  166. * @param isRed
  167. * @return int
  168. */
  169. public int getPlayerPoints(L2PcInstance player, boolean isRed)
  170. {
  171. if(!_redTeamPoints.containsKey(player) && !_blueTeamPoints.containsKey(player))
  172. return 0;
  173. if(isRed)
  174. {
  175. return _redTeamPoints.get(player);
  176. }
  177. return _blueTeamPoints.get(player);
  178. }
  179. /**
  180. * Increases player points for his teams
  181. * @param player
  182. * @param team
  183. */
  184. public synchronized void increasePlayerPoints(L2PcInstance player, int team)
  185. {
  186. if(player == null)
  187. return;
  188. if(team == 0)
  189. {
  190. int points = _redTeamPoints.get(player) + 1;
  191. _redTeamPoints.put(player, points);
  192. _redPoints++;
  193. _bluePoints--;
  194. }
  195. else
  196. {
  197. int points = _blueTeamPoints.get(player) + 1;
  198. _blueTeamPoints.put(player, points);
  199. _bluePoints++;
  200. _redPoints--;
  201. }
  202. }
  203. /**
  204. * Will add a new drop into the list of
  205. * dropped items
  206. * @param item
  207. */
  208. public void addNewDrop(L2ItemInstance item)
  209. {
  210. if(item != null)
  211. _drops.add(item);
  212. }
  213. /**
  214. * Will return true if the event is alredy
  215. * started
  216. * @return boolean
  217. */
  218. public boolean isStarted()
  219. {
  220. return _isStarted;
  221. }
  222. /**
  223. * Will send all packets for the event members with
  224. * the relation info
  225. */
  226. private void broadcastRelationChanged(L2PcInstance plr)
  227. {
  228. for(L2PcInstance p : _holder.getAllPlayers())
  229. {
  230. p.sendPacket(new RelationChanged(plr, plr.getRelation(p), plr.isAutoAttackable(p)));
  231. }
  232. }
  233. /**
  234. * Called when a there is an empty team. The event
  235. * will end.
  236. */
  237. public void endEventAbnormally()
  238. {
  239. try
  240. {
  241. synchronized(this)
  242. {
  243. _isStarted = false;
  244. if(_task != null)
  245. _task.cancel(true);
  246. _abnormalEnd = true;
  247. ThreadPoolManager.getInstance().executeTask(new EndEvent());
  248. if(Config.DEBUG)
  249. _log.config("Handys Block Checker Event at arena "+_arena+" ended due lack of players!");
  250. }
  251. }
  252. catch(Exception e)
  253. {
  254. _log.log(Level.SEVERE, "Couldnt end Block Checker event at "+_arena, e);
  255. }
  256. }
  257. /**
  258. * This inner class set ups all player
  259. * and arena parameters to start the event
  260. */
  261. public class StartEvent implements Runnable
  262. {
  263. // In event used skills
  264. private L2Skill _freeze, _transformationRed, _transformationBlue;
  265. // Common and unparametizer packet
  266. private final ExCubeGameCloseUI _closeUserInterface = new ExCubeGameCloseUI();
  267. public StartEvent()
  268. {
  269. // Initialize all used skills
  270. _freeze = SkillTable.getInstance().getInfo(6034, 1);
  271. _transformationRed = SkillTable.getInstance().getInfo(6035, 1);
  272. _transformationBlue = SkillTable.getInstance().getInfo(6036, 1);
  273. }
  274. /**
  275. * Will set up all player parameters and
  276. * port them to their respective location
  277. * based on their teams
  278. */
  279. private void setUpPlayers()
  280. {
  281. // Set current arena as being used
  282. HandysBlockCheckerManager.getInstance().setArenaBeingUsed(_arena);
  283. // Initialize packets avoiding create a new one per player
  284. _redPoints = _spawns.size() / 2;
  285. _bluePoints = _spawns.size() / 2;
  286. final ExCubeGameChangePoints initialPoints = new ExCubeGameChangePoints(300,_bluePoints,_redPoints);
  287. ExCubeGameExtendedChangePoints clientSetUp;
  288. for(L2PcInstance player : _holder.getAllPlayers())
  289. {
  290. if(player == null) continue;
  291. // Send the secret client packet set up
  292. boolean isRed = _holder.getRedPlayers().contains(player);
  293. clientSetUp = new ExCubeGameExtendedChangePoints(300, _bluePoints, _redPoints, isRed, player, 0);
  294. player.sendPacket(clientSetUp);
  295. player.sendPacket(ActionFailed.STATIC_PACKET);
  296. // Teleport Player - Array access
  297. // Team 0 * 2 = 0; 0 = 0, 0 + 1 = 1.
  298. // Team 1 * 2 = 2; 2 = 2, 2 + 1 = 3
  299. int tc = _holder.getPlayerTeam(player) * 2;
  300. // Get x and y coordinates
  301. int x = _arenaCoordinates[_arena][tc];
  302. int y = _arenaCoordinates[_arena][tc + 1];
  303. player.teleToLocation(x, y, _zCoord);
  304. // Set the player team
  305. if(isRed)
  306. {
  307. _redTeamPoints.put(player,0);
  308. player.setTeam(2);
  309. }
  310. else
  311. {
  312. _blueTeamPoints.put(player,0);
  313. player.setTeam(1);
  314. }
  315. player.stopAllEffects();
  316. if(player.getPet() != null)
  317. player.getPet().unSummon(player);
  318. // Give the player start up effects
  319. // Freeze
  320. _freeze.getEffects(player, player);
  321. // Tranformation
  322. if(_holder.getPlayerTeam(player) == 0)
  323. _transformationRed.getEffects(player, player);
  324. else
  325. _transformationBlue.getEffects(player, player);
  326. // Set the current player arena
  327. player.setBlockCheckerArena((byte) _arena);
  328. player.setInsideZone(L2Character.ZONE_PVP, true);
  329. // Send needed packets
  330. player.sendPacket(initialPoints);
  331. player.sendPacket(_closeUserInterface);
  332. // ExBasicActionList
  333. final ExBasicActionList actionList = ExBasicActionList.getStaticPacket(player);
  334. player.sendPacket(actionList);
  335. broadcastRelationChanged(player);
  336. }
  337. }
  338. @Override
  339. public void run()
  340. {
  341. // Wrong arena passed, stop event
  342. if(_arena == -1)
  343. {
  344. _log.severe("Couldnt set up the arena Id for the Block Checker event, cancelling event...");
  345. return;
  346. }
  347. _isStarted = true;
  348. // Spawn the blocks
  349. ThreadPoolManager.getInstance().executeTask(new SpawnRound(16, 1));
  350. // Start up player parameters
  351. setUpPlayers();
  352. // Set the started time
  353. _startedTime = System.currentTimeMillis() + 300000;
  354. }
  355. }
  356. /**
  357. * This class spawns the second round of boxes
  358. * and schedules the event end
  359. */
  360. private class SpawnRound implements Runnable
  361. {
  362. int _numOfBoxes;
  363. int _round;
  364. SpawnRound(int numberOfBoxes, int round)
  365. {
  366. _numOfBoxes = numberOfBoxes;
  367. _round = round;
  368. }
  369. @Override
  370. public void run()
  371. {
  372. if(!_isStarted) return;
  373. switch(_round)
  374. {
  375. case 1:
  376. // Schedule second spawn round
  377. _task = ThreadPoolManager.getInstance().scheduleGeneral(new SpawnRound(20, 2), 60000);
  378. break;
  379. case 2:
  380. // Schedule third spawn round
  381. _task = ThreadPoolManager.getInstance().scheduleGeneral(new SpawnRound(14, 3), 60000);
  382. break;
  383. case 3:
  384. // Schedule Event End Count Down
  385. _task = ThreadPoolManager.getInstance().scheduleGeneral(new EndEvent(), 180000);
  386. break;
  387. }
  388. // random % 2, if == 0 will spawn a red block
  389. // if != 0, will spawn a blue block
  390. byte random = 2;
  391. // common template
  392. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(18672);
  393. // Spawn blocks
  394. try
  395. {
  396. // Creates 50 new blocks
  397. for(int i = 0; i < _numOfBoxes; i++)
  398. {
  399. L2Spawn spawn = new L2Spawn(template);
  400. spawn.setLocx(_arenaCoordinates[_arena][4] + Rnd.get(-400,400));
  401. spawn.setLocy(_arenaCoordinates[_arena][5] + Rnd.get(-400,400));
  402. spawn.setLocz(_zCoord);
  403. spawn.setAmount(1);
  404. spawn.setHeading(1);
  405. spawn.setRespawnDelay(1);
  406. SpawnTable.getInstance().addNewSpawn(spawn, false);
  407. spawn.init();
  408. L2BlockInstance block = (L2BlockInstance)spawn.getLastSpawn();
  409. // switch color
  410. if(random % 2 == 0) block.setRed(true);
  411. else block.setRed(false);
  412. block.disableCoreAI(true);
  413. _spawns.add(spawn);
  414. random++;
  415. }
  416. }
  417. catch(Exception e)
  418. {
  419. e.printStackTrace();
  420. }
  421. // Spawn the block carrying girl
  422. if(_round == 1 || _round == 2)
  423. {
  424. L2NpcTemplate girl = NpcTable.getInstance().getTemplate(18676);
  425. try
  426. {
  427. final L2Spawn girlSpawn = new L2Spawn(girl);
  428. girlSpawn.setLocx(_arenaCoordinates[_arena][4] + Rnd.get(-400,400));
  429. girlSpawn.setLocy(_arenaCoordinates[_arena][5] + Rnd.get(-400,400));
  430. girlSpawn.setLocz(_zCoord);
  431. girlSpawn.setAmount(1);
  432. girlSpawn.setHeading(1);
  433. girlSpawn.setRespawnDelay(1);
  434. SpawnTable.getInstance().addNewSpawn(girlSpawn, false);
  435. girlSpawn.init();
  436. // Schedule his deletion after 9 secs of spawn
  437. ThreadPoolManager.getInstance().scheduleGeneral(new CarryingGirlUnspawn(girlSpawn), 9000);
  438. }
  439. catch(Exception e)
  440. {
  441. _log.warning("Couldnt Spawn Block Checker NPCs! Wrong instance type at npc table?");
  442. if(Config.DEBUG)
  443. e.printStackTrace();
  444. }
  445. }
  446. _redPoints += _numOfBoxes / 2;
  447. _bluePoints += _numOfBoxes / 2;
  448. int timeLeft = (int)((getStarterTime() - System.currentTimeMillis()) / 1000);
  449. ExCubeGameChangePoints changePoints = new ExCubeGameChangePoints(timeLeft, getBluePoints(), getRedPoints());
  450. getHolder().broadCastPacketToTeam(changePoints);
  451. }
  452. }
  453. private class CarryingGirlUnspawn implements Runnable
  454. {
  455. private L2Spawn _spawn;
  456. private CarryingGirlUnspawn(L2Spawn spawn)
  457. {
  458. _spawn = spawn;
  459. }
  460. @Override
  461. public void run()
  462. {
  463. if(_spawn == null)
  464. {
  465. _log.warning("HBCE: Block Carrying Girl is null");
  466. return;
  467. }
  468. SpawnTable.getInstance().deleteSpawn(_spawn, false);
  469. _spawn.stopRespawn();
  470. _spawn.getLastSpawn().deleteMe();
  471. }
  472. }
  473. /*
  474. private class CountDown implements Runnable
  475. {
  476. @Override
  477. public void run()
  478. {
  479. _holder.broadCastPacketToTeam(SystemMessage.getSystemMessage(SystemMessageId.BLOCK_CHECKER_ENDS_5));
  480. ThreadPoolManager.getInstance().scheduleGeneral(new EndEvent(), 5000);
  481. }
  482. }
  483. */
  484. /**
  485. * This class erase all event parameters on player
  486. * and port them back near Handy. Also, unspawn
  487. * blocks, runs a garbage collector and set as free
  488. * the used arena
  489. */
  490. private class EndEvent implements Runnable
  491. {
  492. // Garbage collector and arena free setter
  493. private void clearMe()
  494. {
  495. HandysBlockCheckerManager.getInstance().clearPaticipantQueueByArenaId(_arena);
  496. _holder.clearPlayers();
  497. _blueTeamPoints.clear();
  498. _redTeamPoints.clear();
  499. HandysBlockCheckerManager.getInstance().setArenaFree(_arena);
  500. for(L2Spawn spawn : _spawns)
  501. {
  502. spawn.stopRespawn();
  503. spawn.getLastSpawn().deleteMe();
  504. SpawnTable.getInstance().deleteSpawn(spawn, false);
  505. spawn = null;
  506. }
  507. _spawns.clear();
  508. for(L2ItemInstance item : _drops)
  509. {
  510. // npe
  511. if(item == null)
  512. continue;
  513. // a player has it, it will be deleted later
  514. if(!item.isVisible() || item.getOwnerId() != 0)
  515. continue;
  516. item.decayMe();
  517. L2World.getInstance().removeObject(item);
  518. }
  519. _drops.clear();
  520. }
  521. /**
  522. * Reward players after event.
  523. * Tie - No Reward
  524. */
  525. private void rewardPlayers()
  526. {
  527. if(_redPoints == _bluePoints)
  528. return;
  529. _isRedWinner = _redPoints > _bluePoints ? true : false;
  530. if(_isRedWinner)
  531. {
  532. rewardAsWinner(true);
  533. rewardAsLooser(false);
  534. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.TEAM_C1_WON);
  535. msg.addString("Red Team");
  536. _holder.broadCastPacketToTeam(msg);
  537. }
  538. else if(_bluePoints > _redPoints)
  539. {
  540. rewardAsWinner(false);
  541. rewardAsLooser(true);
  542. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.TEAM_C1_WON);
  543. msg.addString("Blue Team");
  544. _holder.broadCastPacketToTeam(msg);
  545. }
  546. else
  547. {
  548. rewardAsLooser(true);
  549. rewardAsLooser(false);
  550. }
  551. }
  552. /**
  553. * Reward the speicifed team as a winner team
  554. * 1) Higher score - 8 extra
  555. * 2) Higher score - 5 extra
  556. * @param isRed
  557. */
  558. private void rewardAsWinner(boolean isRed)
  559. {
  560. FastMap<L2PcInstance, Integer> tempPoints = isRed? _redTeamPoints : _blueTeamPoints;
  561. // Main give
  562. for(Entry<L2PcInstance, Integer> points : tempPoints.entrySet())
  563. {
  564. if(points.getKey() == null)
  565. continue;
  566. if(points.getValue() >= 10)
  567. points.getKey().addItem("Block Checker", 13067, 2, points.getKey(), true);
  568. else
  569. tempPoints.remove(points.getKey());
  570. }
  571. int first = 0, second = 0;
  572. L2PcInstance winner1 = null, winner2 = null;
  573. for(Entry<L2PcInstance, Integer> entry : tempPoints.entrySet())
  574. {
  575. L2PcInstance pc = entry.getKey();
  576. int pcPoints = entry.getValue();
  577. if(pcPoints > first)
  578. {
  579. // Move old data
  580. second = first;
  581. winner2 = winner1;
  582. // Set new data
  583. first = pcPoints;
  584. winner1 = pc;
  585. }
  586. else if(pcPoints > second)
  587. {
  588. second = pcPoints;
  589. winner2 = pc;
  590. }
  591. }
  592. if(winner1 != null)
  593. winner1.addItem("Block Checker", 13067, 8, winner1, true);
  594. if(winner2 != null)
  595. winner2.addItem("Block Checker", 13067, 5, winner2, true);
  596. }
  597. /**
  598. * Will reward the looser team with the
  599. * predefined rewards
  600. * Player got >= 10 points: 2 coins
  601. * Player got < 10 points: 0 coins
  602. * @param isRed
  603. */
  604. private void rewardAsLooser(boolean isRed)
  605. {
  606. FastMap<L2PcInstance, Integer> tempPoints = isRed? _redTeamPoints : _blueTeamPoints;
  607. for(Entry<L2PcInstance, Integer> entry : tempPoints.entrySet())
  608. {
  609. L2PcInstance player = entry.getKey();
  610. if(player != null && entry.getValue() >= 10)
  611. player.addItem("Block Checker", 13067, 2, player, true);
  612. }
  613. }
  614. /**
  615. * Telport players back, give status back and
  616. * send final packet
  617. */
  618. private void setPlayersBack()
  619. {
  620. final ExCubeGameEnd end = new ExCubeGameEnd(_isRedWinner);
  621. for(L2PcInstance player : _holder.getAllPlayers())
  622. {
  623. if(player == null) continue;
  624. player.stopAllEffects();
  625. // Remove team aura
  626. player.setTeam(0);
  627. // Set default arena
  628. player.setBlockCheckerArena(DEFAULT_ARENA);
  629. // Remove the event items
  630. PcInventory inv = player.getInventory();
  631. if(inv.getItemByItemId(13787) != null)
  632. {
  633. long count = inv.getInventoryItemCount(13787, 0);
  634. inv.destroyItemByItemId("Handys Block Checker", 13787, count, player, player);
  635. }
  636. if(inv.getItemByItemId(13788) != null)
  637. {
  638. long count = inv.getInventoryItemCount(13788, 0);
  639. inv.destroyItemByItemId("Handys Block Checker", 13788, count, player, player);
  640. }
  641. broadcastRelationChanged(player);
  642. // Teleport Back
  643. player.teleToLocation(-57478, -60367, -2370);
  644. player.setInsideZone(L2Character.ZONE_PVP, false);
  645. // Send end packet
  646. player.sendPacket(end);
  647. player.broadcastUserInfo();
  648. }
  649. }
  650. @Override
  651. public void run()
  652. {
  653. if(!_abnormalEnd)
  654. rewardPlayers();
  655. setPlayersBack();
  656. clearMe();
  657. _isStarted = false;
  658. _abnormalEnd = false;
  659. }
  660. }
  661. }