BlockCheckerEngine.java 21 KB

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