BlockCheckerEngine.java 20 KB

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