Advertisement
Guest User

Olympiad INTERLUDE

a guest
May 13th, 2010
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.66 KB | None | 0 0
  1. Index: /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/Olympiad.java
  2. ===================================================================
  3. --- /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/Olympiad.java (revision 7)
  4. +++ /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/Olympiad.java (revision 20)
  5. @@ -1,25 +1,2 @@
  6. -/*
  7. - * This program is free software; you can redistribute it and/or modify
  8. - * it under the terms of the GNU General Public License as published by
  9. - * the Free Software Foundation; either version 2, or (at your option)
  10. - * any later version.
  11. - *
  12. - * This program is distributed in the hope that it will be useful,
  13. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. - * GNU General Public License for more details.
  16. - *
  17. - * You should have received a copy of the GNU General Public License
  18. - * along with this program; if not, write to the Free Software
  19. - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. - * 02111-1307, USA.
  21. - *
  22. - * http://www.gnu.org/copyleft/gpl.html
  23. - */
  24. -
  25. -/**
  26. - * @author godson
  27. - */
  28. -
  29. package net.sf.l2j.gameserver;
  30.  
  31. @@ -99,14 +76,4 @@
  32. protected static final long VALIDATION_PERIOD = Config.ALT_OLY_VPERIOD; // 24 hours
  33.  
  34. - /* FOR TESTING
  35. - private static final int COMP_START = 8; // 1PM - 2PM
  36. - private static final int COMP_MIN = 15; // 20mins
  37. - private static final long COMP_PERIOD = 7200000; // 2hours
  38. - private static final long BATTLE_PERIOD = 180000; // 3mins
  39. - private static final long BATTLE_WAIT = 600000; // 10mins
  40. - private static final long INITIAL_WAIT = 300000; // 5mins
  41. - private static final long WEEKLY_PERIOD = 7200000; // 2 hours
  42. - private static final long VALIDATION_PERIOD = 3600000; // 1 hour */
  43. -
  44. private static final int COLLISIEUMS = 11; // 22 in all, 11 each for (Classed and NonClassed)
  45.  
  46. @@ -131,10 +98,10 @@
  47. protected static boolean _compStarted;
  48. protected static boolean _battleStarted;
  49. - protected ScheduledFuture _scheduledCompStart;
  50. - protected ScheduledFuture _scheduledCompEnd;
  51. - protected ScheduledFuture _scheduledOlympiadEnd;
  52. - protected ScheduledFuture _scheduledManagerTask;
  53. - protected ScheduledFuture _scheduledWeeklyTask;
  54. - protected ScheduledFuture _scheduledValdationTask;
  55. + protected ScheduledFuture<?> _scheduledCompStart;
  56. + protected ScheduledFuture<?> _scheduledCompEnd;
  57. + protected ScheduledFuture<?> _scheduledOlympiadEnd;
  58. + protected ScheduledFuture<?> _scheduledManagerTask;
  59. + protected ScheduledFuture<?> _scheduledWeeklyTask;
  60. + protected ScheduledFuture<?> _scheduledValdationTask;
  61.  
  62. protected static final int[][] STADIUMS =
  63. @@ -573,4 +540,11 @@
  64. return true;
  65. }
  66. +
  67. + public void removeDisconnectedCompetitor(L2PcInstance player)
  68. + {
  69. + if (_manager == null || (_manager.getOlympiadInstance(player.getOlympiadGameId()) == null)) return;
  70. +
  71. + _manager.getOlympiadInstance(player.getOlympiadGameId()).handleDisconnect(player);
  72. + }
  73.  
  74. private void updateCompStatus()
  75. @@ -837,4 +811,6 @@
  76. public List<L2PcInstance> getSpectators(int id)
  77. {
  78. + if (_manager == null || _manager.getOlympiadInstance(id) == null)
  79. + return null;
  80. return _manager.getOlympiadInstance(id).getSpectators();
  81. }
  82. @@ -1156,6 +1132,4 @@
  83. if (_nobles.size() == 0)
  84. return;
  85. -
  86. - _compStarted = true;
  87.  
  88. try{
  89. @@ -1184,10 +1158,16 @@
  90. }
  91.  
  92. + _compStarted = false;
  93. if (_olympiadInstances.size() == 0)
  94. - {
  95. - _compStarted = false;
  96. return;
  97. - }
  98. -
  99. + for (L2OlympiadGame instance : _olympiadInstances.values())
  100. + {
  101. + if (!instance.isAborted())
  102. + _compStarted = true;
  103. + }
  104. +
  105. + if (!_compStarted)
  106. + return;
  107. +
  108. for (L2OlympiadGame instance : _olympiadInstances.values())
  109. instance.sendMessageToPlayers(false,30);
  110. @@ -1248,7 +1228,8 @@
  111. {
  112. instance.makeCompetitionStart();
  113. - }
  114. -
  115. - //Wait 6 mins (Battle)
  116. + instance.makePlayersVisible();
  117. + }
  118. +
  119. + //Wait 6 minutes (Battle)
  120. try{
  121. wait(BATTLE_PERIOD);
  122. @@ -1402,4 +1383,6 @@
  123. protected COMP_TYPE _type;
  124. private boolean _aborted;
  125. + private boolean _playerOneDisconnected;
  126. + private boolean _playerTwoDisconnected;
  127. private String _playerOneName;
  128. private String _playerTwoName;
  129. @@ -1420,4 +1403,6 @@
  130. {
  131. _aborted = false;
  132. + _playerOneDisconnected = false;
  133. + _playerTwoDisconnected = false;
  134. _type = type;
  135. _stadiumPort = stadiumPort;
  136. @@ -1451,4 +1436,28 @@
  137. }
  138. }
  139. +
  140. + public boolean isAborted()
  141. + {
  142. + return _aborted;
  143. + }
  144. +
  145. + protected void clearPlayers()
  146. + {
  147. + _playerOne = null;
  148. + _playerTwo = null;
  149. + _players = null;
  150. + _playerOneName = "";
  151. + _playerTwoName = "";
  152. + _playerOneID = 0;
  153. + _playerTwoID = 0;
  154. + }
  155. +
  156. + protected void handleDisconnect(L2PcInstance player)
  157. + {
  158. + if (player == _playerOne)
  159. + _playerOneDisconnected = true;
  160. + else if (player == _playerTwo)
  161. + _playerTwoDisconnected = true;
  162. + }
  163.  
  164. protected void removals()
  165. @@ -1457,5 +1466,6 @@
  166.  
  167. if (_playerOne == null || _playerTwo == null) return;
  168. -
  169. + if (_playerOneDisconnected || _playerTwoDisconnected) return;
  170. +
  171. for (L2PcInstance player : _players)
  172. {
  173. @@ -1514,19 +1524,6 @@
  174. L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  175. if (wpn == null) wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  176. - if (wpn != null &&
  177. - (
  178. - (wpn.getItemId() >= 6611 && wpn.getItemId() <= 6621) ||
  179. - wpn.getItemId() == 6842 ||
  180. - wpn.getItemId() == 5597 ||
  181. - wpn.getItemId() == 5605 ||
  182. - wpn.getItemId() == 6314 ||
  183. - wpn.getItemId() == 7715 ||
  184. - wpn.getItemId() == 8119 ||
  185. - wpn.getItemId() == 8138 ||
  186. - wpn.getItemId() == 8146 ||
  187. - wpn.getItemId() == 8815
  188. - )
  189. - )
  190. - {
  191. + if (wpn != null && wpn.isHeroItem())
  192. + {
  193. L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  194. InventoryUpdate iu = new InventoryUpdate();
  195. @@ -1555,5 +1552,5 @@
  196. }
  197.  
  198. - //Remove ss/sps/bsps automation
  199. + //Remove shot automation
  200. Map<Integer, Integer> activeSoulShots = player.getAutoSoulShot();
  201. for (int itemId : activeSoulShots.values())
  202. @@ -1566,15 +1563,4 @@
  203. _sm.addNumber(120);
  204. broadcastMessage(_sm, false);
  205. - }
  206. -
  207. - protected void clearPlayers()
  208. - {
  209. - _playerOne = null;
  210. - _playerTwo = null;
  211. - _players = null;
  212. - _playerOneName = "";
  213. - _playerTwoName = "";
  214. - _playerOneID = 0;
  215. - _playerTwoID = 0;
  216. }
  217.  
  218. @@ -1584,16 +1570,6 @@
  219. _playerTwoLocation = new int[3];
  220.  
  221. - boolean _playerOneCrash = true;
  222. - boolean _playerTwoCrash = true;
  223. -
  224. - try {
  225. - if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  226. - _playerOneCrash=false;
  227. - } catch (Exception e) {}
  228. -
  229. - try {
  230. - if (_playerTwo != null && _playerTwo.getOlympiadGameId() != -1)
  231. - _playerTwoCrash=false;
  232. - } catch (Exception e){ }
  233. + boolean _playerOneCrash = (_playerOne == null || _playerOneDisconnected);
  234. + boolean _playerTwoCrash = (_playerTwo == null || _playerTwoDisconnected);
  235.  
  236. if (_playerOneCrash){
  237. @@ -1613,5 +1589,6 @@
  238. }
  239.  
  240. - if (_playerOneCrash || _playerTwoCrash){
  241. + if (_playerOneCrash || _playerTwoCrash || _aborted)
  242. + {
  243. _playerOne=null;
  244. _playerTwo=null;
  245. @@ -1629,12 +1606,12 @@
  246. _playerTwoLocation[2] = _playerTwo.getZ();
  247.  
  248. - //_playerOne.getAppearance().setInvisible();
  249. - //_playerOne.broadcastUserInfo();
  250. - //_playerOne.decayMe();
  251. - //_playerOne.spawnMe();
  252. - //_playerTwo.getAppearance().setInvisible();
  253. - //_playerTwo.broadcastUserInfo();
  254. - //_playerTwo.decayMe();
  255. - //_playerTwo.spawnMe();
  256. + _playerOne.getAppearance().setInvisible();
  257. + _playerOne.broadcastUserInfo();
  258. + _playerOne.decayMe();
  259. + _playerOne.spawnMe();
  260. + _playerTwo.getAppearance().setInvisible();
  261. + _playerTwo.broadcastUserInfo();
  262. + _playerTwo.decayMe();
  263. + _playerTwo.spawnMe();
  264.  
  265. if (_playerOne.isSitting())
  266. @@ -1647,6 +1624,6 @@
  267. _playerTwo.setTarget(null);
  268.  
  269. - _playerOne.teleToLocation(_stadiumPort[0], _stadiumPort[1], _stadiumPort[2], true);
  270. - _playerTwo.teleToLocation(_stadiumPort[0], _stadiumPort[1], _stadiumPort[2], true);
  271. + _playerOne.teleToLocation(_stadiumPort[0]+1100, _stadiumPort[1], _stadiumPort[2], true);
  272. + _playerTwo.teleToLocation(_stadiumPort[0]-1100, _stadiumPort[1], _stadiumPort[2], true);
  273.  
  274. _playerOne.setIsInOlympiadMode(true);
  275. @@ -1655,6 +1632,6 @@
  276. _playerTwo.setIsInOlympiadMode(true);
  277. _playerTwo.setIsOlympiadStart(false);
  278. - } catch (Exception e) {
  279. - return false;
  280. + } catch (NullPointerException e) {
  281. + return false;
  282. }
  283. return true;
  284. @@ -1724,5 +1701,5 @@
  285. protected void validateWinner()
  286. {
  287. - if (_aborted || (_playerOne == null && _playerTwo == null))
  288. + if (_aborted || (_playerOne == null && _playerTwo == null) || (_playerOneDisconnected && _playerTwoDisconnected))
  289. {
  290. _log.info("Olympia Result: "+_playerOneName+" vs "+_playerTwoName+" ... aborted/tie due to crashes!");
  291. @@ -1745,5 +1722,5 @@
  292. double hpDiffOne = 9999999;
  293. try{
  294. - if (_playerOne != null && _playerOne.getOlympiadGameId() != -1)
  295. + if (_playerOne != null && !_playerOneDisconnected)
  296. {
  297. playerOneHp = _playerOne.getCurrentHp()+_playerOne.getCurrentCp();
  298. @@ -1758,5 +1735,5 @@
  299. double hpDiffTwo = 9999999;
  300. try{
  301. - if (_playerTwo != null && _playerTwo.getOlympiadGameId()!=-1)
  302. + if (_playerTwo != null && !_playerTwoDisconnected)
  303. {
  304. playerTwoHp = _playerTwo.getCurrentHp()+_playerTwo.getCurrentCp();
  305. @@ -1774,5 +1751,11 @@
  306. String result = "";
  307.  
  308. - if (playerTwoHp==0 || hpDiffOne < hpDiffTwo)
  309. + // if players crashed, search if they've relogged
  310. + _playerOne = L2World.getInstance().getPlayer(_playerOneName);
  311. + _players.set(0, _playerOne);
  312. + _playerTwo = L2World.getInstance().getPlayer(_playerTwoName);
  313. + _players.set(1, _playerTwo);
  314. +
  315. + if ((playerTwoHp == 0 && playerOneHp != 0) || (hpDiffOne < hpDiffTwo && playerTwoHp != 0))
  316. {
  317. int pointDiff;
  318. @@ -1790,5 +1773,4 @@
  319. broadcastMessage(_sm3, true);
  320.  
  321. - _playerOne = L2World.getInstance().getPlayer(_playerOneName); // why this...
  322. try {
  323. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+hpDiffOne+" vs "+hpDiffTwo+") "+_playerOneName+" win "+pointDiff+" points";
  324. @@ -1804,5 +1786,5 @@
  325. } catch (Exception e) { }
  326. }
  327. - else if (playerOneHp==0 || hpDiffOne > hpDiffTwo)
  328. + else if ((playerOneHp == 0 && playerTwoHp != 0) || (hpDiffOne > hpDiffTwo && playerOneHp != 0))
  329. {
  330. int pointDiff;
  331. @@ -1811,14 +1793,13 @@
  332. playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  333.  
  334. - _sm.addString(_playerTwo.getName());
  335. + _sm.addString(_playerTwoName);
  336. broadcastMessage(_sm, true);
  337. - _sm2.addString(_playerTwo.getName());
  338. + _sm2.addString(_playerTwoName);
  339. _sm2.addNumber(pointDiff);
  340. broadcastMessage(_sm2, true);
  341. - _sm3.addString(_playerOne.getName());
  342. + _sm3.addString(_playerOneName);
  343. _sm3.addNumber(pointDiff);
  344. broadcastMessage(_sm3, true);
  345.  
  346. - _playerTwo = L2World.getInstance().getPlayer(_playerTwoName); // why this...
  347. try {
  348. result=" ("+playerOneHp+"hp vs "+playerTwoHp+"hp - "+hpDiffOne+" vs "+hpDiffTwo+") "+_playerTwoName+" win "+pointDiff+" points";
  349. @@ -1834,4 +1815,56 @@
  350. } catch (Exception e) { }
  351. }
  352. + else if (_playerOne == null || _playerOneDisconnected)
  353. + {
  354. + int pointDiff;
  355. + pointDiff = (playerOnePoints / 3);
  356. + playerTwoStat.set(POINTS, playerTwoPoints + pointDiff);
  357. + playerOneStat.set(POINTS, playerOnePoints - pointDiff);
  358. +
  359. + _sm.addString(_playerTwoName);
  360. + broadcastMessage(_sm, true);
  361. + _sm2.addString(_playerTwoName);
  362. + _sm2.addNumber(pointDiff);
  363. + broadcastMessage(_sm2, true);
  364. +
  365. + try {
  366. + result=" ("+_playerOne+" lost the game due crashes and "+_playerTwo+" won.";
  367. + L2ItemInstance item = _playerTwo.getInventory().addItem("Olympiad", 6651, 30, _playerTwo, null);
  368. + InventoryUpdate iu = new InventoryUpdate();
  369. + iu.addModifiedItem(item);
  370. + _playerTwo.sendPacket(iu);
  371. +
  372. + SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  373. + sm.addItemName(item.getItemId());
  374. + sm.addNumber(30);
  375. + _playerTwo.sendPacket(sm);
  376. + } catch (Exception e) { }
  377. + }
  378. + else if (_playerTwo == null || _playerTwoDisconnected)
  379. + {
  380. + int pointDiff;
  381. + pointDiff = (playerTwoPoints / 3);
  382. + playerOneStat.set(POINTS, playerOnePoints + pointDiff);
  383. + playerTwoStat.set(POINTS, playerTwoPoints - pointDiff);
  384. +
  385. + _sm.addString(_playerOneName);
  386. + broadcastMessage(_sm, true);
  387. + _sm2.addString(_playerOneName);
  388. + _sm2.addNumber(pointDiff);
  389. + broadcastMessage(_sm2, true);
  390. +
  391. + try {
  392. + result=" ("+_playerTwo+" lost the game due crashes and "+_playerOne+" won.";
  393. + L2ItemInstance item = _playerOne.getInventory().addItem("Olympiad", 6651, 30, _playerOne, null);
  394. + InventoryUpdate iu = new InventoryUpdate();
  395. + iu.addModifiedItem(item);
  396. + _playerOne.sendPacket(iu);
  397. +
  398. + SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  399. + sm.addItemName(item.getItemId());
  400. + sm.addNumber(30);
  401. + _playerOne.sendPacket(sm);
  402. + } catch (Exception e) { }
  403. + }
  404. else
  405. {
  406. @@ -1918,11 +1951,7 @@
  407. protected boolean makeCompetitionStart()
  408. {
  409. - if (_playerOne == null || _playerTwo == null)
  410. - {
  411. - _aborted = true;
  412. - return false;
  413. - }
  414. -
  415. - _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  416. + if (_aborted) return false;
  417. +
  418. + _sm = new SystemMessage(SystemMessageId.STARTS_THE_GAME);
  419.  
  420. try {
  421. @@ -1991,13 +2020,15 @@
  422. private void broadcastMessage(SystemMessage sm, boolean toAll)
  423. {
  424. - try { _playerOne.sendPacket(sm); } catch (Exception e) {}
  425. - try { _playerTwo.sendPacket(sm); } catch (Exception e) {}
  426. + try {
  427. + _playerOne.sendPacket(sm);
  428. + _playerTwo.sendPacket(sm);
  429. + } catch (Exception e) {}
  430.  
  431. if (toAll && _spectators != null)
  432. {
  433. - for (L2PcInstance spec : _spectators)
  434. - {
  435. - try { spec.sendPacket(sm); } catch (NullPointerException e) {}
  436. - }
  437. + for (L2PcInstance spec : _spectators)
  438. + {
  439. + try { spec.sendPacket(sm); } catch (NullPointerException e) {}
  440. + }
  441. }
  442. }
  443. Index: /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/L2ItemInstance.java
  444. ===================================================================
  445. --- /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/L2ItemInstance.java (revision 2)
  446. +++ /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/L2ItemInstance.java (revision 21)
  447. @@ -491,4 +491,9 @@
  448. {
  449. return _item.isStackable();
  450. + }
  451. +
  452. + public boolean isHeroItem()
  453. + {
  454. + return ((_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842);
  455. }
  456.  
  457. Index: /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  458. ===================================================================
  459. --- /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 10)
  460. +++ /trunk/L2_Gameserver/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 21)
  461. @@ -9405,7 +9405,10 @@
  462. try { decayMe(); } catch (Throwable t) {_log.log(Level.SEVERE, "deleteMe()", t); }
  463.  
  464. - // If a Party is in progress, leave it
  465. + // If a Party or Festival is in progress, leave it
  466. if (isInParty()) try { leaveParty(); } catch (Throwable t) {_log.log(Level.SEVERE, "deleteMe()", t); }
  467.  
  468. + if (getOlympiadGameId() != -1)
  469. + Olympiad.getInstance().removeDisconnectedCompetitor(this);
  470. +
  471. // If the L2PcInstance has Pet, unsummon it
  472. if (getPet() != null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement