BlockCheckerEngine.java 20 KB

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