Olympiad.java 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. /**
  20. * @author godson
  21. */
  22. package net.sf.l2j.gameserver;
  23. import java.io.File;
  24. import java.io.FileInputStream;
  25. import java.io.FileOutputStream;
  26. import java.io.IOException;
  27. import java.io.InputStream;
  28. import java.sql.Connection;
  29. import java.sql.PreparedStatement;
  30. import java.sql.ResultSet;
  31. import java.sql.SQLException;
  32. import java.util.Calendar;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.Properties;
  36. import java.util.concurrent.ScheduledFuture;
  37. import java.util.logging.Logger;
  38. import javolution.util.FastList;
  39. import javolution.util.FastMap;
  40. import net.sf.l2j.Config;
  41. import net.sf.l2j.L2DatabaseFactory;
  42. import net.sf.l2j.gameserver.datatables.HeroSkillTable;
  43. import net.sf.l2j.gameserver.datatables.SkillTable;
  44. import net.sf.l2j.gameserver.instancemanager.OlympiadStadiaManager;
  45. import net.sf.l2j.gameserver.model.Inventory;
  46. import net.sf.l2j.gameserver.model.L2ItemInstance;
  47. import net.sf.l2j.gameserver.model.L2Party;
  48. import net.sf.l2j.gameserver.model.L2Skill;
  49. import net.sf.l2j.gameserver.model.L2Summon;
  50. import net.sf.l2j.gameserver.model.L2World;
  51. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  52. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  53. import net.sf.l2j.gameserver.model.entity.Hero;
  54. import net.sf.l2j.gameserver.network.SystemMessageId;
  55. import net.sf.l2j.gameserver.serverpackets.ExOlympiadUserInfoSpectator;
  56. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  57. import net.sf.l2j.gameserver.serverpackets.MagicSkillUse;
  58. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  59. import net.sf.l2j.gameserver.templates.StatsSet;
  60. import net.sf.l2j.util.Rnd;
  61. public class Olympiad
  62. {
  63. protected static final Logger _log = Logger.getLogger(Olympiad.class.getName());
  64. private static Olympiad _instance;
  65. protected static Map<Integer, StatsSet> _nobles;
  66. protected static List<StatsSet> _heroesToBe;
  67. protected static List<L2PcInstance> _nonClassBasedRegisters;
  68. protected static Map<Integer, List<L2PcInstance>> _classBasedRegisters;
  69. private static final String OLYMPIAD_DATA_FILE = "config/olympiad.properties";
  70. public static final String OLYMPIAD_HTML_FILE = "data/html/olympiad/";
  71. private static final String OLYMPIAD_LOAD_NOBLES = "SELECT * from olympiad_nobles";
  72. private static final String OLYMPIAD_SAVE_NOBLES = "INSERT INTO olympiad_nobles " +
  73. "values (?,?,?,?,?)";
  74. private static final String OLYMPIAD_UPDATE_NOBLES = "UPDATE olympiad_nobles set " +
  75. "olympiad_points = ?, competitions_done = ? where char_id = ?";
  76. private static final String OLYMPIAD_GET_HEROS = "SELECT char_id, char_name from " +
  77. "olympiad_nobles where class_id = ? and competitions_done >= 9 order by " +
  78. "olympiad_points desc, competitions_done desc";
  79. private static final String GET_EACH_CLASS_LEADER = "SELECT char_name from " +
  80. "olympiad_nobles where class_id = ? order by olympiad_points desc, " +
  81. "competitions_done desc";
  82. private static final String OLYMPIAD_DELETE_ALL = "DELETE from olympiad_nobles";
  83. private static final int COMP_START = Config.ALT_OLY_START_TIME; // 6PM
  84. private static final int COMP_MIN = Config.ALT_OLY_MIN; // 00 mins
  85. private static final long COMP_PERIOD = Config.ALT_OLY_CPERIOD; // 6 hours
  86. protected static final long BATTLE_PERIOD = Config.ALT_OLY_BATTLE; // 6 mins
  87. protected static final long BATTLE_WAIT = Config.ALT_OLY_BWAIT; // 10mins
  88. protected static final long INITIAL_WAIT = Config.ALT_OLY_IWAIT; // 5mins
  89. protected static final long WEEKLY_PERIOD = Config.ALT_OLY_WPERIOD; // 1 week
  90. protected static final long VALIDATION_PERIOD = Config.ALT_OLY_VPERIOD; // 24 hours
  91. /* FOR TESTING
  92. private static final int COMP_START = 8; // 1PM - 2PM
  93. private static final int COMP_MIN = 15; // 20mins
  94. private static final long COMP_PERIOD = 7200000; // 2hours
  95. private static final long BATTLE_PERIOD = 180000; // 3mins
  96. private static final long BATTLE_WAIT = 600000; // 10mins
  97. private static final long INITIAL_WAIT = 300000; // 5mins
  98. private static final long WEEKLY_PERIOD = 7200000; // 2 hours
  99. private static final long VALIDATION_PERIOD = 3600000; // 1 hour */
  100. private static final int COLLISIEUMS = 11; // 22 in all, 11 each for (Classed and NonClassed)
  101. private static final int DEFAULT_POINTS = 18;
  102. protected static final int WEEKLY_POINTS = 3;
  103. public static final String CHAR_ID = "char_id";
  104. public static final String CLASS_ID = "class_id";
  105. public static final String CHAR_NAME = "char_name";
  106. public static final String POINTS = "olympiad_points";
  107. public static final String COMP_DONE = "competitions_done";
  108. protected long _olympiadEnd;
  109. protected long _validationEnd;
  110. protected int _period;
  111. protected long _nextWeeklyChange;
  112. protected int _currentCycle;
  113. private long _compEnd;
  114. private Calendar _compStart;
  115. protected static boolean _inCompPeriod;
  116. protected static boolean _isOlympiadEnd;
  117. protected static boolean _compStarted;
  118. protected static boolean _battleStarted;
  119. protected ScheduledFuture<?> _scheduledCompStart;
  120. protected ScheduledFuture<?> _scheduledCompEnd;
  121. protected ScheduledFuture<?> _scheduledOlympiadEnd;
  122. protected ScheduledFuture<?> _scheduledManagerTask;
  123. protected ScheduledFuture<?> _scheduledWeeklyTask;
  124. protected ScheduledFuture<?> _scheduledValdationTask;
  125. protected static final int[][] STADIUMS =
  126. {
  127. {-20814, -21189, -3030},
  128. {-120324, -225077, -3331},
  129. {-102495, -209023, -3331},
  130. {-120156, -207378, -3331},
  131. {-87628, -225021, -3331},
  132. {-81705, -213209, -3331},
  133. {-87593, -207339, -3331},
  134. {-93709, -218304, -3331},
  135. {-77157, -218608, -3331},
  136. {-69682, -209027, -3331},
  137. {-76887, -201256, -3331},
  138. {-109985, -218701, -3331},
  139. {-126367, -218228, -3331},
  140. {-109629, -201292, -3331},
  141. {-87523, -240169, -3331},
  142. {-81748, -245950, -3331},
  143. {-77123, -251473, -3331},
  144. {-69778, -241801, -3331},
  145. {-76754, -234014, -3331},
  146. {-93742, -251032, -3331},
  147. {-87466, -257752, -3331},
  148. {-114413, -213241, -3331}
  149. };
  150. private static enum COMP_TYPE
  151. {
  152. CLASSED,
  153. NON_CLASSED
  154. }
  155. protected static OlympiadManager _manager;
  156. public static Olympiad getInstance()
  157. {
  158. if (_instance == null)
  159. _instance = new Olympiad();
  160. return _instance;
  161. }
  162. public Olympiad()
  163. {
  164. try
  165. {
  166. load();
  167. }
  168. catch(IOException e)
  169. {
  170. e.printStackTrace();
  171. }
  172. catch(SQLException s)
  173. {
  174. s.printStackTrace();
  175. }
  176. if (_period == 0) init();
  177. }
  178. private void load() throws IOException, SQLException
  179. {
  180. _nobles = new FastMap<Integer, StatsSet>();
  181. Properties OlympiadProperties = new Properties();
  182. InputStream is = new FileInputStream(new File("./" + OLYMPIAD_DATA_FILE));
  183. OlympiadProperties.load(is);
  184. is.close();
  185. _currentCycle = Integer.parseInt(OlympiadProperties.getProperty("CurrentCycle", "1"));
  186. _period = Integer.parseInt(OlympiadProperties.getProperty("Period", "0"));
  187. _olympiadEnd = Long.parseLong(OlympiadProperties.getProperty("OlympiadEnd", "0"));
  188. _validationEnd = Long.parseLong(OlympiadProperties.getProperty("ValdationEnd", "0"));
  189. _nextWeeklyChange = Long.parseLong(OlympiadProperties.getProperty("NextWeeklyChange", "0"));
  190. switch(_period)
  191. {
  192. case 0:
  193. if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
  194. setNewOlympiadEnd();
  195. else
  196. _isOlympiadEnd = false;
  197. break;
  198. case 1:
  199. if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  200. {
  201. _isOlympiadEnd = true;
  202. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  203. public void run()
  204. {
  205. _period = 0;
  206. _currentCycle++;
  207. deleteNobles();
  208. setNewOlympiadEnd();
  209. init();
  210. }
  211. }, getMillisToValidationEnd());
  212. }
  213. else
  214. {
  215. _currentCycle++;
  216. _period = 0;
  217. deleteNobles();
  218. setNewOlympiadEnd();
  219. }
  220. break;
  221. default:
  222. _log.warning("Olympiad System: Omg something went wrong in loading!! Period = " + _period);
  223. return;
  224. }
  225. try
  226. {
  227. Connection con = L2DatabaseFactory.getInstance().getConnection();
  228. PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_NOBLES);
  229. ResultSet rset = statement.executeQuery();
  230. while(rset.next())
  231. {
  232. StatsSet statDat = new StatsSet();
  233. int charId = rset.getInt(CHAR_ID);
  234. statDat.set(CLASS_ID, rset.getInt(CLASS_ID));
  235. statDat.set(CHAR_NAME, rset.getString(CHAR_NAME));
  236. statDat.set(POINTS, rset.getInt(POINTS));
  237. statDat.set(COMP_DONE, rset.getInt(COMP_DONE));
  238. statDat.set("to_save", false);
  239. _nobles.put(charId, statDat);
  240. }
  241. rset.close();
  242. statement.close();
  243. con.close();
  244. }
  245. catch(Exception e)
  246. {
  247. e.printStackTrace();
  248. }
  249. synchronized(this)
  250. {
  251. _log.info("Olympiad System: Loading Olympiad System....");
  252. if (_period == 0)
  253. _log.info("Olympiad System: Currently in Olympiad Period");
  254. else
  255. _log.info("Olympiad System: Currently in Validation Period");
  256. _log.info("Olympiad System: Period Ends....");
  257. long milliToEnd;
  258. if (_period == 0)
  259. milliToEnd = getMillisToOlympiadEnd();
  260. else
  261. milliToEnd = getMillisToValidationEnd();
  262. double numSecs = (milliToEnd / 1000) % 60;
  263. double countDown = ((milliToEnd / 1000) - numSecs) / 60;
  264. int numMins = (int) Math.floor(countDown % 60);
  265. countDown = (countDown - numMins) / 60;
  266. int numHours = (int) Math.floor(countDown % 24);
  267. int numDays = (int) Math.floor((countDown - numHours) / 24);
  268. _log.info("Olympiad System: In " + numDays + " days, " + numHours
  269. + " hours and " + numMins + " mins.");
  270. if (_period == 0)
  271. {
  272. _log.info("Olympiad System: Next Weekly Change is in....");
  273. milliToEnd = getMillisToWeekChange();
  274. double numSecs2 = (milliToEnd / 1000) % 60;
  275. double countDown2 = ((milliToEnd / 1000) - numSecs2) / 60;
  276. int numMins2 = (int) Math.floor(countDown2 % 60);
  277. countDown2 = (countDown2 - numMins2) / 60;
  278. int numHours2 = (int) Math.floor(countDown2 % 24);
  279. int numDays2 = (int) Math.floor((countDown2 - numHours2) / 24);
  280. _log.info("Olympiad System: " + numDays2 + " days, " + numHours2
  281. + " hours and " + numMins2 + " mins.");
  282. }
  283. }
  284. _log.info("Olympiad System: Loaded " + _nobles.size() + " Nobles");
  285. }
  286. protected void init()
  287. {
  288. if (_period == 1)
  289. return;
  290. _nonClassBasedRegisters = new FastList<L2PcInstance>();
  291. _classBasedRegisters = new FastMap<Integer, List<L2PcInstance>>();
  292. _compStart = Calendar.getInstance();
  293. _compStart.set(Calendar.HOUR_OF_DAY, COMP_START);
  294. _compStart.set(Calendar.MINUTE, COMP_MIN);
  295. _compEnd = _compStart.getTimeInMillis() + COMP_PERIOD;
  296. _scheduledOlympiadEnd = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  297. public void run()
  298. {
  299. SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_ENDED);
  300. sm.addNumber(_currentCycle);
  301. Announcements.getInstance().announceToAll(sm);
  302. Announcements.getInstance().announceToAll("Olympiad Validation Period has began");
  303. _isOlympiadEnd = true;
  304. if (_scheduledManagerTask != null)
  305. _scheduledManagerTask.cancel(true);
  306. if (_scheduledWeeklyTask != null)
  307. _scheduledWeeklyTask.cancel(true);
  308. Calendar validationEnd = Calendar.getInstance();
  309. _validationEnd = validationEnd.getTimeInMillis() + VALIDATION_PERIOD;
  310. saveNobleData();
  311. _period = 1;
  312. sortHerosToBe();
  313. giveHeroBonus();
  314. Hero.getInstance().computeNewHeroes(_heroesToBe);
  315. try {
  316. save();
  317. }
  318. catch (Exception e) {
  319. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  320. }
  321. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  322. public void run()
  323. {
  324. Announcements.getInstance().announceToAll("Olympiad Validation Period has ended");
  325. _period = 0;
  326. _currentCycle++;
  327. deleteNobles();
  328. setNewOlympiadEnd();
  329. init();
  330. }
  331. }, getMillisToValidationEnd());
  332. }
  333. }, getMillisToOlympiadEnd());
  334. updateCompStatus();
  335. scheduleWeeklyChange();
  336. }
  337. public boolean registerNoble(L2PcInstance noble, boolean classBased)
  338. {
  339. SystemMessage sm;
  340. if (_compStarted)
  341. {
  342. noble.sendMessage("Cant Register whilst competition is under way");
  343. return false;
  344. }
  345. if (!_inCompPeriod)
  346. {
  347. sm = new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  348. noble.sendPacket(sm);
  349. return false;
  350. }
  351. if (noble.isCursedWeaponEquiped())
  352. {
  353. noble.sendMessage("You can't participate to Olympiad while holding a cursed weapon.");
  354. return false;
  355. }
  356. if (!noble.isNoble())
  357. {
  358. sm = new SystemMessage(SystemMessageId.ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
  359. noble.sendPacket(sm);
  360. return false;
  361. }
  362. if (noble.getBaseClass() != noble.getClassId().getId())
  363. {
  364. sm = new SystemMessage(SystemMessageId.YOU_CANT_JOIN_THE_OLYMPIAD_WITH_A_SUB_JOB_CHARACTER);
  365. noble.sendPacket(sm);
  366. return false;
  367. }
  368. if (!_nobles.containsKey(noble.getObjectId()))
  369. {
  370. StatsSet statDat = new StatsSet();
  371. statDat.set(CLASS_ID, noble.getClassId().getId());
  372. statDat.set(CHAR_NAME, noble.getName());
  373. statDat.set(POINTS, DEFAULT_POINTS);
  374. statDat.set(COMP_DONE, 0);
  375. statDat.set("to_save", true);
  376. _nobles.put(noble.getObjectId(), statDat);
  377. }
  378. if (_classBasedRegisters.containsKey(noble.getClassId().getId()))
  379. {
  380. List<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  381. for (L2PcInstance partecipant: classed)
  382. {
  383. if (partecipant.getObjectId()==noble.getObjectId())
  384. {
  385. sm = new SystemMessage(SystemMessageId.YOU_ARE_ALREADY_ON_THE_WAITING_LIST_TO_PARTICIPATE_IN_THE_GAME_FOR_YOUR_CLASS);
  386. noble.sendPacket(sm);
  387. return false;
  388. }
  389. }
  390. }
  391. for (L2PcInstance partecipant: _nonClassBasedRegisters)
  392. {
  393. if (partecipant.getObjectId()==noble.getObjectId())
  394. {
  395. sm = new SystemMessage(SystemMessageId.YOU_ARE_ALREADY_ON_THE_WAITING_LIST_FOR_ALL_CLASSES_WAITING_TO_PARTICIPATE_IN_THE_GAME);
  396. noble.sendPacket(sm);
  397. return false;
  398. }
  399. }
  400. if (getNoblePoints(noble.getObjectId()) < 3)
  401. {
  402. noble.sendMessage("Cant register when you have less than 3 points");
  403. return false;
  404. }
  405. if (classBased)
  406. {
  407. if (_classBasedRegisters.containsKey(noble.getClassId().getId()))
  408. {
  409. List<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  410. classed.add(noble);
  411. _classBasedRegisters.remove(noble.getClassId().getId());
  412. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  413. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
  414. noble.sendPacket(sm);
  415. }
  416. else
  417. {
  418. List<L2PcInstance> classed = new FastList<L2PcInstance>();
  419. classed.add(noble);
  420. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  421. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_CLASSIFIED_GAMES);
  422. noble.sendPacket(sm);
  423. }
  424. }
  425. else
  426. {
  427. _nonClassBasedRegisters.add(noble);
  428. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_NO_CLASS_GAMES);
  429. noble.sendPacket(sm);
  430. }
  431. return true;
  432. }
  433. public boolean isRegistered(L2PcInstance noble)
  434. {
  435. if(_nonClassBasedRegisters == null) return false;
  436. if(_classBasedRegisters == null) return false;
  437. if (!_nonClassBasedRegisters.contains(noble))
  438. {
  439. if (!_classBasedRegisters.containsKey(noble.getClassId().getId()))
  440. {
  441. return false;
  442. }
  443. else
  444. {
  445. List<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  446. if (!classed.contains(noble))
  447. {
  448. return false;
  449. }
  450. }
  451. }
  452. return true;
  453. }
  454. public boolean unRegisterNoble(L2PcInstance noble)
  455. {
  456. SystemMessage sm;
  457. if (_compStarted)
  458. {
  459. noble.sendMessage("Cant Unregister whilst competition is under way");
  460. return false;
  461. }
  462. if (!_inCompPeriod)
  463. {
  464. sm = new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  465. noble.sendPacket(sm);
  466. return false;
  467. }
  468. if (!noble.isNoble())
  469. {
  470. sm = new SystemMessage(SystemMessageId.ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
  471. noble.sendPacket(sm);
  472. return false;
  473. }
  474. if (!isRegistered(noble))
  475. {
  476. sm = new SystemMessage(SystemMessageId.YOU_HAVE_NOT_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_A_GAME);
  477. noble.sendPacket(sm);
  478. return false;
  479. }
  480. if (_nonClassBasedRegisters.contains(noble))
  481. _nonClassBasedRegisters.remove(noble);
  482. else
  483. {
  484. List<L2PcInstance> classed = _classBasedRegisters.get(noble.getClassId().getId());
  485. classed.remove(noble);
  486. _classBasedRegisters.remove(noble.getClassId().getId());
  487. _classBasedRegisters.put(noble.getClassId().getId(), classed);
  488. }
  489. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_DELETED_FROM_THE_WAITING_LIST_OF_A_GAME);
  490. noble.sendPacket(sm);
  491. return true;
  492. }
  493. private void updateCompStatus()
  494. {
  495. _compStarted = false;
  496. synchronized(this)
  497. {
  498. long milliToStart = getMillisToCompBegin();
  499. double numSecs = (milliToStart / 1000) % 60;
  500. double countDown = ((milliToStart / 1000) - numSecs) / 60;
  501. int numMins = (int) Math.floor(countDown % 60);
  502. countDown = (countDown - numMins) / 60;
  503. int numHours = (int) Math.floor(countDown % 24);
  504. int numDays = (int) Math.floor((countDown - numHours) / 24);
  505. _log.info("Olympiad System: Competition Period Starts in "
  506. + numDays + " days, " + numHours
  507. + " hours and " + numMins + " mins.");
  508. _log.info("Olympiad System: Event starts/started : " + _compStart.getTime());
  509. }
  510. _scheduledCompStart = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  511. public void run()
  512. {
  513. if (isOlympiadEnd())
  514. return;
  515. _inCompPeriod = true;
  516. OlympiadManager om = new OlympiadManager();
  517. Announcements.getInstance().announceToAll(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_HAS_STARTED));
  518. _log.info("Olympiad System: Olympiad Game Started");
  519. _scheduledManagerTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(om, INITIAL_WAIT, BATTLE_WAIT);
  520. _scheduledCompEnd = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable(){
  521. public void run()
  522. {
  523. if (isOlympiadEnd())
  524. return;
  525. _scheduledManagerTask.cancel(true);
  526. _inCompPeriod = false;
  527. Announcements.getInstance().announceToAll(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_HAS_ENDED));
  528. _log.info("Olympiad System: Olympiad Game Ended");
  529. try {
  530. save();
  531. }
  532. catch (Exception e) {
  533. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  534. }
  535. init();
  536. }
  537. }, getMillisToCompEnd());
  538. }
  539. }, getMillisToCompBegin());
  540. }
  541. private long getMillisToOlympiadEnd()
  542. {
  543. //if (_olympiadEnd > Calendar.getInstance().getTimeInMillis())
  544. return (_olympiadEnd - Calendar.getInstance().getTimeInMillis());
  545. //return 10L;
  546. }
  547. public void manualSelectHeroes()
  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. if(_scheduledOlympiadEnd != null)
  559. _scheduledOlympiadEnd.cancel(true);
  560. Calendar validationEnd = Calendar.getInstance();
  561. _validationEnd = validationEnd.getTimeInMillis() + VALIDATION_PERIOD;
  562. saveNobleData();
  563. _period = 1;
  564. sortHerosToBe();
  565. giveHeroBonus();
  566. Hero.getInstance().computeNewHeroes(_heroesToBe);
  567. try {
  568. save();
  569. }
  570. catch (Exception e) {
  571. _log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
  572. }
  573. _scheduledValdationTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
  574. public void run()
  575. {
  576. Announcements.getInstance().announceToAll("Olympiad Validation Period has ended");
  577. _period = 0;
  578. _currentCycle++;
  579. deleteNobles();
  580. setNewOlympiadEnd();
  581. init();
  582. }
  583. }, getMillisToValidationEnd());
  584. }
  585. protected long getMillisToValidationEnd()
  586. {
  587. if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  588. return (_validationEnd - Calendar.getInstance().getTimeInMillis());
  589. return 10L;
  590. }
  591. public boolean isOlympiadEnd()
  592. {
  593. return _isOlympiadEnd;
  594. }
  595. protected void setNewOlympiadEnd()
  596. {
  597. SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
  598. sm.addNumber(_currentCycle);
  599. Announcements.getInstance().announceToAll(sm);
  600. Calendar currentTime = Calendar.getInstance();
  601. currentTime.add(Calendar.MONTH, 1);
  602. currentTime.set(Calendar.DAY_OF_MONTH, 1);
  603. currentTime.set(Calendar.AM_PM, Calendar.AM);
  604. currentTime.set(Calendar.HOUR, 12);
  605. currentTime.set(Calendar.MINUTE, 0);
  606. currentTime.set(Calendar.SECOND, 0);
  607. _olympiadEnd = currentTime.getTimeInMillis();
  608. Calendar nextChange = Calendar.getInstance();
  609. _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
  610. _isOlympiadEnd = false;
  611. }
  612. public boolean inCompPeriod()
  613. {
  614. return _inCompPeriod;
  615. }
  616. private long getMillisToCompBegin()
  617. {
  618. if (_compStart.getTimeInMillis() < Calendar.getInstance().getTimeInMillis() &&
  619. _compEnd > Calendar.getInstance().getTimeInMillis())
  620. return 10L;
  621. if (_compStart.getTimeInMillis() > Calendar.getInstance().getTimeInMillis())
  622. return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
  623. return setNewCompBegin();
  624. }
  625. private long setNewCompBegin()
  626. {
  627. _compStart = Calendar.getInstance();
  628. _compStart.set(Calendar.HOUR_OF_DAY, COMP_START);
  629. _compStart.set(Calendar.MINUTE, COMP_MIN);
  630. _compStart.add(Calendar.HOUR_OF_DAY, 24);
  631. _compEnd = _compStart.getTimeInMillis() + COMP_PERIOD;
  632. _log.info("Olympiad System: New Schedule @ " + _compStart.getTime());
  633. return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
  634. }
  635. protected long getMillisToCompEnd()
  636. {
  637. //if (_compEnd > Calendar.getInstance().getTimeInMillis())
  638. return (_compEnd - Calendar.getInstance().getTimeInMillis());
  639. //return 10L;
  640. }
  641. private long getMillisToWeekChange()
  642. {
  643. if (_nextWeeklyChange > Calendar.getInstance().getTimeInMillis())
  644. return (_nextWeeklyChange - Calendar.getInstance().getTimeInMillis());
  645. return 10L;
  646. }
  647. private void scheduleWeeklyChange()
  648. {
  649. _scheduledWeeklyTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable() {
  650. public void run()
  651. {
  652. addWeeklyPoints();
  653. _log.info("Olympiad System: Added weekly points to nobles");
  654. Calendar nextChange = Calendar.getInstance();
  655. _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
  656. }
  657. }, getMillisToWeekChange(), WEEKLY_PERIOD);
  658. }
  659. protected synchronized void addWeeklyPoints()
  660. {
  661. if (_period == 1)
  662. return;
  663. for (Integer nobleId : _nobles.keySet())
  664. {
  665. StatsSet nobleInfo = _nobles.get(nobleId);
  666. int currentPoints = nobleInfo.getInteger(POINTS);
  667. currentPoints += WEEKLY_POINTS;
  668. nobleInfo.set(POINTS, currentPoints);
  669. _nobles.remove(nobleId);
  670. _nobles.put(nobleId, nobleInfo);
  671. }
  672. }
  673. public String[] getMatchList()
  674. {
  675. return (_manager == null)? null : _manager.getAllTitles();
  676. }
  677. public int getCurrentCycle()
  678. {
  679. return _currentCycle;
  680. }
  681. public void addSpectator(int id, L2PcInstance spectator)
  682. {
  683. if (_manager == null || (_manager.getOlympiadInstance(id) == null) || !_battleStarted)
  684. {
  685. spectator.sendPacket(new SystemMessage(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS));
  686. return;
  687. }
  688. L2PcInstance[] players = _manager.getOlympiadInstance(id).getPlayers();
  689. if (players == null) return;
  690. spectator.enterOlympiadObserverMode(STADIUMS[id][0], STADIUMS[id][1], STADIUMS[id][2], id);
  691. _manager.getOlympiadInstance(id).addSpectator(spectator);
  692. spectator.sendPacket(new ExOlympiadUserInfoSpectator(players[0], 2));
  693. spectator.sendPacket(new ExOlympiadUserInfoSpectator(players[1], 1));
  694. }
  695. public void removeSpectator(int id, L2PcInstance spectator)
  696. {
  697. if (_manager == null || (_manager.getOlympiadInstance(id) == null)) return;
  698. _manager.getOlympiadInstance(id).removeSpectator(spectator);
  699. }
  700. public List<L2PcInstance> getSpectators(int id)
  701. {
  702. return _manager.getOlympiadInstance(id).getSpectators();
  703. }
  704. public Map<Integer, L2OlympiadGame> getOlympiadGames()
  705. {
  706. return _manager.getOlympiadGames();
  707. }
  708. public boolean playerInStadia(L2PcInstance player)
  709. {
  710. return (OlympiadStadiaManager.getInstance().getStadium(player) != null);
  711. }
  712. public int[] getWaitingList()
  713. {
  714. int[] array = new int[2];
  715. if (!inCompPeriod())
  716. return null;
  717. int classCount = 0;
  718. if (_classBasedRegisters.size() != 0)
  719. for (List<L2PcInstance> classed : _classBasedRegisters.values())
  720. {
  721. classCount += classed.size();
  722. }
  723. array[0] = classCount;
  724. array[1] = _nonClassBasedRegisters.size();
  725. return array;
  726. }
  727. protected synchronized void saveNobleData()
  728. {
  729. Connection con = null;
  730. if (_nobles == null)
  731. return;
  732. try
  733. {
  734. con = L2DatabaseFactory.getInstance().getConnection();
  735. PreparedStatement statement;
  736. for (Integer nobleId : _nobles.keySet())
  737. {
  738. StatsSet nobleInfo = _nobles.get(nobleId);
  739. int charId = nobleId;
  740. int classId = nobleInfo.getInteger(CLASS_ID);
  741. String charName = nobleInfo.getString(CHAR_NAME);
  742. int points = nobleInfo.getInteger(POINTS);
  743. int compDone = nobleInfo.getInteger(COMP_DONE);
  744. boolean toSave = nobleInfo.getBool("to_save");
  745. if (toSave)
  746. {
  747. statement = con.prepareStatement(OLYMPIAD_SAVE_NOBLES);
  748. statement.setInt(1, charId);
  749. statement.setInt(2, classId);
  750. statement.setString(3, charName);
  751. statement.setInt(4, points);
  752. statement.setInt(5, compDone);
  753. statement.execute();
  754. statement.close();
  755. nobleInfo.set("to_save", false);
  756. _nobles.remove(nobleId);
  757. _nobles.put(nobleId, nobleInfo);
  758. }
  759. else
  760. {
  761. statement = con.prepareStatement(OLYMPIAD_UPDATE_NOBLES);
  762. statement.setInt(1, points);
  763. statement.setInt(2, compDone);
  764. statement.setInt(3, charId);
  765. statement.execute();
  766. statement.close();
  767. }
  768. }
  769. }
  770. catch(SQLException e) {_log.warning("Olympiad System: Couldnt save nobles info in db");}
  771. finally
  772. {
  773. try{con.close();}catch(Exception e){e.printStackTrace();}
  774. }
  775. }
  776. protected void sortHerosToBe()
  777. {
  778. if (_period != 1) return;
  779. _heroesToBe = new FastList<StatsSet>();
  780. Connection con = null;
  781. try
  782. {
  783. con = L2DatabaseFactory.getInstance().getConnection();
  784. PreparedStatement statement;
  785. ResultSet rset;
  786. StatsSet hero;
  787. for (int i = 88; i < 119; i++)
  788. {
  789. statement = con.prepareStatement(OLYMPIAD_GET_HEROS);
  790. statement.setInt(1, i);
  791. rset = statement.executeQuery();
  792. if (rset.next())
  793. {
  794. hero = new StatsSet();
  795. hero.set(CLASS_ID, i);
  796. hero.set(CHAR_ID, rset.getInt(CHAR_ID));
  797. hero.set(CHAR_NAME, rset.getString(CHAR_NAME));
  798. _heroesToBe.add(hero);
  799. }
  800. statement.close();
  801. rset.close();
  802. }
  803. }
  804. catch(SQLException e){_log.warning("Olympiad System: Couldnt heros from db");}
  805. finally
  806. {
  807. try{con.close();}catch(Exception e){e.printStackTrace();}
  808. }
  809. }
  810. public List<String> getClassLeaderBoard(int classId)
  811. {
  812. //if (_period != 1) return;
  813. List<String> names = new FastList<String>();
  814. Connection con = null;
  815. try
  816. {
  817. con = L2DatabaseFactory.getInstance().getConnection();
  818. PreparedStatement statement;
  819. ResultSet rset;
  820. statement = con.prepareStatement(GET_EACH_CLASS_LEADER);
  821. statement.setInt(1, classId);
  822. rset = statement.executeQuery();
  823. while (rset.next())
  824. {
  825. names.add(rset.getString(CHAR_NAME));
  826. }
  827. statement.close();
  828. rset.close();
  829. return names;
  830. }
  831. catch(SQLException e){_log.warning("Olympiad System: Couldnt heros from db");}
  832. finally
  833. {
  834. try{con.close();}catch(Exception e){e.printStackTrace();}
  835. }
  836. return names;
  837. }
  838. protected void giveHeroBonus()
  839. {
  840. if (_heroesToBe.size() == 0)
  841. return;
  842. for (StatsSet hero : _heroesToBe)
  843. {
  844. int charId = hero.getInteger(CHAR_ID);
  845. StatsSet noble = _nobles.get(charId);
  846. int currentPoints = noble.getInteger(POINTS);
  847. currentPoints += 300;
  848. noble.set(POINTS, currentPoints);
  849. _nobles.remove(charId);
  850. _nobles.put(charId, noble);
  851. }
  852. }
  853. public int getNoblessePasses(int objId)
  854. {
  855. if (_period != 1 || _nobles.size() == 0)
  856. return 0;
  857. StatsSet noble = _nobles.get(objId);
  858. if (noble == null)
  859. return 0;
  860. int points = noble.getInteger(POINTS);
  861. if (points <= 50)
  862. return 0;
  863. noble.set(POINTS, 0);
  864. _nobles.remove(objId);
  865. _nobles.put(objId, noble);
  866. points *= 1000;
  867. return points;
  868. }
  869. public boolean isRegisteredInComp(L2PcInstance player)
  870. {
  871. boolean result = false;
  872. if (_nonClassBasedRegisters != null && _nonClassBasedRegisters.contains(player))
  873. result = true;
  874. else if (_classBasedRegisters != null && _classBasedRegisters.containsKey(player.getClassId().getId()))
  875. {
  876. List<L2PcInstance> classed = _classBasedRegisters.get(player.getClassId().getId());
  877. if (classed.contains(player))
  878. result = true;
  879. }
  880. return result;
  881. }
  882. public int getNoblePoints(int objId)
  883. {
  884. if (_nobles.size() == 0)
  885. return 0;
  886. StatsSet noble = _nobles.get(objId);
  887. if (noble == null)
  888. return 0;
  889. int points = noble.getInteger(POINTS);
  890. return points;
  891. }
  892. public int getCompetitionDone(int objId)
  893. {
  894. if (_nobles.size() == 0)
  895. return 0;
  896. StatsSet noble = _nobles.get(objId);
  897. if (noble == null)
  898. return 0;
  899. int points = noble.getInteger(COMP_DONE);
  900. return points;
  901. }
  902. protected void deleteNobles()
  903. {
  904. Connection con = null;
  905. try
  906. {
  907. con = L2DatabaseFactory.getInstance().getConnection();
  908. PreparedStatement statement = con.prepareStatement(OLYMPIAD_DELETE_ALL);
  909. statement.execute();
  910. statement.close();
  911. }
  912. catch(SQLException e){_log.warning("Olympiad System: Couldnt delete nobles from db");}
  913. finally
  914. {
  915. try{con.close();}catch(Exception e){e.printStackTrace();}
  916. }
  917. _nobles.clear();
  918. }
  919. public void save() throws IOException
  920. {
  921. saveNobleData();
  922. Properties OlympiadProperties = new Properties();
  923. FileOutputStream fos = new FileOutputStream(new File(Config.DATAPACK_ROOT, OLYMPIAD_DATA_FILE));
  924. OlympiadProperties.setProperty("CurrentCycle", String.valueOf(_currentCycle));
  925. OlympiadProperties.setProperty("Period", String.valueOf(_period));
  926. OlympiadProperties.setProperty("OlympiadEnd", String.valueOf(_olympiadEnd));
  927. OlympiadProperties.setProperty("ValdationEnd", String.valueOf(_validationEnd));
  928. OlympiadProperties.setProperty("NextWeeklyChange", String.valueOf(_nextWeeklyChange));
  929. OlympiadProperties.store(fos, "Olympiad Properties");
  930. fos.close();
  931. }
  932. private class OlympiadManager implements Runnable
  933. {
  934. private Map<Integer, L2OlympiadGame> _olympiadInstances;
  935. private Map<Integer, List<L2PcInstance>> _classBasedParticipants;
  936. private Map<Integer, List<L2PcInstance>> _nonClassBasedParticipants;
  937. public OlympiadManager()
  938. {
  939. _olympiadInstances = new FastMap<Integer, L2OlympiadGame>();
  940. _manager = this;
  941. }
  942. public synchronized void run()
  943. {
  944. if (isOlympiadEnd())
  945. {
  946. _scheduledManagerTask.cancel(true);
  947. return;
  948. }
  949. if (!inCompPeriod())
  950. return;
  951. //Announcements.getInstance().announceToAll("Comp Match Init");
  952. if (_nobles.size() == 0)
  953. return;
  954. _compStarted = true;
  955. try{
  956. sortClassBasedOpponents();
  957. _nonClassBasedParticipants = pickOpponents(_nonClassBasedRegisters);
  958. }catch(Exception e){e.printStackTrace();}
  959. int classIndex = 0;
  960. int nonClassIndex = 0;
  961. int index = 0;
  962. for (int i = 0; i < COLLISIEUMS; i++)
  963. {
  964. if (_classBasedParticipants.get(classIndex) != null)
  965. {
  966. _olympiadInstances.put(index, new L2OlympiadGame(index, COMP_TYPE.CLASSED, _classBasedParticipants.get(classIndex), STADIUMS[index]));
  967. index++;
  968. classIndex++;
  969. }
  970. if (_nonClassBasedParticipants.get(nonClassIndex) != null)
  971. {
  972. _olympiadInstances.put(index, new L2OlympiadGame(index, COMP_TYPE.NON_CLASSED, _nonClassBasedParticipants.get(nonClassIndex), STADIUMS[index]));
  973. nonClassIndex++;
  974. index++;
  975. }
  976. }
  977. if (_olympiadInstances.size() == 0)
  978. {
  979. _compStarted = false;
  980. return;
  981. }
  982. for (L2OlympiadGame instance : _olympiadInstances.values())
  983. instance.sendMessageToPlayers(false,30);
  984. //Wait 30 seconds
  985. try{
  986. wait(30000);
  987. }catch (InterruptedException e){}
  988. for (L2OlympiadGame instance : _olympiadInstances.values())
  989. instance.portPlayersToArena();
  990. //Wait 20 seconds
  991. try{
  992. wait(20000);
  993. }catch (InterruptedException e){}
  994. for (L2OlympiadGame instance : _olympiadInstances.values())
  995. instance.removals();
  996. _battleStarted = true;
  997. //Wait 1 min
  998. for (int i=60;i>10;i-=10)
  999. {
  1000. for (L2OlympiadGame instance : _olympiadInstances.values())
  1001. {
  1002. instance.sendMessageToPlayers(true,i);
  1003. if (i==20)
  1004. instance.additions();
  1005. }
  1006. try{
  1007. wait(10000);
  1008. }catch (InterruptedException e){}
  1009. }
  1010. for (L2OlympiadGame instance : _olympiadInstances.values())
  1011. {
  1012. instance.sendMessageToPlayers(true,10);
  1013. }
  1014. try{
  1015. wait(5000);
  1016. }catch (InterruptedException e){}
  1017. for (int i=5;i>0;i--)
  1018. {
  1019. for (L2OlympiadGame instance : _olympiadInstances.values())
  1020. {
  1021. instance.sendMessageToPlayers(true,i);
  1022. }
  1023. try{
  1024. wait(1000);
  1025. }catch (InterruptedException e){}
  1026. }
  1027. for (L2OlympiadGame instance : _olympiadInstances.values())
  1028. {
  1029. instance.makeCompetitionStart();
  1030. }
  1031. //Wait 6 mins (Battle)
  1032. try{
  1033. wait(BATTLE_PERIOD);
  1034. }catch (InterruptedException e){}
  1035. for (L2OlympiadGame instance : _olympiadInstances.values())
  1036. {
  1037. try{
  1038. instance.validateWinner();
  1039. }catch(Exception e){e.printStackTrace();}
  1040. }
  1041. //Wait 20 seconds
  1042. try{
  1043. wait(20000);
  1044. }catch (InterruptedException e){}
  1045. for (L2OlympiadGame instance : _olympiadInstances.values())
  1046. {
  1047. instance.portPlayersBack();
  1048. instance.clearSpectators();
  1049. }
  1050. //Wait 20 seconds
  1051. try{
  1052. wait(20000);
  1053. }catch (InterruptedException e){}
  1054. _classBasedParticipants.clear();
  1055. _nonClassBasedParticipants.clear();
  1056. _olympiadInstances.clear();
  1057. _classBasedRegisters.clear();
  1058. _nonClassBasedRegisters.clear();
  1059. _battleStarted = false;
  1060. _compStarted = false;
  1061. }
  1062. protected L2OlympiadGame getOlympiadInstance(int index)
  1063. {
  1064. if (_olympiadInstances != null || _compStarted)
  1065. {
  1066. return _olympiadInstances.get(index);
  1067. }
  1068. return null;
  1069. }
  1070. private void sortClassBasedOpponents()
  1071. {
  1072. Map<Integer, List<L2PcInstance>> result = new FastMap<Integer, List<L2PcInstance>>();
  1073. _classBasedParticipants = new FastMap<Integer, List<L2PcInstance>>();
  1074. int count = 0;
  1075. if (_classBasedRegisters.size() == 0) return;
  1076. for (List<L2PcInstance> classed : _classBasedRegisters.values())
  1077. {
  1078. if (classed.size() == 0) continue;
  1079. try{
  1080. result = pickOpponents(classed);
  1081. }catch(Exception e){e.printStackTrace();}
  1082. if (result.size() == 0)
  1083. continue;
  1084. for (List<L2PcInstance> list : result.values())
  1085. {
  1086. if (count == 10) break;
  1087. _classBasedParticipants.put(count, list);
  1088. count++;
  1089. }
  1090. if (count == 10) break;
  1091. }
  1092. }
  1093. protected Map<Integer, L2OlympiadGame> getOlympiadGames()
  1094. {
  1095. return (_olympiadInstances == null)? null : _olympiadInstances;
  1096. }
  1097. private Map<Integer, List<L2PcInstance>> pickOpponents(List<L2PcInstance> list) throws Exception
  1098. {
  1099. Map<Integer, List<L2PcInstance>> result =
  1100. new FastMap<Integer, List<L2PcInstance>>();
  1101. if (list.size() == 0)
  1102. return result;
  1103. int loopCount = (list.size() / 2);
  1104. int first;
  1105. int second;
  1106. if (loopCount < 1)
  1107. return result;
  1108. int count = 0;
  1109. for (int i = 0; i < loopCount; i++)
  1110. {
  1111. count++;
  1112. List<L2PcInstance> opponents = new FastList<L2PcInstance>();
  1113. first = Rnd.nextInt(list.size());
  1114. opponents.add(list.get(first));
  1115. list.remove(first);
  1116. second = Rnd.nextInt(list.size());
  1117. opponents.add(list.get(second));
  1118. list.remove(second);
  1119. result.put(i, opponents);
  1120. if (count == 11)
  1121. break;
  1122. }
  1123. return result;
  1124. }
  1125. protected String[] getAllTitles()
  1126. {
  1127. if(!_compStarted)
  1128. return null;
  1129. if(_olympiadInstances.size() == 0)
  1130. return null;
  1131. String[] msg = new String[_olympiadInstances.size()];
  1132. int count = 0;
  1133. int match = 1;
  1134. for (L2OlympiadGame instance : _olympiadInstances.values())
  1135. {
  1136. msg[count] = match + "_In Progress_" + instance.getTitle();
  1137. count++;
  1138. match++;
  1139. }
  1140. return msg;
  1141. }
  1142. }
  1143. private class L2OlympiadGame
  1144. {
  1145. protected COMP_TYPE _type;
  1146. private boolean _aborted;
  1147. private String _playerOneName;
  1148. private String _playerTwoName;
  1149. private int _playerOneID = 0;
  1150. private int _playerTwoID = 0;
  1151. private L2PcInstance _playerOne;
  1152. private L2PcInstance _playerTwo;
  1153. private List<L2PcInstance> _players;
  1154. private int[] _playerOneLocation;
  1155. private int[] _playerTwoLocation;
  1156. private int[] _stadiumPort;
  1157. private List<L2PcInstance> _spectators;
  1158. private SystemMessage _sm;
  1159. private SystemMessage _sm2;
  1160. private SystemMessage _sm3;
  1161. protected L2OlympiadGame(int id, COMP_TYPE type, List<L2PcInstance> list, int[] stadiumPort)
  1162. {
  1163. _aborted = false;
  1164. _type = type;
  1165. _stadiumPort = stadiumPort;
  1166. _spectators = new FastList<L2PcInstance>();
  1167. if (list != null)
  1168. {
  1169. _players = list;
  1170. _playerOne = list.get(0);
  1171. _playerTwo = list.get(1);
  1172. try {
  1173. _playerOneName = _playerOne.getName();
  1174. _playerTwoName = _playerTwo.getName();
  1175. _playerOne.setOlympiadGameId(id);
  1176. _playerTwo.setOlympiadGameId(id);
  1177. _playerOneID = _playerOne.getObjectId();
  1178. _playerTwoID = _playerTwo.getObjectId();
  1179. }
  1180. catch (Exception e) {
  1181. _aborted = true;
  1182. clearPlayers();
  1183. }
  1184. _log.info("Olympiad System: Game - " + id + ": "
  1185. + _playerOne.getName() + " Vs " + _playerTwo.getName());
  1186. }
  1187. else {
  1188. _aborted = true;
  1189. clearPlayers();
  1190. return;
  1191. }
  1192. }
  1193. protected void removals()
  1194. {
  1195. if (_aborted) return;
  1196. if (_playerOne == null || _playerTwo == null) return;
  1197. for (L2PcInstance player : _players)
  1198. {
  1199. try{
  1200. //Remove Clan Skills
  1201. if (player.getClan() != null)
  1202. {
  1203. for(L2Skill skill: player.getClan().getAllSkills())
  1204. player.removeSkill(skill,false);
  1205. }
  1206. //Abort casting if player casting
  1207. if (player.isCastingNow())
  1208. {
  1209. player.abortCast();
  1210. }
  1211. //Remove Hero Skills
  1212. if (player.isHero())
  1213. {
  1214. for(L2Skill skill: HeroSkillTable.GetHeroSkills())
  1215. player.removeSkill(skill,false);
  1216. }
  1217. //Remove Buffs
  1218. player.stopAllEffects();
  1219. //Remove Summon's Buffs
  1220. if (player.getPet() != null)
  1221. {
  1222. L2Summon summon = player.getPet();
  1223. summon.stopAllEffects();
  1224. if (summon instanceof L2PetInstance)
  1225. summon.unSummon(player);
  1226. }
  1227. /*if (player.getCubics() != null)
  1228. {
  1229. for(L2CubicInstance cubic : player.getCubics().values())
  1230. {
  1231. cubic.stopAction();
  1232. player.delCubic(cubic.getId());
  1233. }
  1234. player.getCubics().clear();
  1235. }*/
  1236. //Remove player from his party
  1237. if (player.getParty() != null)
  1238. {
  1239. L2Party party = player.getParty();
  1240. party.removePartyMember(player);
  1241. }
  1242. //Remove Hero Weapons
  1243. // check to prevent the using of weapon/shield on strider/wyvern
  1244. L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1245. if (wpn == null) wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  1246. if (wpn != null &&
  1247. (
  1248. (wpn.getItemId() >= 6611 && wpn.getItemId() <= 6621) ||
  1249. wpn.getItemId() == 6842
  1250. )
  1251. )
  1252. {
  1253. L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  1254. InventoryUpdate iu = new InventoryUpdate();
  1255. for (int i = 0; i < unequiped.length; i++)
  1256. iu.addModifiedItem(unequiped[i]);
  1257. player.sendPacket(iu);
  1258. player.abortAttack();
  1259. player.broadcastUserInfo();
  1260. // this can be 0 if the user pressed the right mousebutton twice very fast
  1261. if (unequiped.length > 0)
  1262. {
  1263. if (unequiped[0].isWear())
  1264. return;
  1265. SystemMessage sm = null;
  1266. if (unequiped[0].getEnchantLevel() > 0){
  1267. sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  1268. sm.addNumber(unequiped[0].getEnchantLevel());
  1269. sm.addItemName(unequiped[0].getItemId());
  1270. }else{
  1271. sm = new SystemMessage(SystemMessageId.S1_DISARMED);
  1272. sm.addItemName(unequiped[0].getItemId());
  1273. }
  1274. player.sendPacket(sm);
  1275. }
  1276. }
  1277. //Remove ss/sps/bsps automation
  1278. Map<Integer, Integer> activeSoulShots = player.getAutoSoulShot();
  1279. for (int itemId : activeSoulShots.values())
  1280. player.removeAutoSoulShot(itemId);
  1281. player.sendSkillList();
  1282. } catch (Exception e) {}
  1283. }
  1284. _sm = new SystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
  1285. _sm.addNumber(120);
  1286. broadcastMessage(_sm, false);
  1287. }
  1288. protected void clearPlayers()
  1289. {
  1290. _playerOne = null;
  1291. _playerTwo = null;
  1292. _players = null;
  1293. _playerOneName = "";
  1294. _playerTwoName = "";
  1295. _playerOneID = 0;
  1296. _playerTwoID = 0;
  1297. }
  1298. protected boolean portPlayersToArena()
  1299. {
  1300. _playerOneLocation = new int[3];
  1301. _playerTwoLocation = new int[3];
  1302. boolean _playerOneCrash = true;
  1303. boolean _playerTwoCrash = true;
  1304. try {
  1305. if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  1306. _playerOneCrash=false;
  1307. } catch (Exception e) {}
  1308. try {
  1309. if (_playerTwo != null && _playerTwo.getOlympiadGameId() != -1)
  1310. _playerTwoCrash=false;
  1311. } catch (Exception e){ }
  1312. if (_playerOneCrash){
  1313. StatsSet playerOneStat;
  1314. playerOneStat = _nobles.get(_playerOneID);
  1315. int playerOnePoints = playerOneStat.getInteger(POINTS);
  1316. playerOneStat.set(POINTS, playerOnePoints - (playerOnePoints / 5));
  1317. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... "+_playerOneName+" lost "+(playerOnePoints - (playerOnePoints / 5))+" points for crash before teleport to arena");
  1318. }
  1319. if (_playerTwoCrash){
  1320. StatsSet playerTwoStat;
  1321. playerTwoStat = _nobles.get(_playerTwoID);
  1322. int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  1323. playerTwoStat.set(POINTS, playerTwoPoints - (playerTwoPoints / 5));
  1324. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... "+_playerTwoName+" lost "+(playerTwoPoints - (playerTwoPoints / 5))+" points for crash before teleport to arena");
  1325. }
  1326. if (_playerOneCrash || _playerTwoCrash){
  1327. _playerOne=null;
  1328. _playerTwo=null;
  1329. _aborted = true;
  1330. return false;
  1331. }
  1332. try {
  1333. _playerOneLocation[0] = _playerOne.getX();
  1334. _playerOneLocation[1] = _playerOne.getY();
  1335. _playerOneLocation[2] = _playerOne.getZ();
  1336. _playerTwoLocation[0] = _playerTwo.getX();
  1337. _playerTwoLocation[1] = _playerTwo.getY();
  1338. _playerTwoLocation[2] = _playerTwo.getZ();
  1339. //_playerOne.getAppearance().setInvisible();
  1340. //_playerOne.broadcastUserInfo();
  1341. //_playerOne.decayMe();
  1342. //_playerOne.spawnMe();
  1343. //_playerTwo.getAppearance().setInvisible();
  1344. //_playerTwo.broadcastUserInfo();
  1345. //_playerTwo.decayMe();
  1346. //_playerTwo.spawnMe();
  1347. if (_playerOne.isSitting())
  1348. _playerOne.standUp();
  1349. if (_playerTwo.isSitting())
  1350. _playerTwo.standUp();
  1351. _playerOne.setTarget(null);
  1352. _playerTwo.setTarget(null);
  1353. _playerOne.teleToLocation(_stadiumPort[0], _stadiumPort[1], _stadiumPort[2], true);
  1354. _playerTwo.teleToLocation(_stadiumPort[0], _stadiumPort[1], _stadiumPort[2], true);
  1355. _playerOne.setIsInOlympiadMode(true);
  1356. _playerOne.setIsOlympiadStart(false);
  1357. _playerTwo.setIsInOlympiadMode(true);
  1358. _playerTwo.setIsOlympiadStart(false);
  1359. } catch (Exception e) {
  1360. return false;
  1361. }
  1362. return true;
  1363. }
  1364. protected void sendMessageToPlayers(boolean toBattleBegin, int nsecond)
  1365. {
  1366. if(!toBattleBegin)
  1367. _sm = new SystemMessage(SystemMessageId.YOU_WILL_ENTER_THE_OLYMPIAD_STADIUM_IN_S1_SECOND_S);
  1368. else
  1369. _sm = new SystemMessage(SystemMessageId.THE_GAME_WILL_START_IN_S1_SECOND_S);
  1370. _sm.addNumber(nsecond);
  1371. try {
  1372. for (L2PcInstance player : _players)
  1373. player.sendPacket(_sm);
  1374. } catch (Exception e) {};
  1375. }
  1376. protected void portPlayersBack()
  1377. {
  1378. try {
  1379. _playerOne.teleToLocation(_playerOneLocation[0],
  1380. _playerOneLocation[1], _playerOneLocation[2], true);
  1381. }
  1382. catch (Exception e) {}
  1383. try {
  1384. _playerTwo.teleToLocation(_playerTwoLocation[0],
  1385. _playerTwoLocation[1], _playerTwoLocation[2], true);
  1386. }
  1387. catch (Exception e) {}
  1388. for (L2PcInstance player : _players)
  1389. {
  1390. try {
  1391. player.setIsInOlympiadMode(false);
  1392. player.setIsOlympiadStart(false);
  1393. player.setOlympiadSide(-1);
  1394. player.setOlympiadGameId(-1);
  1395. player.setCurrentCp(player.getMaxCp());
  1396. player.setCurrentHp(player.getMaxHp());
  1397. player.setCurrentMp(player.getMaxMp());
  1398. player.getStatus().startHpMpRegeneration();
  1399. //Add Clan Skills
  1400. if (player.getClan() != null)
  1401. {
  1402. for(L2Skill skill: player.getClan().getAllSkills())
  1403. {
  1404. if ( skill.getMinPledgeClass() <= player.getPledgeClass() )
  1405. player.addSkill(skill,false);
  1406. }
  1407. }
  1408. //Add Hero Skills
  1409. if (player.isHero())
  1410. {
  1411. for(L2Skill skill: HeroSkillTable.GetHeroSkills())
  1412. player.addSkill(skill,false);
  1413. }
  1414. player.sendSkillList();
  1415. } catch (Exception e) {}
  1416. }
  1417. }
  1418. protected void validateWinner()
  1419. {
  1420. if (_aborted || (_playerOne == null && _playerTwo == null))
  1421. {
  1422. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... aborted/tie due to crashes!");
  1423. return;
  1424. }
  1425. StatsSet playerOneStat;
  1426. StatsSet playerTwoStat;
  1427. playerOneStat = _nobles.get(_playerOneID);
  1428. playerTwoStat = _nobles.get(_playerTwoID);
  1429. int playerOnePlayed = playerOneStat.getInteger(COMP_DONE);
  1430. int playerTwoPlayed = playerTwoStat.getInteger(COMP_DONE);
  1431. int playerOnePoints = playerOneStat.getInteger(POINTS);
  1432. int playerTwoPoints = playerTwoStat.getInteger(POINTS);
  1433. double playerOneHp = 0;
  1434. double hpDiffOne = 9999999;
  1435. try{
  1436. if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  1437. {
  1438. playerOneHp = _playerOne.getCurrentHp()+_playerOne.getCurrentCp();
  1439. hpDiffOne = (_playerOne.getMaxHp()+_playerOne.getMaxCp()) - playerOneHp;
  1440. }
  1441. }catch (Exception e){
  1442. playerOneHp = 0;
  1443. hpDiffOne = 9999999;
  1444. }
  1445. double playerTwoHp = 0;
  1446. double hpDiffTwo = 9999999;
  1447. try{
  1448. if (_playerTwo != null && _playerTwo.getOlympiadGameId()!=-1)
  1449. {
  1450. playerTwoHp = _playerTwo.getCurrentHp()+_playerTwo.getCurrentCp();
  1451. hpDiffTwo = (_playerTwo.getMaxHp()+_playerTwo.getMaxCp()) - playerTwoHp;
  1452. }
  1453. }catch (Exception e){
  1454. playerTwoHp = 0;
  1455. hpDiffTwo = 9999999;
  1456. }
  1457. _sm = new SystemMessage(SystemMessageId.S1_HAS_WON_THE_GAME);
  1458. _sm2 = new SystemMessage(SystemMessageId.S1_HAS_GAINED_S2_OLYMPIAD_POINTS);
  1459. _sm3 = new SystemMessage(SystemMessageId.S1_HAS_LOST_S2_OLYMPIAD_POINTS);
  1460. String result = "";
  1461. if (playerTwoHp==0 || hpDiffOne < hpDiffTwo)
  1462. {
  1463. int pointDiff;
  1464. pointDiff = (playerTwoPoints / 3);
  1465. playerOneStat.set(POINTS, playerOnePoints + pointDiff);
  1466. playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  1467. _sm.addString(_playerOneName);
  1468. broadcastMessage(_sm, true);
  1469. _sm2.addString(_playerOneName);
  1470. _sm2.addNumber(pointDiff);
  1471. broadcastMessage(_sm2, true);
  1472. _sm3.addString(_playerTwoName);
  1473. _sm3.addNumber(pointDiff);
  1474. broadcastMessage(_sm3, true);
  1475. _playerOne = L2World.getInstance().getPlayer(_playerOneName); // why this...
  1476. try {
  1477. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+hpDiffOne+" vs "+hpDiffTwo+") "+_playerOneName+" win "+pointDiff+" points";
  1478. L2ItemInstance item = _playerOne.getInventory().addItem("Olympiad", 6651, 30, _playerOne, null);
  1479. InventoryUpdate iu = new InventoryUpdate();
  1480. iu.addModifiedItem(item);
  1481. _playerOne.sendPacket(iu);
  1482. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1483. sm.addItemName(item.getItemId());
  1484. sm.addNumber(30);
  1485. _playerOne.sendPacket(sm);
  1486. } catch (Exception e) { }
  1487. }
  1488. else if (playerOneHp==0 || hpDiffOne > hpDiffTwo)
  1489. {
  1490. int pointDiff;
  1491. pointDiff = (playerOnePoints / 3);
  1492. playerTwoStat.set(POINTS, playerTwoPoints + pointDiff);
  1493. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  1494. _sm.addString(_playerTwo.getName());
  1495. broadcastMessage(_sm, true);
  1496. _sm2.addString(_playerTwo.getName());
  1497. _sm2.addNumber(pointDiff);
  1498. broadcastMessage(_sm2, true);
  1499. _sm3.addString(_playerOne.getName());
  1500. _sm3.addNumber(pointDiff);
  1501. broadcastMessage(_sm3, true);
  1502. _playerTwo = L2World.getInstance().getPlayer(_playerTwoName); // why this...
  1503. try {
  1504. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+hpDiffOne+" vs "+hpDiffTwo+") "+_playerTwoName+" win "+pointDiff+" points";
  1505. L2ItemInstance item = _playerTwo.getInventory().addItem("Olympiad", 6651, 30, _playerTwo, null);
  1506. InventoryUpdate iu = new InventoryUpdate();
  1507. iu.addModifiedItem(item);
  1508. _playerTwo.sendPacket(iu);
  1509. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1510. sm.addItemName(item.getItemId());
  1511. sm.addNumber(30);
  1512. _playerTwo.sendPacket(sm);
  1513. } catch (Exception e) { }
  1514. }
  1515. else
  1516. {
  1517. result=" tie";
  1518. _sm = new SystemMessage(SystemMessageId.THE_GAME_ENDED_IN_A_TIE);
  1519. broadcastMessage(_sm, true);
  1520. }
  1521. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... "+result);
  1522. playerOneStat.set(COMP_DONE, playerOnePlayed + 1);
  1523. playerTwoStat.set(COMP_DONE, playerTwoPlayed + 1);
  1524. _nobles.remove(_playerOneID);
  1525. _nobles.remove(_playerTwoID);
  1526. _nobles.put(_playerOneID, playerOneStat);
  1527. _nobles.put(_playerTwoID, playerTwoStat);
  1528. _sm = new SystemMessage(SystemMessageId.YOU_WILL_GO_BACK_TO_THE_VILLAGE_IN_S1_SECOND_S);
  1529. _sm.addNumber(20);
  1530. broadcastMessage(_sm, true);
  1531. }
  1532. protected void additions()
  1533. {
  1534. for (L2PcInstance player : _players)
  1535. {
  1536. try {
  1537. //Set HP/CP/MP to Max
  1538. player.setCurrentCp(player.getMaxCp());
  1539. player.setCurrentHp(player.getMaxHp());
  1540. player.setCurrentMp(player.getMaxMp());
  1541. //Wind Walk Buff for Both
  1542. L2Skill skill;
  1543. SystemMessage sm;
  1544. skill = SkillTable.getInstance().getInfo(1204, 2);
  1545. skill.getEffects(player, player);
  1546. player.broadcastPacket(new MagicSkillUse(player, player, skill.getId(), 2, skill.getHitTime(), 0));
  1547. sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  1548. sm.addSkillName(1204);
  1549. player.sendPacket(sm);
  1550. if (!player.isMageClass())
  1551. {
  1552. //Haste Buff to Fighters
  1553. skill = SkillTable.getInstance().getInfo(1086, 1);
  1554. skill.getEffects(player, player);
  1555. player.broadcastPacket(new MagicSkillUse(player, player, skill.getId(), 1, skill.getHitTime(), 0));
  1556. sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  1557. sm.addSkillName(1086);
  1558. player.sendPacket(sm);
  1559. }else{
  1560. //Acumen Buff to Mages
  1561. skill = SkillTable.getInstance().getInfo(1085, 1);
  1562. skill.getEffects(player, player);
  1563. player.broadcastPacket(new MagicSkillUse(player, player, skill.getId(), 1, skill.getHitTime(), 0));
  1564. sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  1565. sm.addSkillName(1085);
  1566. player.sendPacket(sm);
  1567. }
  1568. } catch (Exception e) { }
  1569. }
  1570. }
  1571. protected boolean makePlayersVisible()
  1572. {
  1573. _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  1574. try {
  1575. for (L2PcInstance player : _players)
  1576. {
  1577. player.getAppearance().setVisible();
  1578. player.broadcastUserInfo();
  1579. player.sendPacket(_sm);
  1580. if (player.getPet() != null)
  1581. player.getPet().updateAbnormalEffect();
  1582. }
  1583. } catch (NullPointerException e) { _aborted = true; return false; }
  1584. return true;
  1585. }
  1586. protected boolean makeCompetitionStart()
  1587. {
  1588. if (_playerOne == null || _playerTwo == null)
  1589. {
  1590. _aborted = true;
  1591. return false;
  1592. }
  1593. _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  1594. try {
  1595. for (L2PcInstance player : _players)
  1596. {
  1597. player.setIsOlympiadStart(true);
  1598. player.sendPacket(_sm);
  1599. }
  1600. } catch (Exception e) {
  1601. _aborted = true;
  1602. return false;
  1603. }
  1604. return true;
  1605. }
  1606. protected String getTitle()
  1607. {
  1608. String msg = "";
  1609. msg+= _playerOneName + " : " + _playerTwoName;
  1610. return msg;
  1611. }
  1612. protected L2PcInstance[] getPlayers()
  1613. {
  1614. L2PcInstance[] players = new L2PcInstance[2];
  1615. if (_playerOne == null || _playerTwo == null) return null;
  1616. players[0] = _playerOne;
  1617. players[1] = _playerTwo;
  1618. return players;
  1619. }
  1620. protected List<L2PcInstance> getSpectators()
  1621. {
  1622. return _spectators;
  1623. }
  1624. protected void addSpectator(L2PcInstance spec)
  1625. {
  1626. _spectators.add(spec);
  1627. }
  1628. protected void removeSpectator(L2PcInstance spec)
  1629. {
  1630. if (_spectators != null && _spectators.contains(spec))
  1631. _spectators.remove(spec);
  1632. }
  1633. protected void clearSpectators()
  1634. {
  1635. if (_spectators != null)
  1636. {
  1637. for (L2PcInstance pc : _spectators)
  1638. {
  1639. try {
  1640. if(!pc.inObserverMode()) continue;
  1641. pc.leaveOlympiadObserverMode();
  1642. } catch (NullPointerException e) {}
  1643. }
  1644. _spectators.clear();
  1645. }
  1646. }
  1647. private void broadcastMessage(SystemMessage sm, boolean toAll)
  1648. {
  1649. try { _playerOne.sendPacket(sm); } catch (Exception e) {}
  1650. try { _playerTwo.sendPacket(sm); } catch (Exception e) {}
  1651. if (toAll && _spectators != null)
  1652. {
  1653. for (L2PcInstance spec : _spectators)
  1654. {
  1655. try { spec.sendPacket(sm); } catch (NullPointerException e) {}
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }