OlympiadGame.java 38 KB

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