Olympiad.java 82 KB

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