/* * Gwiazdka oznaczylem uzyte juz komunikaty [Luno] *1639 The $s1st Olympiad period has started. *1640 The $s1st Olympiad period has ended. *1641 The Olympiad game has started. *1642 The Olympiad game has ended. 1651 The Olympiad game is not currently in progress. << _OlympiadPlayers; private Map _LastOlympiad; private List _LastOlympiadWiners; private int _sezon; private int _day; private int _during_fights; // -1 jeszcze sei nei zaczely, 0 trwaja, 1 juz sie skonczyly, 2,3 - _waitinglist; int waitingListSizeGeneral; // ile jest ogolnie na waiting liscie int waitingListSizeNotClass; // ile jest na liscie jako Not class-defined //Stadiony OlympiadArenas[] _stadions; public static GrandOlympiad getInstance() { if ( _instance == null ) _instance = new GrandOlympiad(); return _instance; } private GrandOlympiad() { _OlympiadPlayers = new FastMap(); _LastOlympiad = new FastMap(); _waitinglist = new FastMap(); _during_fights = -1; // przy uruchamianiu serwera nie jestesmy w trakcie walk, bo trzeba je zaczac // Wczytaj z SQL LoadOlympiadStatus(); if ( checkOlympiadSezon() == true ) // czyli jestesmy w trakcie sezonu { //update daty w statusie UpdateOlympiadStatus() // ustawia taska na koniec sezonu ThreadPoolManager.getInstance().scheduleEffect(new sezon_end(), ....); // ustawia taska na rozpoczecie rozgrywek w dniu dzisiejszym ThreadPoolManager.getInstance().scheduleEffect(new start_fights(), /* odrazu */); } else { //Jak jestesmy tutaj, to znaczy ze przegapilismy koniec sezonu SezonEnd(); // Czyszczenie tabel itd. rozpoczyna tez nowy sezon } LoadOlympiadPlayers(); // wczytuje zarowno aktualnych jak i tych z last olympiad :D //_stadions = new FastMap(); _stadions = new OlympiadArenas[23]; //Ladujemy Stadiony for ( int i=1; i < 23; i++ ) { _stadions[i] = null; } } public boolean isRegistered( int playerid ) { return _OlympiadPlayers.containsKey( playerid ); } public synchronized boolean RegisterPlayer( L2PcInstance player, boolean classgame ) { boolean succes = false; int gametype = 0; if( classgame ) { gametype = player.getBaseClass(); } if ( isRegistered( player.getObjectId() ) ) { //Gracz juz sie zarejestrowal - dodajemy go do waiting list :) //Gracz juz jest na waiting list if (_waitinglist.get(gametype).contains(player.getObjectId())) succes = false; else { _waitinglist.get(gametype).add(player.getObjectId()); waitingListSizeGeneral++; if(gametype==0) waitingListSizeNotClass++; succes = true; } } else { //Gracz napewno nie jest zarejestrowany - mozna go zarejestrowac OlympiadStats os = new OlympiadStats( player ); os.SetGameType( gametype ); _OlympiadPlayers.put( player.getObjectId(), os ); //Z tego chyba wyskoczy Nullpointer xD if (_waitinglist.get(gametype) != null) { //tymczasowo _waitinglist.get(gametype).add( player.getObjectId() ); } else _log.severe("Nullpointer: GrandOlympiad - 224"); waitingListSizeGeneral++; if(gametype==0) waitingListSizeNotClass++; Connection con = null; PreparedStatement statement = null; try { con = L2DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("INSERT INTO OlympiadPlayers (sezon, playerid, name, pkt, fights, defeats, victories, gametype) VALUES (?,?,?,?,?,?,?,?)"); statement.setInt(1, _sezon); // sezon statement.setInt(2, player.getObjectId()); // playerid statement.setString(3,player.getName()); // name statement.setInt(4, 18); // pkt statement.setInt(5, 0); // fights statement.setInt(6, 0); // defeats statement.setInt(7, 0); // victories statement.setInt(8, gametype); // gametype (classid albo 0 jezeli free for all) statement.execute(); statement.close(); con.close(); } catch(SQLException e) { _log.severe("OlympiadPlayers: Failed to save data: " + e); } finally { try { con.close(); //To nie powinno sie zdarzyc no chyba ze caly SQL lezy } catch (Exception e) {} } succes = true; } return succes; } public synchronized boolean UnregisterPlayer (L2PcInstance player) { // TODO@ Sa dwa komunikaty, z ktorych wynika ze mozna sie wypisac zarowno z calej olimpiady jak i tylko waiting listy // jak sie wiec wypisac z tego drugiego ? return false; } //Rejestracja jest tylko jakis czas przed olimpiada czy w trakcie?? //Kiedy dokladnie mozna anulowac?? public boolean CanBeHero( int playerid ) { return _LastOlympiadWiners.contains( playerid ); // To tylko po to, zeby moc sobie wlaczyc hero i wziac bron od statuly ? //tak } public int GetPlayerPts( int playerid ) { return _OlympiadPlayers.get( playerid ).GetOlympiadPoints(); } public int GetPlayerFights( int playerid ) { return _OlympiadPlayers.get( playerid ).GetFightCount(); } public int getWaitingListSizeGeneral() { return this.waitingListSizeGeneral; } public int getWaitingListSizeNotClass() { return this.waitingListSizeNotClass; } public void ChangeOlympiadStats(int playerid, int value ) { _OlympiadPlayers.get( playerid ).ChangeOlympiadStats( value ); } private void LoadOlympiadStatus() { // tabela: olympiad_status (sezon, day) <- poki co tyle. // insert into olympiad_status values (0,100); na poczatku ustawi poprawny Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT sezon, day FROM olympiad_status"); ResultSet rset = statement.executeQuery(); rset.next(); _sezon = rset.getInt( "sezon" ); _day = rset.getInt( "day" ); rset.close(); statement.close(); } catch(SQLException e) { _log.warning("could not load olympiad status :"+e.getMessage()); } finally { try { con.close(); }catch(Exception e){} } } private void UpdateOlympiadStatus() { Connection con = null; PreparedStatement statement = null; try { con = L2DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("UPDATE olympiad_status set sezon=?, day =?"); statement.setInt(1, _sezon); statement.setInt(2, _day); statement.execute(); statement.close(); con.close(); } catch(SQLException e) { _log.severe("olympiad_status: Failed to save data: " + e); } finally { try { con.close(); //To nie powinno sie zdarzyc no chyba ze caly SQL lezy } catch (Exception e) {} } } private void LoadOlympiadPlayers() { // Budowa tabeli: sezon,playerid,name,pkt,fights,defeats,victories,gametype Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT sezon,playerid,name,pts,fights,defeats,victories,gametype,sezon FROM OlympiadPlayers"); ResultSet rset = statement.executeQuery(); while( rset.next() ) { OlympiadStats os = new OlympiadStats( rset.getInt( "playerid" ), rset.getString( "name" ), rset.getInt( "pts" ), rset.getInt("fights"), rset.getInt("gametype"), rset.getInt("defeats"), rset.getInt("victories") ); if(rset.getInt("sezon") == _sezon ) _OlympiadPlayers.put( rset.getInt( "playerid" ), os ); else _LastOlympiad.put( rset.getInt( "playerid" ), os ); } rset.close(); statement.close(); } catch (SQLException e) { _log.warning("could not load from OlympiadPlayers :"+e.getMessage()); } finally { try { con.close(); } catch (Exception e) {} } } private void SezonStart() { /* Funkcja jest wywolana gdy normalnie sezon sie zaczyna, a takze gdy przegapilismy rozpoczecie*/ _sezon++; _day = /*aktualny dzien */; //update mysql UpdateOlympiadStatus(); ThreadPoolManager.getInstance().scheduleEffect(new start_fights(), ...); ThreadPoolManager.getInstance().scheduleEffect(new sezon_end(), ...)//chociaz serwer chyba nie da rady miesiac bez restartu, ale moze.... } private void SezonEnd() { //Mam na mysli to co dzieje sie na zakonczenie miesiaca //TODO@ przeczyscic SQL //aktualne dane graczy ustawic jako LastOlympiad //Dodac zwyciezcow na WinerList //Zapisac zmiany w SQL //Byli hero juz nie sa Hero - trzeba pozabierac statusy HeroTable.getInstance().cleartable(); //(smutne :D ) for (int id: _LastOlympiadWiners) { //TODO@ skrypt zabierajacy status hero z SQL (characters) //where character_id = id set ishero = 0 :) } /* jesli serwer wysypal sie przed zakonczeniem sezonu a wstal po rozpoczeciu nowego: */ if(checkOlympiadSezon() == false ) // w ogole, jesli przegapilismy { if(/* aktualna godzina (dzien itd)> data zwiazana z poczatkiem sezonu*/) { SezonStart(); } else // wysypal sie przed zakonczeniem sezonu, ale uruchomil przed rozpoczeciem nowego { ThreadPoolManager.getInstance().scheduleEffect(new sezon_begin(), ...);// po co duplikat ? } } ThreadPoolManager.getInstance().scheduleEffect(new sezon_begin(), ...); } private void FindPlayersForFights() { //TODO@ Posortuj i wybierz graczy do walki w odpowiednich //przedzialach klass i na odpowiednich stadionach L2PcInstance p1 = null; L2PcInstance p2 = null; Prepare(p1,p2,1); if(/* aktualna godzina + FIGHTS_INTERVAL*2(lub 3) < czas zwiazany z FIGHTS_STOP_TIME */) { ThreadPoolManager.getInstance().scheduleEffect(new start_fights(), FIGHTS_INTERVAL); /* po to , zeby okres walk sie nie konczyl gdy jakas walka jest w trakcie */ } } public void Prepare(L2PcInstance player1, L2PcInstance player2, int stadionid) { //1492 $s1 second later, you will move to the Olympiad Stadium. SystemMessage sm = new SystemMessage(1492); sm.addNumber(30); player1.sendPacket(sm); player2.sendPacket(sm); //po 30s teleportuj na stadion (moze zrobimy taki myk, ze gracz musi zatwierdzic to (glupio sciagac kogos AFK) - ciezko bedzie to zrobic :) ThreadPoolManager.getInstance().scheduleEffect(new PrepareToFight(player1, player2, stadionid), 30000); } public OlympiadArenas GetStadion(int id) { return _stadions[id]; } public void ClearStadion(int id) { _stadions[id] = null; } private boolean checkOlympiadSezon() { /* if dzisiejszy dzien >= day return true * else: */ return false } public void sendMessageToAll(int sysMsgId) { SystemMessage sm = new SystemMessage(sysMsgId); for (L2PcInstance player : L2World.getInstance().getAllPlayers()) player.sendPacket(sm); } // TODO@ 3 punkty dodawane co tydzien /* At the beginning of each Olympiad period, 18 points are equally awarded to all Noblesse, and 3 points each week thereafter. */ /* Participating in a competition is possible only through the Olympiad Master, and the hours of competition are 8:00 PM CST to 12:00 AM CST (8:00 PM GMT+1 to 12:00 AM GMT+1 on the Teon server). No competition requests are taken outside of competition hours. Competitors will be matched randomly and summoned to the coliseum for competition. - jednak losowo During the competition, a character whose HP has reached 0 will merely lose the competition, but not die. - nie ginie */ }