OlympiadGame.java 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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.olympiad;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.SQLException;
  19. import java.util.logging.Level;
  20. import java.util.logging.LogRecord;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.L2DatabaseFactory;
  24. import com.l2jserver.gameserver.datatables.HeroSkillTable;
  25. import com.l2jserver.gameserver.datatables.NpcTable;
  26. import com.l2jserver.gameserver.datatables.SpawnTable;
  27. import com.l2jserver.gameserver.instancemanager.CastleManager;
  28. import com.l2jserver.gameserver.instancemanager.FortManager;
  29. import com.l2jserver.gameserver.model.L2ItemInstance;
  30. import com.l2jserver.gameserver.model.L2Party;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.L2Spawn;
  33. import com.l2jserver.gameserver.model.L2World;
  34. import com.l2jserver.gameserver.model.actor.L2Summon;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  37. import com.l2jserver.gameserver.model.olympiad.Olympiad.COMP_TYPE;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.network.clientpackets.Say2;
  40. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  41. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMatchEnd;
  42. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMode;
  43. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadUserInfo;
  44. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  45. import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
  46. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  47. import com.l2jserver.gameserver.templates.StatsSet;
  48. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  49. import com.l2jserver.util.L2FastList;
  50. /**
  51. *
  52. * @author GodKratos
  53. */
  54. class OlympiadGame
  55. {
  56. protected static final Logger _log = Logger.getLogger(OlympiadGame.class.getName());
  57. protected static final Logger _logResults = Logger.getLogger("olympiad");
  58. protected final COMP_TYPE _type;
  59. protected boolean _aborted;
  60. protected boolean _gamestarted;
  61. protected boolean _playerOneDisconnected;
  62. protected boolean _playerTwoDisconnected;
  63. protected boolean _playerOneDefaulted;
  64. protected boolean _playerTwoDefaulted;
  65. protected String _playerOneName;
  66. protected String _playerTwoName;
  67. protected int _playerOneID = 0;
  68. protected int _playerTwoID = 0;
  69. protected int _playerOneClass = 0;
  70. protected int _playerTwoClass = 0;
  71. protected static final int OLY_BUFFER = 36402;
  72. protected static final int OLY_MANAGER = 31688;
  73. private static final String POINTS = "olympiad_points";
  74. private static final String COMP_DONE = "competitions_done";
  75. private static final String COMP_WON = "competitions_won";
  76. private static final String COMP_LOST = "competitions_lost";
  77. private static final String COMP_DRAWN = "competitions_drawn";
  78. protected static boolean _battleStarted;
  79. protected static boolean _gameIsStarted;
  80. protected long _startTime = 0;
  81. public int _damageP1 = 0;
  82. public int _damageP2 = 0;
  83. public L2PcInstance _playerOne;
  84. public L2PcInstance _playerTwo;
  85. public L2Spawn _spawnOne;
  86. public L2Spawn _spawnTwo;
  87. protected L2FastList<L2PcInstance> _players;
  88. private final int[] _stadiumPort;
  89. private int x1, y1, z1, x2, y2, z2;
  90. public final int _stadiumID;
  91. protected SystemMessage _sm;
  92. private SystemMessage _sm2;
  93. private SystemMessage _sm3;
  94. protected OlympiadGame(int id, COMP_TYPE type, L2FastList<L2PcInstance> list)
  95. {
  96. _aborted = false;
  97. _gamestarted = false;
  98. _stadiumID = id;
  99. _playerOneDisconnected = false;
  100. _playerTwoDisconnected = false;
  101. _type = type;
  102. _stadiumPort = OlympiadManager.STADIUMS[id].getCoordinates();
  103. if (list != null)
  104. {
  105. _players = list;
  106. _playerOne = list.get(0);
  107. _playerTwo = list.get(1);
  108. try
  109. {
  110. _playerOneName = _playerOne.getName();
  111. _playerTwoName = _playerTwo.getName();
  112. _playerOne.setOlympiadGameId(id);
  113. _playerTwo.setOlympiadGameId(id);
  114. _playerOneID = _playerOne.getObjectId();
  115. _playerTwoID = _playerTwo.getObjectId();
  116. _playerOneClass = _playerOne.getBaseClass();
  117. _playerTwoClass = _playerTwo.getBaseClass();
  118. }
  119. catch (Exception e)
  120. {
  121. _aborted = true;
  122. clearPlayers();
  123. }
  124. if (Config.DEBUG)
  125. _log.info("Olympiad System: Game - " + id + ": "
  126. + _playerOne.getName() + " Vs " + _playerTwo.getName());
  127. }
  128. else
  129. {
  130. _aborted = true;
  131. clearPlayers();
  132. return;
  133. }
  134. }
  135. public boolean isAborted()
  136. {
  137. return _aborted;
  138. }
  139. protected void clearPlayers()
  140. {
  141. _playerOne = null;
  142. _playerTwo = null;
  143. _players = null;
  144. _playerOneName = "";
  145. _playerTwoName = "";
  146. _playerOneID = 0;
  147. _playerTwoID = 0;
  148. }
  149. protected void handleDisconnect(L2PcInstance player)
  150. {
  151. if (_gamestarted)
  152. {
  153. if (player == _playerOne)
  154. _playerOneDisconnected = true;
  155. else if (player == _playerTwo)
  156. _playerTwoDisconnected = true;
  157. }
  158. }
  159. public L2Spawn SpawnBuffer(int xPos, int yPos, int zPos, int npcId)
  160. {
  161. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
  162. try
  163. {
  164. final L2Spawn spawn = new L2Spawn(template);
  165. spawn.setLocx(xPos);
  166. spawn.setLocy(yPos);
  167. spawn.setLocz(zPos);
  168. spawn.setAmount(1);
  169. spawn.setHeading(0);
  170. spawn.setRespawnDelay(1);
  171. SpawnTable.getInstance().addNewSpawn(spawn, false);
  172. spawn.init();
  173. return spawn;
  174. }
  175. catch (Exception e)
  176. {
  177. return null;
  178. }
  179. }
  180. protected void removals()
  181. {
  182. if (_aborted)
  183. return;
  184. if (_playerOne == null || _playerTwo == null)
  185. return;
  186. if (_playerOneDisconnected || _playerTwoDisconnected)
  187. return;
  188. for (L2PcInstance player : _players)
  189. {
  190. try
  191. {
  192. // Remove Buffs
  193. player.stopAllEffectsExceptThoseThatLastThroughDeath();
  194. // Remove Clan Skills
  195. if (player.getClan() != null)
  196. {
  197. for (L2Skill skill : player.getClan().getAllSkills())
  198. player.removeSkill(skill, false);
  199. if (player.getClan().getHasCastle() > 0)
  200. CastleManager.getInstance().getCastleByOwner(player.getClan()).removeResidentialSkills(player);
  201. if (player.getClan().getHasFort() > 0)
  202. FortManager.getInstance().getFortByOwner(player.getClan()).removeResidentialSkills(player);
  203. }
  204. // Abort casting if player casting
  205. if (player.isCastingNow())
  206. {
  207. player.abortCast();
  208. }
  209. // Force the character to be visible
  210. player.getAppearance().setVisible();
  211. // Remove Hero Skills
  212. if (player.isHero())
  213. {
  214. for (L2Skill skill : HeroSkillTable.getHeroSkills())
  215. player.removeSkill(skill, false);
  216. }
  217. // Heal Player fully
  218. player.setCurrentCp(player.getMaxCp());
  219. player.setCurrentHp(player.getMaxHp());
  220. player.setCurrentMp(player.getMaxMp());
  221. // Remove Summon's Buffs
  222. if (player.getPet() != null)
  223. {
  224. L2Summon summon = player.getPet();
  225. summon.stopAllEffects();
  226. if (summon instanceof L2PetInstance)
  227. summon.unSummon(player);
  228. }
  229. // stop any cubic that has been given by other player.
  230. player.stopCubicsByOthers();
  231. // Remove player from his party
  232. if (player.getParty() != null)
  233. {
  234. L2Party party = player.getParty();
  235. party.removePartyMember(player);
  236. }
  237. // Remove Agathion
  238. if (player.getAgathionId() > 0)
  239. {
  240. player.setAgathionId(0);
  241. player.broadcastUserInfo();
  242. }
  243. player.checkItemRestriction();
  244. // Remove shot automation
  245. player.disableAutoShotsAll();
  246. // Discharge any active shots
  247. if (player.getActiveWeaponInstance() != null)
  248. {
  249. player.getActiveWeaponInstance().setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  250. player.getActiveWeaponInstance().setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  251. }
  252. // enable skills with cool time <= 15 minutes
  253. for (L2Skill skill : player.getAllSkills())
  254. if (skill.getReuseDelay() <= 900000)
  255. player.enableSkill(skill);
  256. player.sendSkillList();
  257. player.sendPacket(new SkillCoolTime(player));
  258. }
  259. catch (Exception e)
  260. {
  261. }
  262. }
  263. }
  264. protected boolean portPlayersToArena()
  265. {
  266. final boolean _playerOneCrash = (_playerOne == null || _playerOneDisconnected);
  267. final boolean _playerTwoCrash = (_playerTwo == null || _playerTwoDisconnected);
  268. if (_playerOneCrash || _playerTwoCrash || _aborted)
  269. {
  270. _playerOne = null;
  271. _playerTwo = null;
  272. _aborted = true;
  273. return false;
  274. }
  275. try
  276. {
  277. x1 = _playerOne.getX();
  278. y1 = _playerOne.getY();
  279. z1 = _playerOne.getZ();
  280. x2 = _playerTwo.getX();
  281. y2 = _playerTwo.getY();
  282. z2 = _playerTwo.getZ();
  283. if (_playerOne.isSitting())
  284. _playerOne.standUp();
  285. if (_playerTwo.isSitting())
  286. _playerTwo.standUp();
  287. _playerOne.setTarget(null);
  288. _playerTwo.setTarget(null);
  289. _gamestarted = true;
  290. _playerOne.setIsInOlympiadMode(true);
  291. _playerOne.setIsOlympiadStart(false);
  292. _playerOne.setOlympiadSide(1);
  293. _playerOne.olyBuff = 5;
  294. _playerTwo.setIsInOlympiadMode(true);
  295. _playerTwo.setIsOlympiadStart(false);
  296. _playerTwo.setOlympiadSide(2);
  297. _playerTwo.olyBuff = 5;
  298. _playerOne.setInstanceId(0);
  299. _playerOne.teleToLocation(_stadiumPort[0] + 1200, _stadiumPort[1], _stadiumPort[2], false);
  300. _playerTwo.setInstanceId(0);
  301. _playerTwo.teleToLocation(_stadiumPort[0] - 1200, _stadiumPort[1], _stadiumPort[2], false);
  302. _playerOne.sendPacket(new ExOlympiadMode(2));
  303. _playerTwo.sendPacket(new ExOlympiadMode(2));
  304. _spawnOne = SpawnBuffer(_stadiumPort[0] + 1100, _stadiumPort[1], _stadiumPort[2], OLY_BUFFER);
  305. _spawnTwo = SpawnBuffer(_stadiumPort[0] - 1100, _stadiumPort[1], _stadiumPort[2], OLY_BUFFER);
  306. _gameIsStarted = false;
  307. }
  308. catch (NullPointerException e)
  309. {
  310. return false;
  311. }
  312. return true;
  313. }
  314. protected void cleanEffects()
  315. {
  316. if (_playerOne == null || _playerTwo == null)
  317. return;
  318. if (_playerOneDisconnected || _playerTwoDisconnected)
  319. return;
  320. for (L2PcInstance player : _players)
  321. {
  322. try
  323. {
  324. player.stopAllEffectsExceptThoseThatLastThroughDeath();
  325. player.clearSouls();
  326. player.clearCharges();
  327. if(player.getAgathionId() > 0)
  328. player.setAgathionId(0);
  329. if (player.getPet() != null)
  330. {
  331. L2Summon summon = player.getPet();
  332. summon.stopAllEffects();
  333. }
  334. }
  335. catch (Exception e)
  336. {
  337. }
  338. }
  339. }
  340. protected void portPlayersBack()
  341. {
  342. if (_playerOne != null)
  343. {
  344. _playerOne.sendPacket(new ExOlympiadMatchEnd());
  345. _playerOne.teleToLocation(x1, y1, z1, true);
  346. }
  347. if (_playerTwo != null)
  348. {
  349. _playerTwo.sendPacket(new ExOlympiadMatchEnd());
  350. _playerTwo.teleToLocation(x2, y2, z2, true);
  351. }
  352. }
  353. protected void PlayersStatusBack()
  354. {
  355. for (L2PcInstance player : _players)
  356. {
  357. try
  358. {
  359. if (Olympiad.getInstance().playerInStadia(player))
  360. {
  361. if (player.isDead())
  362. player.setIsDead(false);
  363. player.getStatus().startHpMpRegeneration();
  364. player.setCurrentCp(player.getMaxCp());
  365. player.setCurrentHp(player.getMaxHp());
  366. player.setCurrentMp(player.getMaxMp());
  367. }
  368. if(player.isTransformed())
  369. player.untransform();
  370. player.setIsInOlympiadMode(false);
  371. player.setIsOlympiadStart(false);
  372. player.setOlympiadSide(-1);
  373. player.setOlympiadGameId(-1);
  374. player.sendPacket(new ExOlympiadMode(0));
  375. // Add Clan Skills
  376. if (player.getClan() != null)
  377. {
  378. for (L2Skill skill : player.getClan().getAllSkills())
  379. {
  380. if (skill.getMinPledgeClass() <= player.getPledgeClass())
  381. player.addSkill(skill, false);
  382. }
  383. if (player.getClan().getHasCastle() > 0)
  384. CastleManager.getInstance().getCastleByOwner(player.getClan()).giveResidentialSkills(player);
  385. if (player.getClan().getHasFort() > 0)
  386. FortManager.getInstance().getFortByOwner(player.getClan()).giveResidentialSkills(player);
  387. }
  388. // Add Hero Skills
  389. if (player.isHero())
  390. {
  391. for (L2Skill skill : HeroSkillTable.getHeroSkills())
  392. player.addSkill(skill, false);
  393. }
  394. player.sendSkillList();
  395. }
  396. catch (Exception e)
  397. {
  398. }
  399. }
  400. }
  401. protected boolean haveWinner()
  402. {
  403. if (_aborted || _playerOne == null || _playerTwo == null ||
  404. _playerOneDisconnected || _playerTwoDisconnected)
  405. {
  406. return true;
  407. }
  408. double playerOneHp = 0;
  409. try
  410. {
  411. if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  412. {
  413. playerOneHp = _playerOne.getCurrentHp();
  414. }
  415. }
  416. catch (Exception e)
  417. {
  418. playerOneHp = 0;
  419. }
  420. double playerTwoHp = 0;
  421. try
  422. {
  423. if (_playerTwo != null && _playerTwo.getOlympiadGameId() != -1)
  424. {
  425. playerTwoHp = _playerTwo.getCurrentHp();
  426. }
  427. }
  428. catch (Exception e)
  429. {
  430. playerTwoHp = 0;
  431. }
  432. if (playerTwoHp <= 0 || playerOneHp <= 0)
  433. {
  434. return true;
  435. }
  436. return false;
  437. }
  438. protected void validateWinner()
  439. {
  440. if (_aborted)
  441. return;
  442. final boolean _pOneCrash = (_playerOne == null || _playerOneDisconnected);
  443. final boolean _pTwoCrash = (_playerTwo == null || _playerTwoDisconnected);
  444. final int _div;
  445. final int _gpreward;
  446. final String classed;
  447. switch (_type)
  448. {
  449. case NON_CLASSED:
  450. _div = 5;
  451. _gpreward = Config.ALT_OLY_NONCLASSED_RITEM_C;
  452. classed = "no";
  453. break;
  454. default:
  455. _div = 3;
  456. _gpreward = Config.ALT_OLY_CLASSED_RITEM_C;
  457. classed = "yes";
  458. break;
  459. }
  460. final StatsSet playerOneStat = Olympiad.getNobleStats(_playerOneID);
  461. final StatsSet playerTwoStat = Olympiad.getNobleStats(_playerTwoID);
  462. final int playerOnePlayed = playerOneStat.getInteger(COMP_DONE);
  463. final int playerTwoPlayed = playerTwoStat.getInteger(COMP_DONE);
  464. final int playerOneWon = playerOneStat.getInteger(COMP_WON);
  465. final int playerTwoWon = playerTwoStat.getInteger(COMP_WON);
  466. final int playerOneLost = playerOneStat.getInteger(COMP_LOST);
  467. final int playerTwoLost = playerTwoStat.getInteger(COMP_LOST);
  468. final int playerOneDrawn = playerOneStat.getInteger(COMP_DRAWN);
  469. final int playerTwoDrawn = playerTwoStat.getInteger(COMP_DRAWN);
  470. final int playerOnePoints = playerOneStat.getInteger(POINTS);
  471. final int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  472. final int pointDiff = Math.min(Math.min(playerOnePoints, playerTwoPoints) / _div, Config.ALT_OLY_MAX_POINTS);
  473. // Check for if a player defaulted before battle started
  474. if (_playerOneDefaulted || _playerTwoDefaulted)
  475. {
  476. if (_playerOneDefaulted)
  477. {
  478. final int lostPoints = Math.min(playerOnePoints / 3, Config.ALT_OLY_MAX_POINTS);
  479. playerOneStat.set(POINTS, playerOnePoints - lostPoints);
  480. Olympiad.updateNobleStats(_playerOneID, playerOneStat);
  481. SystemMessage sm = new SystemMessage(SystemMessageId.C1_HAS_LOST_S2_OLYMPIAD_POINTS);
  482. sm.addString(_playerOneName);
  483. sm.addNumber(lostPoints);
  484. broadcastMessage(sm, false);
  485. if (Config.DEBUG)
  486. _log.info("Olympia Result: " + _playerOneName + " lost " + lostPoints + " points for defaulting");
  487. if (Config.ALT_OLY_LOG_FIGHTS)
  488. {
  489. LogRecord record = new LogRecord(Level.INFO, _playerOneName+" default");
  490. record.setParameters(new Object[]{_playerOneName, _playerTwoName, 0, 0, 0, 0, lostPoints, classed});
  491. _logResults.log(record);
  492. }
  493. }
  494. if (_playerTwoDefaulted)
  495. {
  496. final int lostPoints = Math.min(playerTwoPoints / 3, Config.ALT_OLY_MAX_POINTS);
  497. playerTwoStat.set(POINTS, playerTwoPoints - lostPoints);
  498. Olympiad.updateNobleStats(_playerTwoID, playerTwoStat);
  499. SystemMessage sm = new SystemMessage(SystemMessageId.C1_HAS_LOST_S2_OLYMPIAD_POINTS);
  500. sm.addString(_playerTwoName);
  501. sm.addNumber(lostPoints);
  502. broadcastMessage(sm, false);
  503. if (Config.DEBUG)
  504. _log.info("Olympia Result: " + _playerTwoName + " lost " + lostPoints + " points for defaulting");
  505. if (Config.ALT_OLY_LOG_FIGHTS)
  506. {
  507. LogRecord record = new LogRecord(Level.INFO, _playerTwoName+" default");
  508. record.setParameters(new Object[]{_playerOneName, _playerTwoName, 0, 0, 0, 0, lostPoints, classed});
  509. _logResults.log(record);
  510. }
  511. }
  512. return;
  513. }
  514. // Create results for players if a player crashed
  515. if (_pOneCrash || _pTwoCrash)
  516. {
  517. if (_pOneCrash && !_pTwoCrash)
  518. {
  519. try
  520. {
  521. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  522. playerOneStat.set(COMP_LOST, playerOneLost + 1);
  523. if (Config.DEBUG)
  524. _log.info("Olympia Result: " + _playerOneName + " vs " + _playerTwoName + " ... "
  525. + _playerOneName + " lost " + pointDiff + " points for crash");
  526. if (Config.ALT_OLY_LOG_FIGHTS)
  527. {
  528. LogRecord record = new LogRecord(Level.INFO, _playerOneName+" crash");
  529. record.setParameters(new Object[]{_playerOneName, _playerTwoName, 0, 0, 0, 0, pointDiff, classed});
  530. _logResults.log(record);
  531. }
  532. playerTwoStat.set(POINTS, playerTwoPoints + pointDiff);
  533. playerTwoStat.set(COMP_WON, playerTwoWon + 1);
  534. if (Config.DEBUG)
  535. _log.info("Olympia Result: " + _playerOneName + " vs " + _playerTwoName + " ... "
  536. + _playerTwoName + " Win " + pointDiff + " points");
  537. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  538. _sm2 = new SystemMessage(SystemMessageId.C1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  539. _sm.addString(_playerTwoName);
  540. broadcastMessage(_sm, true);
  541. _sm2.addString(_playerTwoName);
  542. _sm2.addNumber(pointDiff);
  543. broadcastMessage(_sm2, false);
  544. }
  545. catch (Exception e)
  546. {
  547. _log.log(Level.WARNING, "Exception on validateWinnder(): " + e.getMessage(), e);
  548. }
  549. }
  550. else if (_pTwoCrash && !_pOneCrash)
  551. {
  552. try
  553. {
  554. playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  555. playerTwoStat.set(COMP_LOST, playerTwoLost + 1);
  556. if (Config.DEBUG)
  557. _log.info("Olympia Result: " + _playerTwoName + " vs " + _playerOneName + " ... "
  558. + _playerTwoName + " lost " + pointDiff + " points for crash");
  559. if (Config.ALT_OLY_LOG_FIGHTS)
  560. {
  561. LogRecord record = new LogRecord(Level.INFO, _playerTwoName+" crash");
  562. record.setParameters(new Object[]{_playerOneName, _playerTwoName, 0, 0, 0, 0, pointDiff, classed});
  563. _logResults.log(record);
  564. }
  565. playerOneStat.set(POINTS, playerOnePoints + pointDiff);
  566. playerOneStat.set(COMP_WON, playerOneWon + 1);
  567. if (Config.DEBUG)
  568. _log.info("Olympia Result: " + _playerTwoName + " vs " + _playerOneName + " ... "
  569. + _playerOneName + " Win " + pointDiff + " points");
  570. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  571. _sm2 = new SystemMessage(SystemMessageId.C1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  572. _sm.addString(_playerOneName);
  573. broadcastMessage(_sm, true);
  574. _sm2.addString(_playerOneName);
  575. _sm2.addNumber(pointDiff);
  576. broadcastMessage(_sm2, false);
  577. }
  578. catch (Exception e)
  579. {
  580. _log.log(Level.WARNING, "Exception on validateWinnder(): " + e.getMessage(), e);
  581. }
  582. }
  583. else if (_pOneCrash && _pTwoCrash)
  584. {
  585. try
  586. {
  587. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  588. playerOneStat.set(COMP_LOST, playerOneLost + 1);
  589. playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  590. playerTwoStat.set(COMP_LOST, playerTwoLost + 1);
  591. if (Config.DEBUG)
  592. _log.info("Olympia Result: " + _playerOneName + " vs " + _playerTwoName + " ... "
  593. + " both lost " + pointDiff + " points for crash");
  594. if (Config.ALT_OLY_LOG_FIGHTS)
  595. {
  596. LogRecord record = new LogRecord(Level.INFO, "both crash");
  597. record.setParameters(new Object[]{_playerOneName, _playerTwoName, 0, 0, 0, 0, pointDiff, classed});
  598. _logResults.log(record);
  599. }
  600. }
  601. catch (Exception e)
  602. {
  603. _log.log(Level.WARNING, "Exception on validateWinnder(): " + e.getMessage(), e);
  604. }
  605. }
  606. playerOneStat.set(COMP_DONE, playerOnePlayed + 1);
  607. playerTwoStat.set(COMP_DONE, playerTwoPlayed + 1);
  608. Olympiad.updateNobleStats(_playerOneID, playerOneStat);
  609. Olympiad.updateNobleStats(_playerTwoID, playerTwoStat);
  610. return;
  611. }
  612. double playerOneHp = 0;
  613. if (!_playerOne.isDead())
  614. {
  615. playerOneHp = _playerOne.getCurrentHp() + _playerOne.getCurrentCp();
  616. }
  617. double playerTwoHp = 0;
  618. if (!_playerTwo.isDead())
  619. {
  620. playerTwoHp = _playerTwo.getCurrentHp() + _playerTwo.getCurrentCp();
  621. }
  622. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  623. _sm2 = new SystemMessage(SystemMessageId.C1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  624. _sm3 = new SystemMessage(SystemMessageId.C1_HAS_LOST_S2_OLYMPIAD_POINTS);
  625. String result = "";
  626. // if players crashed, search if they've relogged
  627. _playerOne = L2World.getInstance().getPlayer(_playerOneID);
  628. _players.set(0, _playerOne);
  629. _playerTwo = L2World.getInstance().getPlayer(_playerTwoID);
  630. _players.set(1, _playerTwo);
  631. String winner = "draw";
  632. // Calculate Fight time
  633. long _fightTime = (System.currentTimeMillis() - _startTime);
  634. if (_playerOne == null && _playerTwo == null)
  635. {
  636. playerOneStat.set(COMP_DRAWN, playerOneDrawn + 1);
  637. playerTwoStat.set(COMP_DRAWN, playerTwoDrawn + 1);
  638. result = " tie";
  639. _sm = new SystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
  640. broadcastMessage(_sm, true);
  641. }
  642. else if (_playerTwo == null
  643. || _playerTwo.isOnline() == 0
  644. || (playerTwoHp == 0 && playerOneHp != 0)
  645. || (_damageP1 > _damageP2 && playerTwoHp != 0 && playerOneHp != 0))
  646. {
  647. playerOneStat.set(POINTS, playerOnePoints + pointDiff);
  648. playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  649. playerOneStat.set(COMP_WON, playerOneWon + 1);
  650. playerTwoStat.set(COMP_LOST, playerTwoLost + 1);
  651. _sm.addString(_playerOneName);
  652. broadcastMessage(_sm, true);
  653. _sm2.addString(_playerOneName);
  654. _sm2.addNumber(pointDiff);
  655. broadcastMessage(_sm2, false);
  656. _sm3.addString(_playerTwoName);
  657. _sm3.addNumber(pointDiff);
  658. broadcastMessage(_sm3, false);
  659. winner = _playerOneName + " won";
  660. try
  661. {
  662. // Save Fight Result
  663. saveResults(_playerOneID,_playerTwoID,_playerOneClass,_playerTwoClass,1,_startTime,_fightTime, (_type == COMP_TYPE.CLASSED ? 1 : 0));
  664. result = " (" + playerOneHp + "hp vs " + playerTwoHp + "hp - "
  665. + _damageP1 + "dmg vs " + _damageP2 + "dmg) "
  666. + _playerOneName + " win " + pointDiff + " points";
  667. L2ItemInstance item = _playerOne.getInventory().addItem("Olympiad", Config.ALT_OLY_BATTLE_REWARD_ITEM, _gpreward, _playerOne, null);
  668. InventoryUpdate iu = new InventoryUpdate();
  669. iu.addModifiedItem(item);
  670. _playerOne.sendPacket(iu);
  671. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  672. sm.addItemName(item);
  673. sm.addNumber(_gpreward);
  674. _playerOne.sendPacket(sm);
  675. }
  676. catch (Exception e)
  677. {
  678. }
  679. }
  680. else if (_playerOne == null
  681. || _playerOne.isOnline() == 0
  682. || (playerOneHp == 0 && playerTwoHp != 0)
  683. || (_damageP2 > _damageP1 && playerOneHp != 0 && playerTwoHp != 0))
  684. {
  685. playerTwoStat.set(POINTS, playerTwoPoints + pointDiff);
  686. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  687. playerTwoStat.set(COMP_WON, playerTwoWon + 1);
  688. playerOneStat.set(COMP_LOST, playerOneLost + 1);
  689. _sm.addString(_playerTwoName);
  690. broadcastMessage(_sm, true);
  691. _sm2.addString(_playerTwoName);
  692. _sm2.addNumber(pointDiff);
  693. broadcastMessage(_sm2, false);
  694. _sm3.addString(_playerOneName);
  695. _sm3.addNumber(pointDiff);
  696. broadcastMessage(_sm3, false);
  697. winner = _playerTwoName + " won";
  698. try
  699. {
  700. // Save Fight Result
  701. saveResults(_playerOneID,_playerTwoID,_playerOneClass,_playerTwoClass,2,_startTime,_fightTime,(_type == COMP_TYPE.CLASSED ? 1 : 0));
  702. result = " (" + playerOneHp + "hp vs " + playerTwoHp + "hp - "
  703. + _damageP1 + "dmg vs " + _damageP2 + "dmg) "
  704. + _playerTwoName + " win " + pointDiff + " points";
  705. L2ItemInstance item = _playerTwo.getInventory().addItem("Olympiad", Config.ALT_OLY_BATTLE_REWARD_ITEM, _gpreward, _playerTwo, null);
  706. InventoryUpdate iu = new InventoryUpdate();
  707. iu.addModifiedItem(item);
  708. _playerTwo.sendPacket(iu);
  709. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  710. sm.addItemName(item);
  711. sm.addNumber(_gpreward);
  712. _playerTwo.sendPacket(sm);
  713. }
  714. catch (Exception e)
  715. {
  716. }
  717. }
  718. else
  719. {
  720. // Save Fight Result
  721. saveResults(_playerOneID,_playerTwoID,_playerOneClass,_playerTwoClass,0,_startTime,_fightTime,(_type == COMP_TYPE.CLASSED ? 1 : 0));
  722. result = " tie";
  723. _sm = new SystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
  724. broadcastMessage(_sm, true);
  725. final int pointOneDiff = Math.min(playerOnePoints / 5, Config.ALT_OLY_MAX_POINTS);
  726. final int pointTwoDiff = Math.min(playerTwoPoints / 5, Config.ALT_OLY_MAX_POINTS);
  727. playerOneStat.set(POINTS, playerOnePoints - pointOneDiff);
  728. playerTwoStat.set(POINTS, playerTwoPoints - pointTwoDiff);
  729. playerOneStat.set(COMP_DRAWN, playerOneDrawn + 1);
  730. playerTwoStat.set(COMP_DRAWN, playerTwoDrawn + 1);
  731. _sm2 = new SystemMessage(SystemMessageId.C1_HAS_LOST_S2_OLYMPIAD_POINTS);
  732. _sm2.addString(_playerOneName);
  733. _sm2.addNumber(pointOneDiff);
  734. broadcastMessage(_sm2, false);
  735. _sm3 = new SystemMessage(SystemMessageId.C1_HAS_LOST_S2_OLYMPIAD_POINTS);
  736. _sm3.addString(_playerTwoName);
  737. _sm3.addNumber(pointTwoDiff);
  738. broadcastMessage(_sm3, false);
  739. }
  740. if (Config.DEBUG)
  741. _log.info("Olympia Result: " + _playerOneName + " vs " + _playerTwoName + " ... " + result);
  742. playerOneStat.set(COMP_DONE, playerOnePlayed + 1);
  743. playerTwoStat.set(COMP_DONE, playerTwoPlayed + 1);
  744. Olympiad.updateNobleStats(_playerOneID, playerOneStat);
  745. Olympiad.updateNobleStats(_playerTwoID, playerTwoStat);
  746. if (Config.ALT_OLY_LOG_FIGHTS)
  747. {
  748. LogRecord record = new LogRecord(Level.INFO, winner);
  749. record.setParameters(new Object[]{_playerOneName, _playerTwoName, playerOneHp, playerTwoHp, _damageP1, _damageP2, pointDiff, classed});
  750. _logResults.log(record);
  751. }
  752. byte step = 10;
  753. for (byte i = 40; i > 0; i -= step)
  754. {
  755. _sm = new SystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_TOWN_IN_S1_SECONDS);
  756. _sm.addNumber(i);
  757. broadcastMessage(_sm, false);
  758. switch (i)
  759. {
  760. case 10:
  761. step = 5;
  762. break;
  763. case 5:
  764. step = 1;
  765. break;
  766. }
  767. try
  768. {
  769. Thread.sleep(step*1000);
  770. }
  771. catch (InterruptedException e)
  772. {
  773. }
  774. }
  775. }
  776. protected boolean makeCompetitionStart()
  777. {
  778. _startTime = System.currentTimeMillis();
  779. if (_aborted)
  780. return false;
  781. _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  782. broadcastMessage(_sm, true);
  783. _gameIsStarted = true;
  784. try
  785. {
  786. for (L2PcInstance player : _players)
  787. {
  788. player.setIsOlympiadStart(true);
  789. player.updateEffectIcons();
  790. }
  791. }
  792. catch (Exception e)
  793. {
  794. _aborted = true;
  795. return false;
  796. }
  797. return true;
  798. }
  799. protected void addDamage(L2PcInstance player, int damage)
  800. {
  801. if (_playerOne == null || _playerTwo == null)
  802. return;
  803. if (player == _playerOne)
  804. _damageP1 += damage;
  805. else if (player == _playerTwo)
  806. _damageP2 += damage;
  807. }
  808. protected String getTitle()
  809. {
  810. final String msg = _playerOneName + " / " + _playerTwoName;
  811. return msg;
  812. }
  813. protected L2PcInstance[] getPlayers()
  814. {
  815. if (_players == null || _players.isEmpty())
  816. return null;
  817. final L2PcInstance[] players = new L2PcInstance[_players.size()];
  818. _players.toArray(players);
  819. return players;
  820. }
  821. protected void broadcastMessage(SystemMessage sm, boolean toAll)
  822. {
  823. for (L2PcInstance player : _players)
  824. {
  825. if (player != null)
  826. {
  827. player.sendPacket(sm);
  828. }
  829. }
  830. if (toAll && OlympiadManager.STADIUMS[_stadiumID].getSpectators() != null)
  831. {
  832. for (L2PcInstance spec : OlympiadManager.STADIUMS[_stadiumID].getSpectators())
  833. {
  834. if (spec != null)
  835. spec.sendPacket(sm);
  836. }
  837. }
  838. }
  839. protected void announceGame()
  840. {
  841. int objId;
  842. String npcName;
  843. for (L2Spawn manager : SpawnTable.getInstance().getSpawnTable().values())
  844. {
  845. if (manager != null && manager.getNpcid() == OLY_MANAGER)
  846. {
  847. objId = manager.getLastSpawn().getObjectId();
  848. npcName = manager.getLastSpawn().getName();
  849. manager.getLastSpawn().broadcastPacket(new CreatureSay(objId, Say2.SHOUT, npcName, "Olympiad is going to begin in Arena " + (_stadiumID + 1) + " in a moment."));
  850. }
  851. }
  852. }
  853. protected void saveResults(int _playerOne, int _playerTwo, int _playerOneClass, int _playerTwoClass, int _winner, long _startTime, long _fightTime, int _classed)
  854. {
  855. Connection con = null;
  856. try
  857. {
  858. con = L2DatabaseFactory.getInstance().getConnection();
  859. PreparedStatement statement = con.prepareStatement("INSERT INTO olympiad_fights (charOneId, charTwoId, charOneClass, charTwoClass, winner, start, time, classed) values(?,?,?,?,?,?,?,?)");
  860. statement.setInt(1, _playerOne);
  861. statement.setInt(2, _playerTwo);
  862. statement.setInt(3, _playerOneClass);
  863. statement.setInt(4, _playerTwoClass);
  864. statement.setInt(5, _winner);
  865. statement.setLong(6, _startTime);
  866. statement.setLong(7, _fightTime);
  867. statement.setInt(8, _classed);
  868. statement.execute();
  869. statement.close();
  870. }
  871. catch (SQLException e)
  872. {
  873. if(_log.isLoggable(Level.SEVERE))
  874. _log.log(Level.SEVERE, "SQL exception while saving olympiad fight.", e);
  875. }
  876. finally
  877. {
  878. L2DatabaseFactory.close(con);
  879. }
  880. }
  881. }
  882. /**
  883. *
  884. * @author ascharot
  885. *
  886. */
  887. class OlympiadGameTask implements Runnable
  888. {
  889. protected static final Logger _log = Logger.getLogger(OlympiadGameTask.class.getName());
  890. public OlympiadGame _game = null;
  891. protected static final long BATTLE_PERIOD = Config.ALT_OLY_BATTLE; // 6 mins
  892. private boolean _terminated = false;
  893. private boolean _started = false;
  894. public boolean isTerminated()
  895. {
  896. return _terminated || _game._aborted;
  897. }
  898. public boolean isStarted()
  899. {
  900. return _started;
  901. }
  902. public OlympiadGameTask(OlympiadGame game)
  903. {
  904. _game = game;
  905. }
  906. protected boolean checkBattleStatus()
  907. {
  908. boolean _pOneCrash = (_game._playerOne == null || _game._playerOneDisconnected);
  909. boolean _pTwoCrash = (_game._playerTwo == null || _game._playerTwoDisconnected);
  910. if (_pOneCrash || _pTwoCrash || _game._aborted)
  911. {
  912. return false;
  913. }
  914. return true;
  915. }
  916. protected boolean checkDefaulted()
  917. {
  918. _game._playerOne = L2World.getInstance().getPlayer(_game._playerOneID);
  919. _game._players.set(0, _game._playerOne);
  920. _game._playerTwo = L2World.getInstance().getPlayer(_game._playerTwoID);
  921. _game._players.set(1, _game._playerTwo);
  922. for (int i = 0; i < 2; i++)
  923. {
  924. boolean defaulted = false;
  925. L2PcInstance player = _game._players.get(i);
  926. if (player != null)
  927. player.setOlympiadGameId(_game._stadiumID);
  928. L2PcInstance otherPlayer = _game._players.get(i^1);
  929. SystemMessage sm = null;
  930. if (player == null)
  931. {
  932. defaulted = true;
  933. }
  934. else if (player.isDead())
  935. {
  936. sm = new SystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_OLYMPIAD_WHILE_DEAD);
  937. sm.addPcName(player);
  938. defaulted = true;
  939. }
  940. else if (player.isSubClassActive())
  941. {
  942. sm = new SystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_IN_OLYMPIAD_WHILE_CHANGED_TO_SUB_CLASS);
  943. sm.addPcName(player);
  944. defaulted = true;
  945. }
  946. else if (player.isCursedWeaponEquipped())
  947. {
  948. sm = new SystemMessage(SystemMessageId.C1_CANNOT_JOIN_OLYMPIAD_POSSESSING_S2);
  949. sm.addPcName(player);
  950. sm.addItemName(player.getCursedWeaponEquippedId());
  951. defaulted = true;
  952. }
  953. else if (player.getInventoryLimit()*0.8 <= player.getInventory().getSize())
  954. {
  955. sm = new SystemMessage(SystemMessageId.C1_CANNOT_PARTICIPATE_IN_OLYMPIAD_INVENTORY_SLOT_EXCEEDS_80_PERCENT);
  956. sm.addPcName(player);
  957. defaulted = true;
  958. }
  959. if (defaulted)
  960. {
  961. if (player != null)
  962. player.sendPacket(sm);
  963. if (otherPlayer != null)
  964. otherPlayer.sendPacket(new SystemMessage(SystemMessageId.THE_GAME_HAS_BEEN_CANCELLED_BECAUSE_THE_OTHER_PARTY_DOES_NOT_MEET_THE_REQUIREMENTS_FOR_JOINING_THE_GAME));
  965. if (i == 0)
  966. _game._playerOneDefaulted = true;
  967. else
  968. _game._playerTwoDefaulted = true;
  969. }
  970. }
  971. return _game._playerOneDefaulted || _game._playerTwoDefaulted;
  972. }
  973. public void run()
  974. {
  975. _started = true;
  976. if (_game != null)
  977. {
  978. if (_game._playerOne == null || _game._playerTwo == null)
  979. {
  980. return;
  981. }
  982. if (teleportCountdown())
  983. runGame();
  984. _terminated = true;
  985. _game.validateWinner();
  986. _game.PlayersStatusBack();
  987. _game.cleanEffects();
  988. if (_game._gamestarted)
  989. {
  990. _game._gamestarted = false;
  991. OlympiadManager.STADIUMS[_game._stadiumID].closeDoors();
  992. try
  993. {
  994. _game.portPlayersBack();
  995. }
  996. catch (Exception e)
  997. {
  998. _log.log(Level.WARNING, "Exception on portPlayersBack(): " + e.getMessage(), e);
  999. }
  1000. }
  1001. if (OlympiadManager.STADIUMS[_game._stadiumID].getSpectators() != null)
  1002. {
  1003. for (L2PcInstance spec : OlympiadManager.STADIUMS[_game._stadiumID].getSpectators())
  1004. {
  1005. if (spec != null)
  1006. spec.sendPacket(new ExOlympiadMatchEnd());
  1007. }
  1008. }
  1009. if (_game._spawnOne != null)
  1010. {
  1011. _game._spawnOne.getLastSpawn().deleteMe();
  1012. _game._spawnOne = null;
  1013. }
  1014. if (_game._spawnTwo != null)
  1015. {
  1016. _game._spawnTwo.getLastSpawn().deleteMe();
  1017. _game._spawnTwo = null;
  1018. }
  1019. _game.clearPlayers();
  1020. OlympiadManager.getInstance().removeGame(_game);
  1021. _game = null;
  1022. }
  1023. }
  1024. private boolean runGame()
  1025. {
  1026. SystemMessage sm;
  1027. // Checking for opponents and teleporting to arena
  1028. if (checkDefaulted())
  1029. {
  1030. return false;
  1031. }
  1032. OlympiadManager.STADIUMS[_game._stadiumID].closeDoors();
  1033. _game.portPlayersToArena();
  1034. _game.removals();
  1035. if (Config.ALT_OLY_ANNOUNCE_GAMES)
  1036. _game.announceGame();
  1037. try
  1038. {
  1039. Thread.sleep(5000);
  1040. }
  1041. catch (InterruptedException e)
  1042. {
  1043. }
  1044. synchronized (this)
  1045. {
  1046. if (!OlympiadGame._battleStarted)
  1047. OlympiadGame._battleStarted = true;
  1048. }
  1049. byte step = 10;
  1050. for (byte i = 60; i > 0; i -= step)
  1051. {
  1052. sm = new SystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
  1053. sm.addNumber(i);
  1054. _game.broadcastMessage(sm, true);
  1055. switch (i)
  1056. {
  1057. case 10:
  1058. _game._damageP1 = 0;
  1059. _game._damageP2 = 0;
  1060. OlympiadManager.STADIUMS[_game._stadiumID].openDoors();
  1061. step = 5;
  1062. break;
  1063. case 5:
  1064. step = 1;
  1065. break;
  1066. }
  1067. try
  1068. {
  1069. Thread.sleep(step*1000);
  1070. }
  1071. catch (InterruptedException e)
  1072. {
  1073. }
  1074. }
  1075. if (!checkBattleStatus())
  1076. {
  1077. return false;
  1078. }
  1079. _game._spawnOne.getLastSpawn().deleteMe();
  1080. _game._spawnTwo.getLastSpawn().deleteMe();
  1081. _game._spawnOne = null;
  1082. _game._spawnTwo = null;
  1083. if (!_game.makeCompetitionStart())
  1084. {
  1085. return false;
  1086. }
  1087. _game._playerOne.sendPacket(new ExOlympiadUserInfo(_game._playerOne));
  1088. _game._playerOne.sendPacket(new ExOlympiadUserInfo(_game._playerTwo));
  1089. _game._playerTwo.sendPacket(new ExOlympiadUserInfo(_game._playerTwo));
  1090. _game._playerTwo.sendPacket(new ExOlympiadUserInfo(_game._playerOne));
  1091. if (OlympiadManager.STADIUMS[_game._stadiumID].getSpectators() != null)
  1092. {
  1093. for (L2PcInstance spec : OlympiadManager.STADIUMS[_game._stadiumID].getSpectators())
  1094. {
  1095. if (spec != null)
  1096. {
  1097. spec.sendPacket(new ExOlympiadUserInfo(_game._playerOne));
  1098. spec.sendPacket(new ExOlympiadUserInfo(_game._playerTwo));
  1099. }
  1100. }
  1101. }
  1102. // Wait 3 mins (Battle)
  1103. for (int i = 0; i < BATTLE_PERIOD; i += 10000)
  1104. {
  1105. try
  1106. {
  1107. Thread.sleep(10000);
  1108. // If game haveWinner then stop waiting battle_period
  1109. // and validate winner
  1110. if (_game.haveWinner())
  1111. break;
  1112. }
  1113. catch (InterruptedException e)
  1114. {
  1115. }
  1116. }
  1117. return checkBattleStatus();
  1118. }
  1119. private boolean teleportCountdown()
  1120. {
  1121. SystemMessage sm;
  1122. // Waiting for teleport to arena
  1123. byte step = 60;
  1124. for (byte i = Config.ALT_OLY_WAIT_TIME; i > 0; i -= step)
  1125. {
  1126. sm = new SystemMessage(SystemMessageId.YOU_WILL_ENTER_THE_OLYMPIAD_STADIUM_IN_S1_SECOND_S);
  1127. sm.addNumber(i);
  1128. _game.broadcastMessage(sm, false);
  1129. switch (i)
  1130. {
  1131. case 60:
  1132. step = 30;
  1133. break;
  1134. case 30:
  1135. step = 15;
  1136. break;
  1137. case 15:
  1138. step = 5;
  1139. break;
  1140. case 5:
  1141. step = 1;
  1142. break;
  1143. }
  1144. try
  1145. {
  1146. Thread.sleep(step*1000);
  1147. }
  1148. catch (InterruptedException e)
  1149. {
  1150. return false;
  1151. }
  1152. }
  1153. return true;
  1154. }
  1155. }