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.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.getEffects(player, player);
  364. // Transformation
  365. if (_holder.getPlayerTeam(player) == 0)
  366. {
  367. _transformationRed.getEffects(player, player);
  368. }
  369. else
  370. {
  371. _transformationBlue.getEffects(player, player);
  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. final ExBasicActionList actionList = ExBasicActionList.getStaticPacket(player);
  381. player.sendPacket(actionList);
  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(0);
  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. }