BlockCheckerEngine.java 21 KB

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