Olympiad.java 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447
  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. /**
  16. * @author godson
  17. */
  18. package net.sf.l2j.gameserver;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileOutputStream;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.sql.Connection;
  25. import java.sql.PreparedStatement;
  26. import java.sql.ResultSet;
  27. import java.sql.SQLException;
  28. import java.util.Calendar;
  29. import java.util.Map;
  30. import java.util.Properties;
  31. import java.util.concurrent.ScheduledFuture;
  32. import java.util.logging.Logger;
  33. import javolution.util.FastMap;
  34. import net.sf.l2j.Config;
  35. import net.sf.l2j.L2DatabaseFactory;
  36. import net.sf.l2j.gameserver.datatables.DoorTable;
  37. import net.sf.l2j.gameserver.datatables.HeroSkillTable;
  38. import net.sf.l2j.gameserver.datatables.NpcTable;
  39. import net.sf.l2j.gameserver.datatables.SpawnTable;
  40. import net.sf.l2j.gameserver.instancemanager.OlympiadStadiaManager;
  41. import net.sf.l2j.gameserver.model.Inventory;
  42. import net.sf.l2j.gameserver.model.L2ItemInstance;
  43. import net.sf.l2j.gameserver.model.L2Party;
  44. import net.sf.l2j.gameserver.model.L2Skill;
  45. import net.sf.l2j.gameserver.model.L2Spawn;
  46. import net.sf.l2j.gameserver.model.L2Summon;
  47. import net.sf.l2j.gameserver.model.L2World;
  48. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  49. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  50. import net.sf.l2j.gameserver.model.entity.Hero;
  51. import net.sf.l2j.gameserver.network.SystemMessageId;
  52. import net.sf.l2j.gameserver.serverpackets.ExAutoSoulShot;
  53. import net.sf.l2j.gameserver.serverpackets.ExOlympiadMode;
  54. import net.sf.l2j.gameserver.serverpackets.ExOlympiadUserInfoSpectator;
  55. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  56. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  57. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  58. import net.sf.l2j.gameserver.templates.StatsSet;
  59. import net.sf.l2j.util.L2FastList;
  60. import net.sf.l2j.util.Rnd;
  61. public class Olympiad
  62. {
  63. /**
  64. *
  65. * @author ascharot
  66. *
  67. */
  68. private class OlympiadGameTask implements Runnable
  69. {
  70. public L2OlympiadGame _game = null;
  71. private SystemMessage _sm;
  72. private SystemMessage _sm2;
  73. private boolean _terminated = false;
  74. public boolean isTerminated()
  75. {
  76. return _terminated;
  77. }
  78. private boolean _started = false;
  79. public boolean isStarted()
  80. {
  81. return _started;
  82. }
  83. public OlympiadGameTask(L2OlympiadGame game)
  84. {
  85. _game = game;
  86. }
  87. protected boolean checkBattleStatus()
  88. {
  89. boolean _pOneCrash = (_game._playerOne == null || _game._playerOneDisconnected);
  90. boolean _pTwoCrash = (_game._playerTwo == null || _game._playerTwoDisconnected);
  91. if(_pOneCrash || _pTwoCrash || _game._aborted) {
  92. return false;
  93. }
  94. return true;
  95. }
  96. protected boolean checkStatus()
  97. {
  98. boolean _pOneCrash = (_game._playerOne == null || _game._playerOneDisconnected);
  99. boolean _pTwoCrash = (_game._playerTwo == null || _game._playerTwoDisconnected);
  100. StatsSet playerOneStat;
  101. StatsSet playerTwoStat;
  102. playerOneStat = _nobles.get(_game._playerOneID);
  103. playerTwoStat = _nobles.get(_game._playerTwoID);
  104. int playerOnePlayed = playerOneStat.getInteger(COMP_DONE);
  105. int playerTwoPlayed = playerTwoStat.getInteger(COMP_DONE);
  106. if(_pOneCrash || _pTwoCrash || _game._aborted) {
  107. if (_pOneCrash && !_pTwoCrash){
  108. try{
  109. int playerOnePoints = playerOneStat.getInteger(POINTS);
  110. int transferPoints = playerOnePoints / 5;
  111. playerOneStat.set(POINTS, playerOnePoints - transferPoints);
  112. if (Config.DEBUG)
  113. _log.info("Olympia Result: "+_game._playerOneName+" vs "+_game._playerTwoName+" ... "+_game._playerOneName+" lost "+transferPoints+" points for crash");
  114. int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  115. playerTwoStat.set(POINTS, playerTwoPoints + transferPoints);
  116. if (Config.DEBUG)
  117. _log.info("Olympia Result: "+_game._playerOneName+" vs "+_game._playerTwoName+" ... "+_game._playerTwoName+" Win "+transferPoints+" points");
  118. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  119. _sm2 = new SystemMessage(SystemMessageId.S1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  120. _sm.addString(_game._playerTwoName);
  121. broadcastMessage(_sm, true);
  122. _sm2.addString(_game._playerTwoName);
  123. _sm2.addNumber(transferPoints);
  124. broadcastMessage(_sm2, true);
  125. } catch(Exception e){e.printStackTrace();}
  126. }
  127. if (_pTwoCrash && !_pOneCrash){
  128. try{
  129. int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  130. int transferPoints = playerTwoPoints / 5;
  131. playerTwoStat.set(POINTS, playerTwoPoints - transferPoints);
  132. if (Config.DEBUG)
  133. _log.info("Olympia Result: "+_game._playerTwoName+" vs "+_game._playerOneName+" ... "+_game._playerTwoName+" lost "+transferPoints+" points for crash");
  134. int playerOnePoints = playerOneStat.getInteger(POINTS);
  135. playerOneStat.set(POINTS, playerOnePoints + transferPoints);
  136. if (Config.DEBUG)
  137. _log.info("Olympia Result: "+_game._playerTwoName+" vs "+_game._playerOneName+" ... "+_game._playerOneName+" Win "+transferPoints+" points");
  138. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  139. _sm2 = new SystemMessage(SystemMessageId.S1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  140. _sm.addString(_game._playerOneName);
  141. broadcastMessage(_sm, true);
  142. _sm2.addString(_game._playerOneName);
  143. _sm2.addNumber(transferPoints);
  144. broadcastMessage(_sm2, true);
  145. } catch(Exception e){e.printStackTrace();}
  146. }
  147. playerOneStat.set(COMP_DONE, playerOnePlayed + 1);
  148. playerTwoStat.set(COMP_DONE, playerTwoPlayed + 1);
  149. _terminated = true;
  150. _game._gamestarted = false;
  151. _game.closeDoors();
  152. _game.PlayersStatusBack();
  153. try{
  154. _game.portPlayersBack();
  155. }catch(Exception e){e.printStackTrace();}
  156. _game = null;
  157. return false;
  158. }
  159. return true;
  160. }
  161. public void run()
  162. {
  163. _started = true;
  164. if(_game != null)
  165. {
  166. if(_game._playerOne != null && _game._playerTwo != null)
  167. {
  168. //Waiting for teleport to arena
  169. for (int i=120;i>10;i-=5)
  170. {
  171. switch(i) {
  172. case 120:
  173. case 60:
  174. case 30:
  175. case 15:
  176. _game.sendMessageToPlayers(false,i);
  177. break;
  178. }
  179. try{ Thread.sleep(5000); }catch (InterruptedException e){}
  180. }
  181. for (int i=5;i>0;i--)
  182. {
  183. _game.sendMessageToPlayers(false,i);
  184. try{ Thread.sleep(1000); }catch (InterruptedException e){}
  185. }
  186. //Checking for openents and teleporting to arena
  187. if(!checkStatus()) { return; }
  188. _game.closeDoors();
  189. _game.removals();
  190. _game.portPlayersToArena();
  191. try{ Thread.sleep(5000); }catch (InterruptedException e){}
  192. synchronized(this){
  193. if(!_battleStarted)
  194. _battleStarted = true;
  195. }
  196. for (int i=60;i>10;i-=10)
  197. {
  198. _game.sendMessageToPlayers(true,i);
  199. try{ Thread.sleep(10000); }catch (InterruptedException e){}
  200. if (i==20) {
  201. _game.additions();
  202. _game.openDoors();
  203. _game.sendMessageToPlayers(true,10);
  204. try{ Thread.sleep(5000); }catch (InterruptedException e){}
  205. }
  206. }
  207. for (int i=5;i>0;i--)
  208. {
  209. _game.sendMessageToPlayers(true,i);
  210. try{ Thread.sleep(1000); }catch (InterruptedException e){}
  211. }
  212. if(!checkStatus()) { return; }
  213. UnSpawnBuffer(_game._spawnOne);
  214. UnSpawnBuffer(_game._spawnTwo);
  215. _game._playerOne.sendPacket(new ExOlympiadUserInfoSpectator(_game._playerTwo, 1));
  216. _game._playerTwo.sendPacket(new ExOlympiadUserInfoSpectator(_game._playerOne, 1));
  217. if (_game._spectators != null)
  218. {
  219. for (L2PcInstance spec : _game.getSpectators())
  220. {
  221. try {
  222. spec.sendPacket(new ExOlympiadUserInfoSpectator(_game._playerTwo, 2));
  223. spec.sendPacket(new ExOlympiadUserInfoSpectator(_game._playerOne, 1));
  224. } catch (NullPointerException e) {}
  225. }
  226. }
  227. _game.makeCompetitionStart();
  228. //Wait 3 mins (Battle)
  229. for(int i=0; i<BATTLE_PERIOD; i += 10000)
  230. {
  231. try{
  232. Thread.sleep(10000);
  233. //If game haveWinner thean stop waiting battle_period and validate winner
  234. if(_game.haveWinner() || !checkBattleStatus())
  235. break;
  236. } catch (InterruptedException e){}
  237. }
  238. if(!checkStatus()) { return; }
  239. _terminated = true;
  240. _game._gamestarted = false;
  241. try{
  242. _game.validateWinner();
  243. _game.PlayersStatusBack();
  244. _game.removals();
  245. _game.portPlayersBack();
  246. }catch(Exception e){e.printStackTrace();}
  247. _game = null;
  248. }
  249. }
  250. }
  251. private void broadcastMessage(SystemMessage sm, boolean toAll)
  252. {
  253. try {
  254. _game._playerOne.sendPacket(sm);
  255. _game._playerTwo.sendPacket(sm);
  256. } catch (Exception e) {}
  257. if (toAll && _game._spectators != null)
  258. {
  259. for (L2PcInstance spec : _game._spectators)
  260. {
  261. try { spec.sendPacket(sm); } catch (NullPointerException e) {}
  262. }
  263. }
  264. }
  265. }
  266. protected static final Logger _log = Logger.getLogger(Olympiad.class.getName());
  267. private static Olympiad _instance;
  268. protected static Map<Integer, StatsSet> _nobles;
  269. protected static L2FastList<StatsSet> _heroesToBe;
  270. protected static L2FastList<L2PcInstance> _nonClassBasedRegisters;
  271. protected static Map<Integer, L2FastList<L2PcInstance>> _classBasedRegisters;
  272. private static final String OLYMPIAD_DATA_FILE = "config/olympiad.properties";
  273. public static final String OLYMPIAD_HTML_FILE = "data/html/olympiad/";
  274. private static final String OLYMPIAD_LOAD_NOBLES = "SELECT * FROM olympiad_nobles";
  275. private static final String OLYMPIAD_SAVE_NOBLES = "INSERT INTO olympiad_nobles " +
  276. "VALUES (?,?,?,?,?)";
  277. private static final String OLYMPIAD_UPDATE_NOBLES = "UPDATE olympiad_nobles SET " +
  278. "olympiad_points = ?, competitions_done = ? WHERE charId = ?";
  279. private static final String OLYMPIAD_GET_HEROS = "SELECT charId, char_name FROM " +
  280. "olympiad_nobles WHERE class_id = ? AND competitions_done >= 9 ORDER BY " +
  281. "olympiad_points DESC, competitions_done DESC";
  282. private static final String GET_EACH_CLASS_LEADER = "SELECT char_name FROM " +
  283. "olympiad_nobles WHERE class_id = ? ORDER BY olympiad_points DESC, " +
  284. "competitions_done DESC";
  285. private static final String OLYMPIAD_DELETE_ALL = "DELETE FROM olympiad_nobles";
  286. private static final int[] HERO_IDS = {88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,
  287. 106,107,108,109,110,111,112,113,114,115,116,117,118,131,132,133,134};
  288. private static final int COMP_START = Config.ALT_OLY_START_TIME; // 6PM
  289. private static final int COMP_MIN = Config.ALT_OLY_MIN; // 00 mins
  290. private static final long COMP_PERIOD = Config.ALT_OLY_CPERIOD; // 6 hours
  291. protected static final long BATTLE_PERIOD = Config.ALT_OLY_BATTLE; // 6 mins
  292. protected static final long BATTLE_WAIT = Config.ALT_OLY_BWAIT; // 10mins
  293. protected static final long INITIAL_WAIT = Config.ALT_OLY_IWAIT; // 5mins
  294. protected static final long WEEKLY_PERIOD = Config.ALT_OLY_WPERIOD; // 1 week
  295. protected static final long VALIDATION_PERIOD = Config.ALT_OLY_VPERIOD; // 24 hours
  296. /* FOR TESTING
  297. private static final int COMP_START = 8; // 1PM - 2PM
  298. private static final int COMP_MIN = 15; // 20mins
  299. private static final long COMP_PERIOD = 7200000; // 2hours
  300. private static final long BATTLE_PERIOD = 180000; // 3mins
  301. private static final long BATTLE_WAIT = 600000; // 10mins
  302. private static final long INITIAL_WAIT = 300000; // 5mins
  303. private static final long WEEKLY_PERIOD = 7200000; // 2 hours
  304. private static final long VALIDATION_PERIOD = 3600000; // 1 hour */
  305. private static final int DEFAULT_POINTS = 18;
  306. protected static final int WEEKLY_POINTS = 3;
  307. public static final String CHAR_ID = "charId";
  308. public static final String CLASS_ID = "class_id";
  309. public static final String CHAR_NAME = "char_name";
  310. public static final String POINTS = "olympiad_points";
  311. public static final String COMP_DONE = "competitions_done";
  312. public static DoorTable _doorTable;
  313. protected long _olympiadEnd;
  314. protected long _validationEnd;
  315. protected int _period;
  316. protected long _nextWeeklyChange;
  317. protected int _currentCycle;
  318. private long _compEnd;
  319. private Calendar _compStart;
  320. protected static boolean _inCompPeriod;
  321. protected static boolean _isOlympiadEnd;
  322. protected static boolean _compStarted = false;
  323. protected static boolean _battleStarted;
  324. protected static boolean _cycleTerminated;
  325. protected ScheduledFuture<?> _scheduledCompStart;
  326. protected ScheduledFuture<?> _scheduledCompEnd;
  327. protected ScheduledFuture<?> _scheduledOlympiadEnd;
  328. protected ScheduledFuture<?> _scheduledManagerTask;
  329. protected ScheduledFuture<?> _scheduledWeeklyTask;
  330. protected ScheduledFuture<?> _scheduledValdationTask;
  331. public static class Stadia
  332. {
  333. private boolean _freeToUse = true;
  334. public boolean isFreeToUse()
  335. {
  336. return _freeToUse;
  337. }
  338. public void setStadiaBusy()
  339. {
  340. _freeToUse = false;
  341. }
  342. public void setStadiaFree()
  343. {
  344. _freeToUse = true;
  345. }
  346. private int[] _coords = new int[3];
  347. private int[] _doors = new int[2];
  348. public int[] getCoordinates()
  349. {
  350. return _coords;
  351. }
  352. public int[] getDoorID()
  353. {
  354. return _doors;
  355. }
  356. public Stadia(int[] coords, int[] doors)
  357. {
  358. _coords = coords;
  359. _doors = doors;
  360. }
  361. public Stadia(int x, int y, int z, int d1, int d2)
  362. {
  363. _coords[0] = x;
  364. _coords[1] = y;
  365. _coords[2] = z;
  366. _doors[0] = d1;
  367. _doors[1] = d2;
  368. }
  369. }
  370. protected static final Stadia[] STADIUMS =
  371. {
  372. new Stadia(-20838, -21075, -3000, 19170001, 19170002),
  373. new Stadia(-88000, -252637, -3331, 17100001, 17100002),
  374. new Stadia(-83760, -252637, -3331, 17100003, 17100004),
  375. new Stadia(-79600, -252637, -3331, 17100005, 17100006),
  376. new Stadia(-75648, -252637, -3331, 17100007, 17100008),
  377. new Stadia(-88000, -249762, -3331, 17100009, 17100010),
  378. new Stadia(-83760, -249762, -3331, 17100011, 17100012),
  379. new Stadia(-79600, -249762, -3331, 17100013, 17100014),
  380. new Stadia(-75648, -249762, -3331, 17100015, 17100016),
  381. new Stadia(-88000, -246951, -3331, 17100017, 17100018),
  382. new Stadia(-83760, -246951, -3331, 17100019, 17100020),
  383. new Stadia(-79600, -246951, -3331, 17100021, 17100022),
  384. new Stadia(-75648, -246951, -3331, 17100023, 17100024),
  385. new Stadia(-88000, -244290, -3331, 17100025, 17100026),
  386. new Stadia(-83760, -244290, -3331, 17100027, 17100028),
  387. new Stadia(-79600, -244290, -3331, 17100029, 17100030),
  388. new Stadia(-75648, -244290, -3331, 17100031, 17100032),
  389. new Stadia(-88000, -241490, -3331, 17100033, 17100034),
  390. new Stadia(-83760, -241490, -3331, 17100035, 17100036),
  391. new Stadia(-79600, -241490, -3331, 17100037, 17100038),
  392. new Stadia(-75648, -241490, -3331, 17100039, 17100040),
  393. new Stadia(-88000, -238825, -3331, 17100041, 17100042),
  394. new Stadia(-83760, -238825, -3331, 17100043, 17100044)
  395. };
  396. private static enum COMP_TYPE
  397. {
  398. CLASSED,
  399. NON_CLASSED
  400. }
  401. protected static OlympiadManager _manager;
  402. public static Olympiad getInstance()
  403. {
  404. if (_instance == null)
  405. _instance = new Olympiad();
  406. return _instance;
  407. }
  408. public Olympiad()
  409. {
  410. try
  411. {
  412. load();
  413. }
  414. catch(IOException e)
  415. {
  416. e.printStackTrace();
  417. }
  418. catch(SQLException s)
  419. {
  420. s.printStackTrace();
  421. }
  422. if (_period == 0) init();
  423. }
  424. private void load() throws IOException, SQLException
  425. {
  426. _nobles = new FastMap<Integer, StatsSet>();
  427. Properties OlympiadProperties = new Properties();
  428. InputStream is = new FileInputStream(new File("./" + OLYMPIAD_DATA_FILE));
  429. OlympiadProperties.load(is);
  430. is.close();
  431. _currentCycle = Integer.parseInt(OlympiadProperties.getProperty("CurrentCycle", "1"));
  432. _period = Integer.parseInt(OlympiadProperties.getProperty("Period", "0"));
  433. _olympiadEnd = Long.parseLong(OlympiadProperties.getProperty("OlympiadEnd", "0"));
  434. _validationEnd = Long.parseLong(OlympiadProperties.getProperty("ValdationEnd", "0"));
  435. _nextWeeklyChange = Long.parseLong(OlympiadProperties.getProperty("NextWeeklyChange", "0"));
  436. switch(_period)
  437. {
  438. case 0:
  439. if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
  440. setNewOlympiadEnd();
  441. else
  442. _isOlympiadEnd = false;
  443. break;
  444. case 1:
  445. if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  446. {
  447. _isOlympiadEnd = true;
  448. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  449. public void run()
  450. {
  451. _period = 0;
  452. _currentCycle++;
  453. deleteNobles();
  454. setNewOlympiadEnd();
  455. init();
  456. }
  457. }, getMillisToValidationEnd());
  458. }
  459. else
  460. {
  461. _currentCycle++;
  462. _period = 0;
  463. deleteNobles();
  464. setNewOlympiadEnd();
  465. }
  466. break;
  467. default:
  468. _log.warning("Olympiad System: Omg something went wrong in loading!! Period = " + _period);
  469. return;
  470. }
  471. try
  472. {
  473. Connection con = L2DatabaseFactory.getInstance().getConnection();
  474. PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_NOBLES);
  475. ResultSet rset = statement.executeQuery();
  476. while(rset.next())
  477. {
  478. StatsSet statDat = new StatsSet();
  479. int charId = rset.getInt(CHAR_ID);
  480. statDat.set(CLASS_ID, rset.getInt(CLASS_ID));
  481. statDat.set(CHAR_NAME, rset.getString(CHAR_NAME));
  482. statDat.set(POINTS, rset.getInt(POINTS));
  483. statDat.set(COMP_DONE, rset.getInt(COMP_DONE));
  484. statDat.set("to_save", false);
  485. _nobles.put(charId, statDat);
  486. }
  487. rset.close();
  488. statement.close();
  489. con.close();
  490. }
  491. catch(Exception e)
  492. {
  493. e.printStackTrace();
  494. }
  495. synchronized(this)
  496. {
  497. _log.info("Olympiad System: Loading Olympiad System....");
  498. if (_period == 0)
  499. _log.info("Olympiad System: Currently in Olympiad Period");
  500. else
  501. _log.info("Olympiad System: Currently in Validation Period");
  502. _log.info("Olympiad System: Period Ends....");
  503. long milliToEnd;
  504. if (_period == 0)
  505. milliToEnd = getMillisToOlympiadEnd();
  506. else
  507. milliToEnd = getMillisToValidationEnd();
  508. double numSecs = (milliToEnd / 1000) % 60;
  509. double countDown = ((milliToEnd / 1000) - numSecs) / 60;
  510. int numMins = (int) Math.floor(countDown % 60);
  511. countDown = (countDown - numMins) / 60;
  512. int numHours = (int) Math.floor(countDown % 24);
  513. int numDays = (int) Math.floor((countDown - numHours) / 24);
  514. _log.info("Olympiad System: In " + numDays + " days, " + numHours
  515. + " hours and " + numMins + " mins.");
  516. if (_period == 0)
  517. {
  518. _log.info("Olympiad System: Next Weekly Change is in....");
  519. milliToEnd = getMillisToWeekChange();
  520. double numSecs2 = (milliToEnd / 1000) % 60;
  521. double countDown2 = ((milliToEnd / 1000) - numSecs2) / 60;
  522. int numMins2 = (int) Math.floor(countDown2 % 60);
  523. countDown2 = (countDown2 - numMins2) / 60;
  524. int numHours2 = (int) Math.floor(countDown2 % 24);
  525. int numDays2 = (int) Math.floor((countDown2 - numHours2) / 24);
  526. _log.info("Olympiad System: " + numDays2 + " days, " + numHours2
  527. + " hours and " + numMins2 + " mins.");
  528. }
  529. }
  530. _log.info("Olympiad System: Loaded " + _nobles.size() + " Nobles");
  531. }
  532. protected void init()
  533. {
  534. if (_period == 1)
  535. return;
  536. _nonClassBasedRegisters = new L2FastList<L2PcInstance>();
  537. _classBasedRegisters = new FastMap<Integer, L2FastList<L2PcInstance>>();
  538. _compStart = Calendar.getInstance();
  539. _compStart.set(Calendar.HOUR_OF_DAY, COMP_START);
  540. _compStart.set(Calendar.MINUTE, COMP_MIN);
  541. _compEnd = _compStart.getTimeInMillis() + COMP_PERIOD;
  542. _scheduledOlympiadEnd = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  543. public void run()
  544. {
  545. SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_ENDED);
  546. sm.addNumber(_currentCycle);
  547. Announcements.getInstance().announceToAll(sm);
  548. Announcements.getInstance().announceToAll("Olympiad Validation Period has began");
  549. _isOlympiadEnd = true;
  550. if (_scheduledManagerTask != null)
  551. _scheduledManagerTask.cancel(true);
  552. if (_scheduledWeeklyTask != null)
  553. _scheduledWeeklyTask.cancel(true);
  554. Calendar validationEnd = Calendar.getInstance();
  555. _validationEnd = validationEnd.getTimeInMillis() + VALIDATION_PERIOD;
  556. saveNobleData();
  557. _period = 1;
  558. sortHerosToBe();
  559. giveHeroBonus();
  560. Hero.getInstance().computeNewHeroes(_heroesToBe);
  561. try {
  562. save();
  563. }
  564. catch (Exception e) {
  565. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  566. }
  567. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  568. public void run()
  569. {
  570. Announcements.getInstance().announceToAll("Olympiad Validation Period has ended");
  571. _period = 0;
  572. _currentCycle++;
  573. deleteNobles();
  574. setNewOlympiadEnd();
  575. init();
  576. }
  577. }, getMillisToValidationEnd());
  578. }
  579. }, getMillisToOlympiadEnd());
  580. updateCompStatus();
  581. scheduleWeeklyChange();
  582. }
  583. public boolean registerNoble(L2PcInstance noble, boolean classBased)
  584. {
  585. SystemMessage sm;
  586. /*
  587. if (_compStarted)
  588. {
  589. noble.sendMessage("Cant Register whilst competition is under way");
  590. return false;
  591. }
  592. */
  593. if (!_inCompPeriod)
  594. {
  595. sm = new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  596. noble.sendPacket(sm);
  597. return false;
  598. }
  599. if (noble.isCursedWeaponEquipped())
  600. {
  601. noble.sendMessage("You can't participate to Olympiad while holding a cursed weapon.");
  602. return false;
  603. }
  604. if (!noble.isNoble())
  605. {
  606. sm = new SystemMessage(SystemMessageId.ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
  607. noble.sendPacket(sm);
  608. return false;
  609. }
  610. if (noble.getBaseClass() != noble.getClassId().getId())
  611. {
  612. sm = new SystemMessage(SystemMessageId.YOU_CANT_JOIN_THE_OLYMPIAD_WITH_A_SUB_JOB_CHARACTER);
  613. noble.sendPacket(sm);
  614. return false;
  615. }
  616. if (!_nobles.containsKey(noble.getObjectId()))
  617. {
  618. StatsSet statDat = new StatsSet();
  619. statDat.set(CLASS_ID, noble.getClassId().getId());
  620. statDat.set(CHAR_NAME, noble.getName());
  621. statDat.set(POINTS, DEFAULT_POINTS);
  622. statDat.set(COMP_DONE, 0);
  623. statDat.set("to_save", true);
  624. _nobles.put(noble.getObjectId(), statDat);
  625. }
  626. if (_classBasedRegisters.containsKey(noble.getClassId().getId()))
  627. {
  628. L2FastList<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  629. for (L2PcInstance partecipant: classed)
  630. {
  631. if (partecipant.getObjectId()==noble.getObjectId())
  632. {
  633. sm = new SystemMessage(SystemMessageId.YOU_ARE_ALREADY_ON_THE_WAITING_LIST_TO_PARTICIPATE_IN_THE_GAME_FOR_YOUR_CLASS);
  634. noble.sendPacket(sm);
  635. return false;
  636. }
  637. }
  638. }
  639. for (L2PcInstance partecipant: _nonClassBasedRegisters)
  640. {
  641. if (partecipant.getObjectId()==noble.getObjectId())
  642. {
  643. sm = new SystemMessage(SystemMessageId.YOU_ARE_ALREADY_ON_THE_WAITING_LIST_FOR_ALL_CLASSES_WAITING_TO_PARTICIPATE_IN_THE_GAME);
  644. noble.sendPacket(sm);
  645. return false;
  646. }
  647. }
  648. for (L2OlympiadGame g : _manager.getOlympiadGames().values())
  649. {
  650. for(L2PcInstance player : g.getPlayers())
  651. {
  652. if(player.getObjectId() == noble.getObjectId())
  653. {
  654. sm = new SystemMessage(SystemMessageId.YOU_ARE_ALREADY_ON_THE_WAITING_LIST_FOR_ALL_CLASSES_WAITING_TO_PARTICIPATE_IN_THE_GAME);
  655. noble.sendPacket(sm);
  656. return false;
  657. }
  658. }
  659. }
  660. if (classBased && getNoblePoints(noble.getObjectId()) < 3)
  661. {
  662. noble.sendMessage("Cant register when you have less than 3 points");
  663. return false;
  664. }
  665. if (!classBased && getNoblePoints(noble.getObjectId()) < 5)
  666. {
  667. noble.sendMessage("Cant register when you have less than 5 points");
  668. return false;
  669. }
  670. if (classBased)
  671. {
  672. if (_classBasedRegisters.containsKey(noble.getClassId().getId()))
  673. {
  674. L2FastList<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  675. classed.add(noble);
  676. _classBasedRegisters.remove(noble.getClassId().getId());
  677. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  678. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
  679. noble.sendPacket(sm);
  680. }
  681. else
  682. {
  683. L2FastList<L2PcInstance> classed = new L2FastList<L2PcInstance>();
  684. classed.add(noble);
  685. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  686. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
  687. noble.sendPacket(sm);
  688. }
  689. }
  690. else
  691. {
  692. _nonClassBasedRegisters.add(noble);
  693. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_NO_CLASS_GAMES);
  694. noble.sendPacket(sm);
  695. }
  696. return true;
  697. }
  698. public boolean isRegistered(L2PcInstance noble)
  699. {
  700. if(_nonClassBasedRegisters == null) return false;
  701. if(_classBasedRegisters == null) return false;
  702. if (!_nonClassBasedRegisters.contains(noble))
  703. {
  704. if (!_classBasedRegisters.containsKey(noble.getClassId().getId()))
  705. {
  706. return false;
  707. }
  708. else
  709. {
  710. L2FastList<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  711. if (!classed.contains(noble))
  712. {
  713. return false;
  714. }
  715. }
  716. }
  717. return true;
  718. }
  719. public boolean unRegisterNoble(L2PcInstance noble)
  720. {
  721. SystemMessage sm;
  722. /*
  723. if (_compStarted)
  724. {
  725. noble.sendMessage("Cant Unregister whilst competition is under way");
  726. return false;
  727. }
  728. */
  729. if (!_inCompPeriod)
  730. {
  731. sm = new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  732. noble.sendPacket(sm);
  733. return false;
  734. }
  735. if (!noble.isNoble())
  736. {
  737. sm = new SystemMessage(SystemMessageId.ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
  738. noble.sendPacket(sm);
  739. return false;
  740. }
  741. if (!isRegistered(noble))
  742. {
  743. sm = new SystemMessage(SystemMessageId.YOU_HAVE_NOT_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_A_GAME);
  744. noble.sendPacket(sm);
  745. return false;
  746. }
  747. if (_nonClassBasedRegisters.contains(noble))
  748. _nonClassBasedRegisters.remove(noble);
  749. else
  750. {
  751. L2FastList<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  752. classed.remove(noble);
  753. _classBasedRegisters.remove(noble.getClassId().getId());
  754. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  755. }
  756. for(L2OlympiadGame game: _manager.getOlympiadGames().values())
  757. {
  758. if(game._playerOne.getObjectId() == noble.getObjectId() || game._playerTwo.getObjectId() == noble.getObjectId())
  759. {
  760. noble.sendMessage("Cant Unregister whilst you are already selected for a game");
  761. return false;
  762. }
  763. }
  764. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_DELETED_FROM_THE_WAITING_LIST_OF_A_GAME);
  765. noble.sendPacket(sm);
  766. return true;
  767. }
  768. public void removeDisconnectedCompetitor(L2PcInstance player)
  769. {
  770. if (_manager == null || (_manager.getOlympiadInstance(player.getOlympiadGameId()) == null)) return;
  771. _manager.getOlympiadInstance(player.getOlympiadGameId()).handleDisconnect(player);
  772. }
  773. private void updateCompStatus()
  774. {
  775. //_compStarted = false;
  776. synchronized(this)
  777. {
  778. long milliToStart = getMillisToCompBegin();
  779. double numSecs = (milliToStart / 1000) % 60;
  780. double countDown = ((milliToStart / 1000) - numSecs) / 60;
  781. int numMins = (int) Math.floor(countDown % 60);
  782. countDown = (countDown - numMins) / 60;
  783. int numHours = (int) Math.floor(countDown % 24);
  784. int numDays = (int) Math.floor((countDown - numHours) / 24);
  785. _log.info("Olympiad System: Competition Period Starts in "
  786. + numDays + " days, " + numHours
  787. + " hours and " + numMins + " mins.");
  788. _log.info("Olympiad System: Event starts/started : " + _compStart.getTime());
  789. }
  790. _scheduledCompStart = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  791. public void run()
  792. {
  793. if (isOlympiadEnd())
  794. return;
  795. _inCompPeriod = true;
  796. OlympiadManager om = new OlympiadManager();
  797. Announcements.getInstance().announceToAll(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_HAS_STARTED));
  798. _log.info("Olympiad System: Olympiad Game Started");
  799. Thread olyCycle = new Thread(om);
  800. olyCycle.start();
  801. //_scheduledManagerTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(om, INITIAL_WAIT, BATTLE_WAIT);
  802. _scheduledCompEnd = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  803. public void run()
  804. {
  805. if (isOlympiadEnd())
  806. return;
  807. //_scheduledManagerTask.cancel(true);
  808. _inCompPeriod = false;
  809. Announcements.getInstance().announceToAll(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_HAS_ENDED));
  810. _log.info("Olympiad System: Olympiad Game Ended");
  811. try {
  812. while(_battleStarted){
  813. try{
  814. //wait 1 minutes for end of pendings games
  815. Thread.sleep(60000);
  816. }catch (InterruptedException e){}
  817. }
  818. save();
  819. }
  820. catch (Exception e) {
  821. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  822. }
  823. init();
  824. }
  825. }, getMillisToCompEnd());
  826. }
  827. }, getMillisToCompBegin());
  828. }
  829. private long getMillisToOlympiadEnd()
  830. {
  831. //if (_olympiadEnd > Calendar.getInstance().getTimeInMillis())
  832. return (_olympiadEnd - Calendar.getInstance().getTimeInMillis());
  833. //return 10L;
  834. }
  835. public void manualSelectHeroes()
  836. {
  837. SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_ENDED);
  838. sm.addNumber(_currentCycle);
  839. Announcements.getInstance().announceToAll(sm);
  840. Announcements.getInstance().announceToAll("Olympiad Validation Period has began");
  841. _isOlympiadEnd = true;
  842. if (_scheduledManagerTask != null)
  843. _scheduledManagerTask.cancel(true);
  844. if (_scheduledWeeklyTask != null)
  845. _scheduledWeeklyTask.cancel(true);
  846. if(_scheduledOlympiadEnd != null)
  847. _scheduledOlympiadEnd.cancel(true);
  848. Calendar validationEnd = Calendar.getInstance();
  849. _validationEnd = validationEnd.getTimeInMillis() + VALIDATION_PERIOD;
  850. saveNobleData();
  851. _period = 1;
  852. sortHerosToBe();
  853. giveHeroBonus();
  854. Hero.getInstance().computeNewHeroes(_heroesToBe);
  855. try {
  856. save();
  857. }
  858. catch (Exception e) {
  859. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  860. }
  861. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  862. public void run()
  863. {
  864. Announcements.getInstance().announceToAll("Olympiad Validation Period has ended");
  865. _period = 0;
  866. _currentCycle++;
  867. deleteNobles();
  868. setNewOlympiadEnd();
  869. init();
  870. }
  871. }, getMillisToValidationEnd());
  872. }
  873. protected long getMillisToValidationEnd()
  874. {
  875. if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  876. return (_validationEnd - Calendar.getInstance().getTimeInMillis());
  877. return 10L;
  878. }
  879. public boolean isOlympiadEnd()
  880. {
  881. return _isOlympiadEnd;
  882. }
  883. protected void setNewOlympiadEnd()
  884. {
  885. SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
  886. sm.addNumber(_currentCycle);
  887. Announcements.getInstance().announceToAll(sm);
  888. Calendar currentTime = Calendar.getInstance();
  889. currentTime.add(Calendar.MONTH, 1);
  890. currentTime.set(Calendar.DAY_OF_MONTH, 1);
  891. currentTime.set(Calendar.AM_PM, Calendar.AM);
  892. currentTime.set(Calendar.HOUR, 12);
  893. currentTime.set(Calendar.MINUTE, 0);
  894. currentTime.set(Calendar.SECOND, 0);
  895. _olympiadEnd = currentTime.getTimeInMillis();
  896. Calendar nextChange = Calendar.getInstance();
  897. _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
  898. _isOlympiadEnd = false;
  899. }
  900. public boolean inCompPeriod()
  901. {
  902. return _inCompPeriod;
  903. }
  904. private long getMillisToCompBegin()
  905. {
  906. if (_compStart.getTimeInMillis() < Calendar.getInstance().getTimeInMillis() &&
  907. _compEnd > Calendar.getInstance().getTimeInMillis())
  908. return 10L;
  909. if (_compStart.getTimeInMillis() > Calendar.getInstance().getTimeInMillis())
  910. return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
  911. return setNewCompBegin();
  912. }
  913. private long setNewCompBegin()
  914. {
  915. _compStart = Calendar.getInstance();
  916. _compStart.set(Calendar.HOUR_OF_DAY, COMP_START);
  917. _compStart.set(Calendar.MINUTE, COMP_MIN);
  918. _compStart.add(Calendar.HOUR_OF_DAY, 24);
  919. _compEnd = _compStart.getTimeInMillis() + COMP_PERIOD;
  920. _log.info("Olympiad System: New Schedule @ " + _compStart.getTime());
  921. return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
  922. }
  923. protected long getMillisToCompEnd()
  924. {
  925. //if (_compEnd > Calendar.getInstance().getTimeInMillis())
  926. return (_compEnd - Calendar.getInstance().getTimeInMillis());
  927. //return 10L;
  928. }
  929. private long getMillisToWeekChange()
  930. {
  931. if (_nextWeeklyChange > Calendar.getInstance().getTimeInMillis())
  932. return (_nextWeeklyChange - Calendar.getInstance().getTimeInMillis());
  933. return 10L;
  934. }
  935. private void scheduleWeeklyChange()
  936. {
  937. _scheduledWeeklyTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable() {
  938. public void run()
  939. {
  940. addWeeklyPoints();
  941. _log.info("Olympiad System: Added weekly points to nobles");
  942. Calendar nextChange = Calendar.getInstance();
  943. _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
  944. }
  945. }, getMillisToWeekChange(), WEEKLY_PERIOD);
  946. }
  947. protected synchronized void addWeeklyPoints()
  948. {
  949. if (_period == 1)
  950. return;
  951. for (Integer nobleId : _nobles.keySet())
  952. {
  953. StatsSet nobleInfo = _nobles.get(nobleId);
  954. int currentPoints = nobleInfo.getInteger(POINTS);
  955. currentPoints += WEEKLY_POINTS;
  956. nobleInfo.set(POINTS, currentPoints);
  957. _nobles.remove(nobleId);
  958. _nobles.put(nobleId, nobleInfo);
  959. }
  960. }
  961. public String[] getMatchList()
  962. {
  963. return (_manager == null)? null : _manager.getAllTitles();
  964. }
  965. // returns the players for the given olympiad game Id
  966. public L2PcInstance[] getPlayers(int Id)
  967. {
  968. if (_manager == null || (_manager.getOlympiadInstance(Id) == null))
  969. {
  970. return null;
  971. }
  972. L2PcInstance[] players = _manager.getOlympiadInstance(Id).getPlayers();
  973. return players;
  974. }
  975. public int getCurrentCycle()
  976. {
  977. return _currentCycle;
  978. }
  979. public void addSpectator(int id, L2PcInstance spectator)
  980. {
  981. for(L2PcInstance player : _nonClassBasedRegisters)
  982. {
  983. if(spectator.getObjectId() == player.getObjectId())
  984. {
  985. spectator.sendMessage("You are already registered for a competition");
  986. return;
  987. }
  988. }
  989. for(L2FastList<L2PcInstance> list : _classBasedRegisters.values())
  990. {
  991. for(L2PcInstance player : list)
  992. {
  993. if(spectator.getObjectId() == player.getObjectId())
  994. {
  995. spectator.sendMessage("You are already registered for a competition");
  996. return;
  997. }
  998. }
  999. }
  1000. if(spectator.getOlympiadGameId() != -1)
  1001. {
  1002. spectator.sendMessage("You are already registered for a competition");
  1003. return;
  1004. }
  1005. if (_manager == null || (_manager.getOlympiadInstance(id) == null))
  1006. {
  1007. spectator.sendPacket(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS));
  1008. return;
  1009. }
  1010. L2PcInstance[] players = _manager.getOlympiadInstance(id).getPlayers();
  1011. if (players == null) return;
  1012. spectator.enterOlympiadObserverMode(STADIUMS[id].getCoordinates()[0], STADIUMS[id].getCoordinates()[1], STADIUMS[id].getCoordinates()[2], id);
  1013. _manager.getOlympiadInstance(id).addSpectator(spectator);
  1014. }
  1015. public void UnSpawnBuffer(L2Spawn spawn)
  1016. {
  1017. spawn.getLastSpawn().decayMe();
  1018. }
  1019. public void removeSpectator(int id, L2PcInstance spectator)
  1020. {
  1021. if (_manager == null || (_manager.getOlympiadInstance(id) == null)) return;
  1022. _manager.getOlympiadInstance(id).removeSpectator(spectator);
  1023. }
  1024. public L2FastList<L2PcInstance> getSpectators(int id)
  1025. {
  1026. if (_manager == null || _manager.getOlympiadInstance(id) == null)
  1027. return null;
  1028. return _manager.getOlympiadInstance(id).getSpectators();
  1029. }
  1030. public Map<Integer, L2OlympiadGame> getOlympiadGames()
  1031. {
  1032. return _manager.getOlympiadGames();
  1033. }
  1034. public boolean playerInStadia(L2PcInstance player)
  1035. {
  1036. return (OlympiadStadiaManager.getInstance().getStadium(player) != null);
  1037. }
  1038. public int[] getWaitingList()
  1039. {
  1040. int[] array = new int[2];
  1041. if (!inCompPeriod())
  1042. return null;
  1043. int classCount = 0;
  1044. if (_classBasedRegisters.size() != 0)
  1045. for (L2FastList<L2PcInstance> classed : _classBasedRegisters.values())
  1046. {
  1047. classCount += classed.size();
  1048. }
  1049. array[0] = classCount;
  1050. array[1] = _nonClassBasedRegisters.size();
  1051. return array;
  1052. }
  1053. protected synchronized void saveNobleData()
  1054. {
  1055. Connection con = null;
  1056. if (_nobles == null)
  1057. return;
  1058. try
  1059. {
  1060. con = L2DatabaseFactory.getInstance().getConnection();
  1061. PreparedStatement statement;
  1062. for (Integer nobleId : _nobles.keySet())
  1063. {
  1064. StatsSet nobleInfo = _nobles.get(nobleId);
  1065. int charId = nobleId;
  1066. int classId = nobleInfo.getInteger(CLASS_ID);
  1067. String charName = nobleInfo.getString(CHAR_NAME);
  1068. int points = nobleInfo.getInteger(POINTS);
  1069. int compDone = nobleInfo.getInteger(COMP_DONE);
  1070. boolean toSave = nobleInfo.getBool("to_save");
  1071. if (toSave)
  1072. {
  1073. statement = con.prepareStatement(OLYMPIAD_SAVE_NOBLES);
  1074. statement.setInt(1, charId);
  1075. statement.setInt(2, classId);
  1076. statement.setString(3, charName);
  1077. statement.setInt(4, points);
  1078. statement.setInt(5, compDone);
  1079. statement.execute();
  1080. statement.close();
  1081. nobleInfo.set("to_save", false);
  1082. _nobles.remove(nobleId);
  1083. _nobles.put(nobleId, nobleInfo);
  1084. }
  1085. else
  1086. {
  1087. statement = con.prepareStatement(OLYMPIAD_UPDATE_NOBLES);
  1088. statement.setInt(1, points);
  1089. statement.setInt(2, compDone);
  1090. statement.setInt(3, charId);
  1091. statement.execute();
  1092. statement.close();
  1093. }
  1094. }
  1095. }
  1096. catch(SQLException e) {_log.warning("Olympiad System: Couldnt save nobles info in db");}
  1097. finally
  1098. {
  1099. try{con.close();}catch(Exception e){e.printStackTrace();}
  1100. }
  1101. }
  1102. protected void sortHerosToBe()
  1103. {
  1104. if (_period != 1) return;
  1105. _heroesToBe = new L2FastList<StatsSet>();
  1106. Connection con = null;
  1107. try
  1108. {
  1109. con = L2DatabaseFactory.getInstance().getConnection();
  1110. PreparedStatement statement;
  1111. ResultSet rset;
  1112. StatsSet hero;
  1113. for (int i = 0; i < HERO_IDS.length; i++)
  1114. {
  1115. statement = con.prepareStatement(OLYMPIAD_GET_HEROS);
  1116. statement.setInt(1, HERO_IDS[i]);
  1117. rset = statement.executeQuery();
  1118. if (rset.next())
  1119. {
  1120. hero = new StatsSet();
  1121. hero.set(CLASS_ID, HERO_IDS[i]);
  1122. hero.set(CHAR_ID, rset.getInt(CHAR_ID));
  1123. hero.set(CHAR_NAME, rset.getString(CHAR_NAME));
  1124. _heroesToBe.add(hero);
  1125. }
  1126. statement.close();
  1127. rset.close();
  1128. }
  1129. }
  1130. catch(SQLException e){_log.warning("Olympiad System: Couldnt heros from db");}
  1131. finally
  1132. {
  1133. try{con.close();}catch(Exception e){e.printStackTrace();}
  1134. }
  1135. }
  1136. public L2FastList<String> getClassLeaderBoard(int classId)
  1137. {
  1138. //if (_period != 1) return;
  1139. L2FastList<String> names = new L2FastList<String>();
  1140. Connection con = null;
  1141. try
  1142. {
  1143. con = L2DatabaseFactory.getInstance().getConnection();
  1144. PreparedStatement statement;
  1145. ResultSet rset;
  1146. statement = con.prepareStatement(GET_EACH_CLASS_LEADER);
  1147. statement.setInt(1, classId);
  1148. rset = statement.executeQuery();
  1149. while (rset.next())
  1150. {
  1151. names.add(rset.getString(CHAR_NAME));
  1152. }
  1153. statement.close();
  1154. rset.close();
  1155. return names;
  1156. }
  1157. catch(SQLException e){_log.warning("Olympiad System: Couldnt heros from db");}
  1158. finally
  1159. {
  1160. try{con.close();}catch(Exception e){e.printStackTrace();}
  1161. }
  1162. return names;
  1163. }
  1164. protected void giveHeroBonus()
  1165. {
  1166. if (_heroesToBe.size() == 0)
  1167. return;
  1168. for (StatsSet hero : _heroesToBe)
  1169. {
  1170. int charId = hero.getInteger(CHAR_ID);
  1171. StatsSet noble = _nobles.get(charId);
  1172. int currentPoints = noble.getInteger(POINTS);
  1173. currentPoints += Config.ALT_OLY_HERO_POINTS;
  1174. noble.set(POINTS, currentPoints);
  1175. _nobles.remove(charId);
  1176. _nobles.put(charId, noble);
  1177. }
  1178. }
  1179. public int getNoblessePasses(int objId)
  1180. {
  1181. if (_period != 1 || _nobles.size() == 0)
  1182. return 0;
  1183. StatsSet noble = _nobles.get(objId);
  1184. if (noble == null)
  1185. return 0;
  1186. int points = noble.getInteger(POINTS);
  1187. if (points <= Config.ALT_OLY_MIN_POINT_FOR_EXCH)
  1188. return 0;
  1189. noble.set(POINTS, 0);
  1190. _nobles.remove(objId);
  1191. _nobles.put(objId, noble);
  1192. points *= Config.ALT_OLY_GP_PER_POINT;
  1193. return points;
  1194. }
  1195. public boolean isRegisteredInComp(L2PcInstance player)
  1196. {
  1197. boolean result = false;
  1198. if (_nonClassBasedRegisters != null && _nonClassBasedRegisters.contains(player))
  1199. result = true;
  1200. else if (_classBasedRegisters != null && _classBasedRegisters.containsKey(player.getClassId().getId()))
  1201. {
  1202. L2FastList<L2PcInstance> classed = _classBasedRegisters.get(player.getClassId().getId());
  1203. if (classed.contains(player))
  1204. result = true;
  1205. }
  1206. if (!_inCompPeriod){}
  1207. else {
  1208. for(L2OlympiadGame game: _manager.getOlympiadGames().values())
  1209. {
  1210. if(game._playerOne.getObjectId() == player.getObjectId() || game._playerTwo.getObjectId() == player.getObjectId())
  1211. {
  1212. result = true;
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. return result;
  1218. }
  1219. public int getNoblePoints(int objId)
  1220. {
  1221. if (_nobles.size() == 0)
  1222. return 0;
  1223. StatsSet noble = _nobles.get(objId);
  1224. if (noble == null)
  1225. return 0;
  1226. int points = noble.getInteger(POINTS);
  1227. return points;
  1228. }
  1229. public int getCompetitionDone(int objId)
  1230. {
  1231. if (_nobles.size() == 0)
  1232. return 0;
  1233. StatsSet noble = _nobles.get(objId);
  1234. if (noble == null)
  1235. return 0;
  1236. int points = noble.getInteger(COMP_DONE);
  1237. return points;
  1238. }
  1239. protected void deleteNobles()
  1240. {
  1241. Connection con = null;
  1242. try
  1243. {
  1244. con = L2DatabaseFactory.getInstance().getConnection();
  1245. PreparedStatement statement = con.prepareStatement(OLYMPIAD_DELETE_ALL);
  1246. statement.execute();
  1247. statement.close();
  1248. }
  1249. catch(SQLException e){_log.warning("Olympiad System: Couldnt delete nobles from db");}
  1250. finally
  1251. {
  1252. try{con.close();}catch(Exception e){e.printStackTrace();}
  1253. }
  1254. _nobles.clear();
  1255. }
  1256. public void save() throws IOException
  1257. {
  1258. saveNobleData();
  1259. Properties OlympiadProperties = new Properties();
  1260. FileOutputStream fos = new FileOutputStream(new File(Config.DATAPACK_ROOT, OLYMPIAD_DATA_FILE));
  1261. OlympiadProperties.setProperty("CurrentCycle", String.valueOf(_currentCycle));
  1262. OlympiadProperties.setProperty("Period", String.valueOf(_period));
  1263. OlympiadProperties.setProperty("OlympiadEnd", String.valueOf(_olympiadEnd));
  1264. OlympiadProperties.setProperty("ValdationEnd", String.valueOf(_validationEnd));
  1265. OlympiadProperties.setProperty("NextWeeklyChange", String.valueOf(_nextWeeklyChange));
  1266. OlympiadProperties.store(fos, "Olympiad Properties");
  1267. fos.close();
  1268. }
  1269. private class OlympiadManager implements Runnable
  1270. {
  1271. private Map<Integer, L2OlympiadGame> _olympiadInstances;
  1272. public OlympiadManager()
  1273. {
  1274. _olympiadInstances = new FastMap<Integer, L2OlympiadGame>();
  1275. _manager = this;
  1276. }
  1277. public synchronized void run()
  1278. {
  1279. _cycleTerminated = false;
  1280. if (isOlympiadEnd())
  1281. {
  1282. _scheduledManagerTask.cancel(true);
  1283. _cycleTerminated = true;
  1284. return;
  1285. }
  1286. Map<Integer, OlympiadGameTask> _gamesQueue = new FastMap<Integer, OlympiadGameTask>();
  1287. while(inCompPeriod())
  1288. {
  1289. if (_nobles.size() == 0)
  1290. {
  1291. try{
  1292. wait(60000);
  1293. }catch(InterruptedException ex){}
  1294. continue;
  1295. }
  1296. //_compStarted = true;
  1297. int classBasedPgCount = 0;
  1298. for(L2FastList<L2PcInstance> classList : _classBasedRegisters.values())
  1299. classBasedPgCount += classList.size();
  1300. while((_gamesQueue.size() > 0 || classBasedPgCount >= Config.ALT_OLY_CLASSED || _nonClassBasedRegisters.size() >= Config.ALT_OLY_NONCLASSED) && inCompPeriod())
  1301. {
  1302. //first cycle do nothing
  1303. int _gamesQueueSize = 0;
  1304. _gamesQueueSize = _gamesQueue.size();
  1305. for(int i=0; i<_gamesQueueSize;i++)
  1306. {
  1307. if(_gamesQueue.get(i) == null || _gamesQueue.get(i).isTerminated() || _gamesQueue.get(i)._game == null)
  1308. {
  1309. if(_gamesQueue.containsKey(i)) {
  1310. //removes terminated games from the queue
  1311. try {
  1312. _olympiadInstances.remove(i);
  1313. _gamesQueue.remove(i);
  1314. STADIUMS[i].setStadiaFree();
  1315. } catch(Exception e) {e.printStackTrace();}
  1316. } else {
  1317. _gamesQueueSize = _gamesQueueSize+1;
  1318. }
  1319. }else if(_gamesQueue.get(i) != null && !_gamesQueue.get(i).isStarted())
  1320. {
  1321. //start new games
  1322. Thread T = new Thread(_gamesQueue.get(i));
  1323. T.start();
  1324. }
  1325. }
  1326. //set up the games queue
  1327. for(int i=0; i<STADIUMS.length; i++)
  1328. {
  1329. if(!existNextOpponents(_nonClassBasedRegisters) && !existNextOpponents(getRandomClassList(_classBasedRegisters)))
  1330. {
  1331. break;
  1332. }
  1333. if(STADIUMS[i].isFreeToUse())
  1334. {
  1335. if (existNextOpponents(_nonClassBasedRegisters))
  1336. {
  1337. try{
  1338. _olympiadInstances.put(i, new L2OlympiadGame(i, COMP_TYPE.NON_CLASSED, nextOpponents(_nonClassBasedRegisters), STADIUMS[i].getCoordinates()));
  1339. _gamesQueue.put(i,new OlympiadGameTask(_olympiadInstances.get(i)));
  1340. STADIUMS[i].setStadiaBusy();
  1341. }catch(Exception ex)
  1342. {
  1343. if(_olympiadInstances.get(i) != null){
  1344. for(L2PcInstance player : _olympiadInstances.get(i).getPlayers())
  1345. {
  1346. player.sendMessage("Your olympiad registration was canceled due to an error");
  1347. player.setIsInOlympiadMode(false);
  1348. player.setIsOlympiadStart(false);
  1349. player.setOlympiadSide(-1);
  1350. player.setOlympiadGameId(-1);
  1351. }
  1352. _olympiadInstances.remove(i);
  1353. }
  1354. if(_gamesQueue.get(i)!= null)
  1355. _gamesQueue.remove(i);
  1356. STADIUMS[i].setStadiaFree();
  1357. //try to reuse this stadia next time
  1358. i--;
  1359. }
  1360. }
  1361. else if (existNextOpponents(getRandomClassList(_classBasedRegisters)))
  1362. {
  1363. try{
  1364. _olympiadInstances.put(i, new L2OlympiadGame(i, COMP_TYPE.CLASSED, nextOpponents(getRandomClassList(_classBasedRegisters)), STADIUMS[i].getCoordinates()));
  1365. _gamesQueue.put(i,new OlympiadGameTask(_olympiadInstances.get(i)));
  1366. STADIUMS[i].setStadiaBusy();
  1367. }catch(Exception ex)
  1368. {
  1369. if(_olympiadInstances.get(i) != null){
  1370. for(L2PcInstance player : _olympiadInstances.get(i).getPlayers())
  1371. {
  1372. player.sendMessage("Your olympiad registration was canceled due to an error");
  1373. player.setIsInOlympiadMode(false);
  1374. player.setIsOlympiadStart(false);
  1375. player.setOlympiadSide(-1);
  1376. player.setOlympiadGameId(-1);
  1377. }
  1378. _olympiadInstances.remove(i);
  1379. }
  1380. if(_gamesQueue.get(i)!= null)
  1381. _gamesQueue.remove(i);
  1382. STADIUMS[i].setStadiaFree();
  1383. //try to reuse this stadia next time
  1384. i--;
  1385. }
  1386. }
  1387. }
  1388. }
  1389. //wait 30 sec for !stress the server
  1390. try{
  1391. wait(30000);
  1392. }catch (InterruptedException e){}
  1393. }
  1394. //wait 30 sec for !stress the server
  1395. try{
  1396. wait(30000);
  1397. }catch (InterruptedException e){}
  1398. }
  1399. //when comp time finish wait for all games terminated before execute the cleanup code
  1400. boolean allGamesTerminated = false;
  1401. //wait for all games terminated
  1402. while(!allGamesTerminated)
  1403. {
  1404. try{
  1405. wait(30000);
  1406. }catch (InterruptedException e){}
  1407. if(_gamesQueue.size() == 0)
  1408. {
  1409. allGamesTerminated = true;
  1410. }else{
  1411. for(OlympiadGameTask game : _gamesQueue.values())
  1412. {
  1413. allGamesTerminated = allGamesTerminated || game.isTerminated();
  1414. }
  1415. }
  1416. }
  1417. _cycleTerminated = true;
  1418. //when all games terminated clear all
  1419. _gamesQueue.clear();
  1420. /*_classBasedParticipants.clear();
  1421. _nonClassBasedParticipants.clear();*/
  1422. //Wait 20 seconds
  1423. _olympiadInstances.clear();
  1424. _classBasedRegisters.clear();
  1425. _nonClassBasedRegisters.clear();
  1426. _battleStarted = false;
  1427. //_compStarted = false;
  1428. }
  1429. protected L2OlympiadGame getOlympiadInstance(int index)
  1430. {
  1431. if (_olympiadInstances != null && _olympiadInstances.size() > 0)
  1432. {
  1433. return _olympiadInstances.get(index);
  1434. }
  1435. return null;
  1436. }
  1437. protected Map<Integer, L2OlympiadGame> getOlympiadGames()
  1438. {
  1439. return (_olympiadInstances == null)? null : _olympiadInstances;
  1440. }
  1441. private L2FastList<L2PcInstance> getRandomClassList(Map<Integer, L2FastList<L2PcInstance>> list)
  1442. {
  1443. if(list.size() == 0)
  1444. return null;
  1445. Map<Integer, L2FastList<L2PcInstance>> tmp = new FastMap<Integer, L2FastList<L2PcInstance>>();
  1446. int tmpIndex = 0;
  1447. for(L2FastList<L2PcInstance> l : list.values())
  1448. {
  1449. tmp.put(tmpIndex, l);
  1450. tmpIndex ++;
  1451. }
  1452. L2FastList<L2PcInstance> rndList = new L2FastList<L2PcInstance>();
  1453. int classIndex = 0;
  1454. if(tmp.size() == 1)
  1455. classIndex = 0;
  1456. else
  1457. classIndex = Rnd.nextInt(tmp.size());
  1458. rndList = tmp.get(classIndex);
  1459. return rndList;
  1460. }
  1461. private L2FastList<L2PcInstance> nextOpponents(L2FastList<L2PcInstance> list)
  1462. {
  1463. L2FastList<L2PcInstance> opponents = new L2FastList<L2PcInstance>();
  1464. if (list.size() == 0)
  1465. return opponents;
  1466. int loopCount = (list.size() / 2);
  1467. int first;
  1468. int second;
  1469. if (loopCount < 1)
  1470. return opponents;
  1471. first = Rnd.nextInt(list.size());
  1472. opponents.add(list.get(first));
  1473. list.remove(first);
  1474. second = Rnd.nextInt(list.size());
  1475. opponents.add(list.get(second));
  1476. list.remove(second);
  1477. return opponents;
  1478. }
  1479. private boolean existNextOpponents(L2FastList<L2PcInstance> list)
  1480. {
  1481. if(list == null)
  1482. return false;
  1483. if (list.size() == 0)
  1484. return false;
  1485. int loopCount = list.size() >> 1;
  1486. if (loopCount < 1)
  1487. return false;
  1488. else
  1489. return true;
  1490. }
  1491. protected String[] getAllTitles()
  1492. {
  1493. /*if(!_compStarted)
  1494. return null;*/
  1495. String[] msg = new String[_olympiadInstances.size()];
  1496. int count = 0;
  1497. int match = 1;
  1498. int showbattle = 0;
  1499. for (L2OlympiadGame instance : _olympiadInstances.values())
  1500. {
  1501. if (instance._gamestarted == true) { showbattle = 1; } else { showbattle = 0; }
  1502. msg[count] = "<"+showbattle+"><"+instance._stadiumID+"> In Progress " + instance.getTitle();
  1503. count++;
  1504. match++;
  1505. }
  1506. return msg;
  1507. }
  1508. }
  1509. private class L2OlympiadGame
  1510. {
  1511. protected COMP_TYPE _type;
  1512. public boolean _aborted;
  1513. public boolean _gamestarted;
  1514. public boolean _playerOneDisconnected;
  1515. public boolean _playerTwoDisconnected;
  1516. public String _playerOneName;
  1517. public String _playerTwoName;
  1518. public int _playerOneID = 0;
  1519. public int _playerTwoID = 0;
  1520. public int OLY_BUFFER = 36402;
  1521. public L2PcInstance _playerOne;
  1522. public L2PcInstance _playerTwo;
  1523. public L2Spawn _spawnOne;
  1524. public L2Spawn _spawnTwo;
  1525. private L2FastList<L2PcInstance> _players;
  1526. private int[] _stadiumPort;
  1527. private int x1, y1, z1, x2, y2, z2;
  1528. public int _stadiumID;
  1529. public L2FastList<L2PcInstance> _spectators;
  1530. private SystemMessage _sm;
  1531. private SystemMessage _sm2;
  1532. private SystemMessage _sm3;
  1533. protected L2OlympiadGame(int id, COMP_TYPE type, L2FastList<L2PcInstance> list, int[] stadiumPort)
  1534. {
  1535. _aborted = false;
  1536. _gamestarted = false;
  1537. _stadiumID = id;
  1538. _playerOneDisconnected = false;
  1539. _playerTwoDisconnected = false;
  1540. _type = type;
  1541. _stadiumPort = stadiumPort;
  1542. _spectators = new L2FastList<L2PcInstance>();
  1543. if (list != null)
  1544. {
  1545. _players = list;
  1546. _playerOne = list.get(0);
  1547. _playerTwo = list.get(1);
  1548. try {
  1549. _playerOneName = _playerOne.getName();
  1550. _playerTwoName = _playerTwo.getName();
  1551. _playerOne.setOlympiadGameId(id);
  1552. _playerTwo.setOlympiadGameId(id);
  1553. _playerOneID = _playerOne.getObjectId();
  1554. _playerTwoID = _playerTwo.getObjectId();
  1555. }
  1556. catch (Exception e) {
  1557. _aborted = true;
  1558. clearPlayers();
  1559. }
  1560. if (Config.DEBUG)
  1561. _log.info("Olympiad System: Game - " + id + ": " + _playerOne.getName() + " Vs " + _playerTwo.getName());
  1562. }
  1563. else {
  1564. _aborted = true;
  1565. clearPlayers();
  1566. return;
  1567. }
  1568. }
  1569. public boolean isAborted()
  1570. {
  1571. return _aborted;
  1572. }
  1573. protected void clearPlayers()
  1574. {
  1575. _playerOne = null;
  1576. _playerTwo = null;
  1577. _players = null;
  1578. _playerOneName = "";
  1579. _playerTwoName = "";
  1580. _playerOneID = 0;
  1581. _playerTwoID = 0;
  1582. }
  1583. protected void handleDisconnect(L2PcInstance player)
  1584. {
  1585. if (player == _playerOne)
  1586. _playerOneDisconnected = true;
  1587. else if (player == _playerTwo)
  1588. _playerTwoDisconnected = true;
  1589. }
  1590. public void openDoors()
  1591. {
  1592. _doorTable = DoorTable.getInstance();
  1593. try {
  1594. _doorTable.getDoor(STADIUMS[_stadiumID].getDoorID()[0]).openMe();
  1595. _doorTable.getDoor(STADIUMS[_stadiumID].getDoorID()[1]).openMe();
  1596. //_log.info("open doors"+STADIUMS[_stadiumID].getDoorID()[0]+"<>"+STADIUMS[_stadiumID].getDoorID()[1]);
  1597. } catch (Exception e) {}
  1598. }
  1599. public void closeDoors()
  1600. {
  1601. _doorTable = DoorTable.getInstance();
  1602. try {
  1603. _doorTable.getDoor(STADIUMS[_stadiumID].getDoorID()[0]).closeMe();
  1604. _doorTable.getDoor(STADIUMS[_stadiumID].getDoorID()[1]).closeMe();
  1605. //_log.info("close doors"+STADIUMS[_stadiumID].getDoorID()[0]+"<>"+STADIUMS[_stadiumID].getDoorID()[1]);
  1606. } catch (Exception e) {}
  1607. }
  1608. public L2Spawn SpawnBuffer(int xPos, int yPos, int zPos, int npcId)
  1609. {
  1610. L2NpcTemplate template;
  1611. template = NpcTable.getInstance().getTemplate(npcId);
  1612. try {
  1613. L2Spawn spawn = new L2Spawn(template);
  1614. spawn.setLocx(xPos);
  1615. spawn.setLocy(yPos);
  1616. spawn.setLocz(zPos);
  1617. spawn.setAmount(1);
  1618. spawn.setHeading(0);
  1619. spawn.setRespawnDelay(1);
  1620. SpawnTable.getInstance().addNewSpawn(spawn, false);
  1621. spawn.init();
  1622. return spawn;
  1623. } catch (Exception e) { return null; }
  1624. }
  1625. protected void removals()
  1626. {
  1627. if (_aborted) return;
  1628. if (_playerOne == null || _playerTwo == null) return;
  1629. if (_playerOneDisconnected || _playerTwoDisconnected) return;
  1630. for (L2PcInstance player : _players)
  1631. {
  1632. try{
  1633. //Remove Clan Skills
  1634. if (player.getClan() != null)
  1635. {
  1636. for(L2Skill skill: player.getClan().getAllSkills())
  1637. player.removeSkill(skill,false);
  1638. }
  1639. //Abort casting if player casting
  1640. if (player.isCastingNow())
  1641. {
  1642. player.abortCast();
  1643. }
  1644. //Remove Hero Skills
  1645. if (player.isHero())
  1646. {
  1647. for(L2Skill skill: HeroSkillTable.getHeroSkills())
  1648. player.removeSkill(skill,false);
  1649. }
  1650. // Heal Player fully
  1651. player.setCurrentCp(player.getMaxCp());
  1652. player.setCurrentHp(player.getMaxHp());
  1653. player.setCurrentMp(player.getMaxMp());
  1654. //Remove Buffs
  1655. player.stopAllEffects();
  1656. //Remove Summon's Buffs
  1657. if (player.getPet() != null)
  1658. {
  1659. L2Summon summon = player.getPet();
  1660. summon.stopAllEffects();
  1661. if (summon instanceof L2PetInstance)
  1662. summon.unSummon(player);
  1663. }
  1664. /*if (player.getCubics() != null)
  1665. {
  1666. for(L2CubicInstance cubic : player.getCubics().values())
  1667. {
  1668. cubic.stopAction();
  1669. player.delCubic(cubic.getId());
  1670. }
  1671. player.getCubics().clear();
  1672. }*/
  1673. //Remove player from his party
  1674. if (player.getParty() != null)
  1675. {
  1676. L2Party party = player.getParty();
  1677. party.removePartyMember(player);
  1678. }
  1679. //Remove Hero Weapons
  1680. // check to prevent the using of weapon/shield on strider/wyvern
  1681. L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1682. if (wpn == null) wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  1683. if (wpn != null && (wpn.isHeroItem() || wpn.isOlyRestrictedItem()))
  1684. {
  1685. L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  1686. InventoryUpdate iu = new InventoryUpdate();
  1687. for (int i = 0; i < unequiped.length; i++)
  1688. iu.addModifiedItem(unequiped[i]);
  1689. player.sendPacket(iu);
  1690. player.abortAttack();
  1691. player.broadcastUserInfo();
  1692. // this can be 0 if the user pressed the right mouse button twice very fast
  1693. if (unequiped.length > 0)
  1694. {
  1695. if (unequiped[0].isWear())
  1696. return;
  1697. SystemMessage sm = null;
  1698. if (unequiped[0].getEnchantLevel() > 0){
  1699. sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  1700. sm.addNumber(unequiped[0].getEnchantLevel());
  1701. sm.addItemName(unequiped[0]);
  1702. }else{
  1703. sm = new SystemMessage(SystemMessageId.S1_DISARMED);
  1704. sm.addItemName(unequiped[0]);
  1705. }
  1706. player.sendPacket(sm);
  1707. }
  1708. }
  1709. //Remove shot automation
  1710. Map<Integer, Integer> activeSoulShots = player.getAutoSoulShot();
  1711. for (int itemId : activeSoulShots.values())
  1712. {
  1713. player.removeAutoSoulShot(itemId);
  1714. ExAutoSoulShot atk = new ExAutoSoulShot(itemId, 0);
  1715. player.sendPacket(atk);
  1716. }
  1717. player.sendSkillList();
  1718. }
  1719. catch (Exception e) {}
  1720. }
  1721. }
  1722. protected boolean portPlayersToArena()
  1723. {
  1724. boolean _playerOneCrash = (_playerOne == null || _playerOneDisconnected);
  1725. boolean _playerTwoCrash = (_playerTwo == null || _playerTwoDisconnected);
  1726. if (_playerOneCrash || _playerTwoCrash || _aborted)
  1727. {
  1728. _playerOne=null;
  1729. _playerTwo=null;
  1730. _aborted = true;
  1731. return false;
  1732. }
  1733. try {
  1734. x1 = _playerOne.getX();
  1735. y1 = _playerOne.getY();
  1736. z1 = _playerOne.getZ();
  1737. x2 = _playerTwo.getX();
  1738. y2 = _playerTwo.getY();
  1739. z2 = _playerTwo.getZ();
  1740. if (_playerOne.isSitting())
  1741. _playerOne.standUp();
  1742. if (_playerTwo.isSitting())
  1743. _playerTwo.standUp();
  1744. _playerOne.setTarget(null);
  1745. _playerTwo.setTarget(null);
  1746. _playerOne.teleToLocation(_stadiumPort[0]+1200, _stadiumPort[1], _stadiumPort[2], false);
  1747. _playerTwo.teleToLocation(_stadiumPort[0]-1200, _stadiumPort[1], _stadiumPort[2], false);
  1748. _playerOne.sendPacket(new ExOlympiadMode(2));
  1749. _playerTwo.sendPacket(new ExOlympiadMode(2));
  1750. _spawnOne = SpawnBuffer(_stadiumPort[0]+1100, _stadiumPort[1], _stadiumPort[2], OLY_BUFFER);
  1751. _spawnTwo = SpawnBuffer(_stadiumPort[0]-1100, _stadiumPort[1], _stadiumPort[2], OLY_BUFFER);
  1752. _playerOne.setIsInOlympiadMode(true);
  1753. _playerOne.setIsOlympiadStart(false);
  1754. _playerOne.setOlympiadSide(1);
  1755. _playerOne.olyBuff = 5;
  1756. _playerTwo.setIsInOlympiadMode(true);
  1757. _playerTwo.setIsOlympiadStart(false);
  1758. _playerTwo.setOlympiadSide(2);
  1759. _playerTwo.olyBuff = 5;
  1760. _gamestarted = true;
  1761. } catch (NullPointerException e)
  1762. {
  1763. return false;
  1764. }
  1765. return true;
  1766. }
  1767. protected void sendMessageToPlayers(boolean toBattleBegin, int nsecond)
  1768. {
  1769. if(!toBattleBegin)
  1770. _sm = new SystemMessage(SystemMessageId.YOU_WILL_ENTER_THE_OLYMPIAD_STADIUM_IN_S1_SECOND_S);
  1771. else
  1772. _sm = new SystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
  1773. _sm.addNumber(nsecond);
  1774. try {
  1775. for (L2PcInstance player : _players)
  1776. player.sendPacket(_sm);
  1777. } catch (Exception e) {};
  1778. }
  1779. protected void portPlayersBack()
  1780. {
  1781. _playerOne.teleToLocation(x1, y1, z1, true);
  1782. _playerTwo.teleToLocation(x2, y2, z2, true);
  1783. }
  1784. protected void PlayersStatusBack()
  1785. {
  1786. for (L2PcInstance player : _players)
  1787. {
  1788. try {
  1789. if(player.isDead() == true) { player.setIsDead(false); }
  1790. player.getStatus().startHpMpRegeneration();
  1791. player.setCurrentCp(player.getMaxCp());
  1792. player.setCurrentHp(player.getMaxHp());
  1793. player.setCurrentMp(player.getMaxMp());
  1794. player.setIsInOlympiadMode(false);
  1795. player.setIsOlympiadStart(false);
  1796. player.setOlympiadSide(-1);
  1797. player.setOlympiadGameId(-1);
  1798. player.sendPacket(new ExOlympiadMode(0));
  1799. //Add Clan Skills
  1800. if (player.getClan() != null)
  1801. {
  1802. for(L2Skill skill: player.getClan().getAllSkills())
  1803. {
  1804. if ( skill.getMinPledgeClass() <= player.getPledgeClass() )
  1805. player.addSkill(skill,false);
  1806. }
  1807. }
  1808. //Add Hero Skills
  1809. if (player.isHero())
  1810. {
  1811. for(L2Skill skill: HeroSkillTable.getHeroSkills())
  1812. player.addSkill(skill,false);
  1813. }
  1814. player.sendSkillList();
  1815. } catch (Exception e) {}
  1816. }
  1817. }
  1818. protected boolean haveWinner()
  1819. {
  1820. boolean retval = false;
  1821. if (_aborted || _playerOne == null || _playerTwo == null)
  1822. {
  1823. return true;
  1824. }
  1825. double playerOneHp = 0;
  1826. try{
  1827. if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  1828. {
  1829. playerOneHp = _playerOne.getCurrentHp();
  1830. }
  1831. }catch (Exception e){
  1832. playerOneHp = 0;
  1833. }
  1834. double playerTwoHp = 0;
  1835. try{
  1836. if (_playerTwo != null && _playerTwo.getOlympiadGameId()!=-1)
  1837. {
  1838. playerTwoHp = _playerTwo.getCurrentHp();
  1839. }
  1840. }catch (Exception e){
  1841. playerTwoHp = 0;
  1842. }
  1843. if (playerTwoHp==0 || playerOneHp==0)
  1844. {
  1845. return true;
  1846. }
  1847. return retval;
  1848. }
  1849. protected void validateWinner()
  1850. {
  1851. if (_aborted || _playerOne == null || _playerTwo == null || _playerOneDisconnected || _playerTwoDisconnected)
  1852. {
  1853. return;
  1854. }
  1855. StatsSet playerOneStat;
  1856. StatsSet playerTwoStat;
  1857. playerOneStat = _nobles.get(_playerOneID);
  1858. playerTwoStat = _nobles.get(_playerTwoID);
  1859. int _div;
  1860. int _gpreward;
  1861. int playerOnePlayed = playerOneStat.getInteger(COMP_DONE);
  1862. int playerTwoPlayed = playerTwoStat.getInteger(COMP_DONE);
  1863. int playerOnePoints = playerOneStat.getInteger(POINTS);
  1864. int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  1865. double playerOneHp = 0;
  1866. try
  1867. {
  1868. if (_playerOne != null && !_playerOneDisconnected)
  1869. {
  1870. if (!_playerOne.isDead())
  1871. {
  1872. playerOneHp = _playerOne.getCurrentHp()+_playerOne.getCurrentCp();
  1873. }
  1874. }
  1875. }
  1876. catch (Exception e)
  1877. {
  1878. playerOneHp = 0;
  1879. }
  1880. double playerTwoHp = 0;
  1881. try
  1882. {
  1883. if (_playerTwo != null && !_playerTwoDisconnected)
  1884. {
  1885. if (!_playerTwo.isDead())
  1886. {
  1887. playerTwoHp = _playerTwo.getCurrentHp()+_playerTwo.getCurrentCp();
  1888. }
  1889. }
  1890. }
  1891. catch (Exception e)
  1892. {
  1893. playerTwoHp = 0;
  1894. }
  1895. _sm = new SystemMessage(SystemMessageId.C1_HAS_WON_THE_GAME);
  1896. _sm2 = new SystemMessage(SystemMessageId.S1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  1897. _sm3 = new SystemMessage(SystemMessageId.S1_HAS_LOST_S2_OLYMPIAD_POINTS);
  1898. String result = "";
  1899. // if players crashed, search if they've relogged
  1900. _playerOne = L2World.getInstance().getPlayer(_playerOneName);
  1901. _players.set(0, _playerOne);
  1902. _playerTwo = L2World.getInstance().getPlayer(_playerTwoName);
  1903. _players.set(1, _playerTwo);
  1904. switch(_type){
  1905. case NON_CLASSED: _div=5; _gpreward=Config.ALT_OLY_NONCLASSED_RITEM_C; break;
  1906. default: _div=3; _gpreward=Config.ALT_OLY_CLASSED_RITEM_C; break;
  1907. }
  1908. if (_playerTwo.isOnline() == 0 || (playerTwoHp == 0 && playerOneHp != 0) || (_playerOne.dmgDealt > _playerTwo.dmgDealt && playerTwoHp != 0 && playerOneHp != 0))
  1909. {
  1910. int pointDiff;
  1911. pointDiff = playerTwoPoints / _div;
  1912. playerOneStat.set(POINTS, playerOnePoints + pointDiff);
  1913. playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  1914. _sm.addString(_playerOneName);
  1915. broadcastMessage(_sm, true);
  1916. _sm2.addString(_playerOneName);
  1917. _sm2.addNumber(pointDiff);
  1918. broadcastMessage(_sm2, true);
  1919. _sm3.addString(_playerTwoName);
  1920. _sm3.addNumber(pointDiff);
  1921. broadcastMessage(_sm3, true);
  1922. try {
  1923. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+_playerOne.dmgDealt+"dmg vs "+_playerTwo.dmgDealt+"dmg) "+_playerOneName+" win "+pointDiff+" points";
  1924. L2ItemInstance item = _playerOne.getInventory().addItem("Olympiad", Config.ALT_OLY_BATTLE_REWARD_ITEM, _gpreward, _playerOne, null);
  1925. InventoryUpdate iu = new InventoryUpdate();
  1926. iu.addModifiedItem(item);
  1927. _playerOne.sendPacket(iu);
  1928. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1929. sm.addItemName(item);
  1930. sm.addNumber(_gpreward);
  1931. _playerOne.sendPacket(sm);
  1932. } catch (Exception e) { }
  1933. }
  1934. else if (_playerOne.isOnline() == 0 || (playerOneHp == 0 && playerTwoHp != 0) || (_playerTwo.dmgDealt > _playerOne.dmgDealt && playerOneHp != 0 && playerTwoHp != 0))
  1935. {
  1936. int pointDiff;
  1937. pointDiff = playerOnePoints / _div;
  1938. playerTwoStat.set(POINTS, playerTwoPoints + pointDiff);
  1939. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  1940. _sm.addString(_playerTwoName);
  1941. broadcastMessage(_sm, true);
  1942. _sm2.addString(_playerTwoName);
  1943. _sm2.addNumber(pointDiff);
  1944. broadcastMessage(_sm2, true);
  1945. _sm3.addString(_playerOneName);
  1946. _sm3.addNumber(pointDiff);
  1947. broadcastMessage(_sm3, true);
  1948. try {
  1949. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+_playerOne.dmgDealt+"dmg vs "+_playerTwo.dmgDealt+"dmg) "+_playerTwoName+" win "+pointDiff+" points";
  1950. L2ItemInstance item = _playerTwo.getInventory().addItem("Olympiad", Config.ALT_OLY_BATTLE_REWARD_ITEM, _gpreward, _playerTwo, null);
  1951. InventoryUpdate iu = new InventoryUpdate();
  1952. iu.addModifiedItem(item);
  1953. _playerTwo.sendPacket(iu);
  1954. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1955. sm.addItemName(item);
  1956. sm.addNumber(_gpreward);
  1957. _playerTwo.sendPacket(sm);
  1958. } catch (Exception e) { }
  1959. }
  1960. else
  1961. {
  1962. result=" tie";
  1963. _sm = new SystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
  1964. broadcastMessage(_sm, true);
  1965. }
  1966. if (Config.DEBUG)
  1967. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... "+result);
  1968. playerOneStat.set(COMP_DONE, playerOnePlayed + 1);
  1969. playerTwoStat.set(COMP_DONE, playerTwoPlayed + 1);
  1970. _nobles.remove(_playerOneID);
  1971. _nobles.remove(_playerTwoID);
  1972. _nobles.put(_playerOneID, playerOneStat);
  1973. _nobles.put(_playerTwoID, playerTwoStat);
  1974. for (int i=40;i>10;i-=10)
  1975. {
  1976. _sm = new SystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_TOWN_IN_S1_SECONDS);
  1977. _sm.addNumber(i);
  1978. broadcastMessage(_sm, false);
  1979. try{ Thread.sleep(10000); }catch (InterruptedException e){}
  1980. if (i==20) {
  1981. _sm = new SystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_TOWN_IN_S1_SECONDS);
  1982. _sm.addNumber(10);
  1983. broadcastMessage(_sm, false);
  1984. try{ Thread.sleep(5000); }catch (InterruptedException e){}
  1985. }
  1986. }
  1987. for (int i=5;i>0;i--)
  1988. {
  1989. _sm = new SystemMessage(SystemMessageId.YOU_WILL_BE_MOVED_TO_TOWN_IN_S1_SECONDS);
  1990. _sm.addNumber(i);
  1991. broadcastMessage(_sm, false);
  1992. try{ Thread.sleep(1000); }catch (InterruptedException e){}
  1993. }
  1994. }
  1995. protected void additions()
  1996. {
  1997. for (L2PcInstance player : _players)
  1998. {
  1999. try {
  2000. //Set HP/CP/MP to Max
  2001. player.setCurrentCp(player.getMaxCp());
  2002. player.setCurrentHp(player.getMaxHp());
  2003. player.setCurrentMp(player.getMaxMp());
  2004. player.dmgDealt = 0;
  2005. } catch (Exception e) { }
  2006. }
  2007. }
  2008. protected boolean makePlayersVisible()
  2009. {
  2010. _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  2011. try {
  2012. for (L2PcInstance player : _players)
  2013. {
  2014. player.getAppearance().setVisible();
  2015. player.broadcastUserInfo();
  2016. player.sendPacket(_sm);
  2017. if (player.getPet() != null)
  2018. player.getPet().updateAbnormalEffect();
  2019. }
  2020. } catch (NullPointerException e) { _aborted = true; return false; }
  2021. return true;
  2022. }
  2023. protected boolean makeCompetitionStart()
  2024. {
  2025. if (_aborted) return false;
  2026. _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  2027. broadcastMessage(_sm, true);
  2028. try {
  2029. for (L2PcInstance player : _players)
  2030. {
  2031. player.setIsOlympiadStart(true);
  2032. }
  2033. } catch (Exception e) {
  2034. _aborted = true;
  2035. return false;
  2036. }
  2037. return true;
  2038. }
  2039. protected String getTitle()
  2040. {
  2041. String msg = "";
  2042. msg+= _playerOneName + " : " + _playerTwoName;
  2043. return msg;
  2044. }
  2045. protected L2PcInstance[] getPlayers()
  2046. {
  2047. L2PcInstance[] players = new L2PcInstance[2];
  2048. if (_playerOne == null || _playerTwo == null) return null;
  2049. players[0] = _playerOne;
  2050. players[1] = _playerTwo;
  2051. return players;
  2052. }
  2053. protected L2FastList<L2PcInstance> getSpectators()
  2054. {
  2055. return _spectators;
  2056. }
  2057. protected void addSpectator(L2PcInstance spec)
  2058. {
  2059. _spectators.add(spec);
  2060. }
  2061. protected void removeSpectator(L2PcInstance spec)
  2062. {
  2063. if (_spectators != null && _spectators.contains(spec))
  2064. _spectators.remove(spec);
  2065. }
  2066. protected void clearSpectators()
  2067. {
  2068. if (_spectators != null)
  2069. {
  2070. for (L2PcInstance pc : _spectators)
  2071. {
  2072. try {
  2073. if(!pc.inObserverMode()) continue;
  2074. pc.leaveOlympiadObserverMode();
  2075. } catch (NullPointerException e) {}
  2076. }
  2077. _spectators.clear();
  2078. }
  2079. }
  2080. private void broadcastMessage(SystemMessage sm, boolean toAll)
  2081. {
  2082. try {
  2083. _playerOne.sendPacket(sm);
  2084. _playerTwo.sendPacket(sm);
  2085. } catch (Exception e) {}
  2086. if (toAll && _spectators != null)
  2087. {
  2088. for (L2PcInstance spec : _spectators)
  2089. {
  2090. try { spec.sendPacket(sm); } catch (NullPointerException e) {}
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }