OlympiadGame.java 38 KB

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