BlockCheckerEngine.java 21 KB

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