Olympiad.java 83 KB

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