Jump to content
  • 0

REQUEST [HELP]


Question

Posted

Xerete! 

 oi efialtes pou vlepoume merikes fores!!!

http://prntscr.com/hl3uol

http://prntscr.com/hl3vm2

http://prntscr.com/hl3vqw

 

 

 

/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.gameserver.communitybbs.tasks;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.l2j.Config;
import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ThreadPoolManager;

public class PlayerStatsUpdateTask
  {
       static Logger _log = Logger.getLogger(PlayerStatsUpdateTask.class.getName());
       private static StringBuilder _pvpList = new StringBuilder();
       private static StringBuilder _pkList = new StringBuilder();
       private static StringBuilder _raidList = new StringBuilder();
       private static StringBuilder _adenaList = new StringBuilder();      
       private static StringBuilder _onlineList = new StringBuilder();
       private static String _lastUpdate = "error";
       Connection con = L2DatabaseFactory.getInstance().getConnection();      
      
       public static void updateTask()
       {
               _log.log(Level.INFO, "[CommunityBoard]: Started player stats update task!");
              
               ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
           {
                       @Override
                       public void run()
                   {
                       PlayerStatsUpdateTask.cleanUpTask();
                       PlayerStatsUpdateTask.updatePvPList();
                       PlayerStatsUpdateTask.updatePkList();
                       PlayerStatsUpdateTask.updateRaidList();
                       PlayerStatsUpdateTask.updateAdenaList();
                       PlayerStatsUpdateTask.updateOnlineList();
                      
                       Date date = new Date();
                       PlayerStatsUpdateTask.lastUpdate(date.toString());                             
                   }
           }, 1000L, 600000L);
       }
      
       static void cleanUpTask()
       {
               _pvpList.delete(0, _pvpList.length());
           _pkList.delete(0, _pkList.length());
           _raidList.delete(0, _raidList.length());
           _adenaList.delete(0, _adenaList.length());
           _onlineList.delete(0, _onlineList.length());               
       }
      
        static void updatePvPList()
        {
                try
                {
                        Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
                    try
                    {
                        int pos = 0;
                        
                        PreparedStatement statement = con.prepareStatement("SELECT SUM(chr.points), SUM(it.count), ch.char_name, ch.pkkills, ch.pvpkills, ch.onlinetime, ch.base_class, ch.online FROM characters ch LEFT JOIN character_raid_points chr ON ch.obj_Id=chr.char_id LEFT OUTER JOIN items it ON ch.obj_Id=it.owner_id WHERE item_id=57 GROUP BY ch.obj_Id ORDER BY pvpkills DESC LIMIT " + Config.TOP_PLAYER_RESULTS);
                        ResultSet result = statement.executeQuery();
                        while (result.next()) 
                        {
                                pos++;
                                boolean status = false;
                                if (result.getInt("online") == 1)
                                {
                                        status = true;
                                }
                            String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
                            String adenas = getAdenas(result.getInt("SUM(it.count)"));                          

                            _pvpList.append("<table border=0 cellspacing=0 cellpadding=2 height=" + Config.TOP_PLAYER_ROW_HEIGHT + " width=610><tr><td FIXWIDTH=5></td>");
                            _pvpList.append("<td FIXWIDTH=25>" + pos + "</td>");
                            _pvpList.append("<td FIXWIDTH=180>" + result.getString("ch.char_name") + "</td>");
                            _pvpList.append("<td FIXWIDTH=175>" + className(result.getInt("base_class")) + "</td>");
                            _pvpList.append("<td FIXWIDTH=60>" + result.getInt("ch.pvpkills") + "</td>");
                            _pvpList.append("<td FIXWIDTH=60>" + result.getInt("ch.pkkills") + "</td>");
                            _pvpList.append("<td FIXWIDTH=70>" + result.getInt("SUM(chr.points)") + "</td>");
                            _pvpList.append("<td FIXWIDTH=140>" + adenas + "</td>");
                            _pvpList.append("<td FIXWIDTH=150>" + timeon + "</td>");
                            _pvpList.append("<td FIXWIDTH=65>" + (status ? "<font color=99FF00>Online</font>" : "<font color=CC0000>Offline</font>") + "</td>");
                            _pvpList.append("</tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");                       
                        }
                        result.close();
                        statement.close();
                    }
                    catch (Throwable localThrowable1)
                    {
                        localThrowable3 = localThrowable1;throw localThrowable1;
                    }
                    finally
                    {
                        if (con != null)
                        {
                                if (localThrowable3 != null)
                                {
                                        try
                                        {
                                                con.close();
                                        }
                                        catch (Throwable localThrowable2)
                                        {
                                                localThrowable3.addSuppressed(localThrowable2);
                                        }
                                }
                                else
                                {
                                        con.close();
                                }
                        }
                    }
                }
                catch (Exception e)
                {
                        _log.log(Level.WARNING, "Failed to update pvp list!");
                        e.printStackTrace();
                }
        }
        
        static void updatePkList()
        {
                try
                {
                        Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
                        try
                        {
                                int pos = 0;
                                
                                PreparedStatement statement = con.prepareStatement("SELECT SUM(chr.points), SUM(it.count), ch.char_name, ch.pkkills, ch.pvpkills, ch.onlinetime, ch.base_class, ch.online FROM characters ch LEFT JOIN character_raid_points chr ON ch.obj_Id=chr.char_id LEFT OUTER JOIN items it ON ch.obj_Id=it.owner_id WHERE item_id=57 GROUP BY ch.obj_Id ORDER BY pkkills DESC LIMIT " + Config.TOP_PLAYER_RESULTS);
                            ResultSet result = statement.executeQuery();
                            while (result.next())
                            {
                                pos++;
                                boolean status = false;
                                if (result.getInt("online") == 1)
                                {
                                        status = true;
                                }
                                String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
                                String adenas = getAdenas(result.getInt("SUM(it.count)"));
                                
                                _pkList.append("<table border=0 cellspacing=0 cellpadding=2 height=" + Config.TOP_PLAYER_ROW_HEIGHT + " width=610><tr><td FIXWIDTH=5></td>");
                                _pkList.append("<td FIXWIDTH=25>" + pos + "</td>");
                                _pkList.append("<td FIXWIDTH=180>" + result.getString("ch.char_name") + "</td>");
                                _pkList.append("<td FIXWIDTH=175>" + className(result.getInt("base_class")) + "</td>");
                                _pkList.append("<td FIXWIDTH=60>" + result.getInt("ch.pvpkills") + "</td>");
                                _pkList.append("<td FIXWIDTH=60>" + result.getInt("ch.pkkills") + "</td>");
                                _pkList.append("<td FIXWIDTH=70>" + result.getInt("SUM(chr.points)") + "</td>");
                                _pkList.append("<td FIXWIDTH=140>" + adenas + "</td>");
                                _pkList.append("<td FIXWIDTH=150>" + timeon + "</td>");
                                _pkList.append("<td FIXWIDTH=65>" + (status ? "<font color=99FF00>Online</font>" : "<font color=CC0000>Offline</font>") + "</td>");
                                _pkList.append("</tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");                                
                            }
                            result.close();
                            statement.close();
                        }
                        catch (Throwable localThrowable1)
                        {
                                localThrowable3 = localThrowable1;throw localThrowable1;
                        }
                        finally
                        {
                                if (con != null)
                                {
                                        if (localThrowable3 != null)
                                        {
                                                try
                                                {
                                                        con.close();
                                                }
                                                catch (Throwable localThrowable2)
                                                {
                                                        localThrowable3.addSuppressed(localThrowable2);
                                                }
                                        }
                                        else
                                        {
                                                con.close();
                                        }
                                }
                        }
                }
                catch (Exception e)
                {
                        _log.log(Level.WARNING, "Failed to update pk list!");
                        e.printStackTrace();
                }
        }
        
        static void updateRaidList()
        {
                try
                {
                        Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
                        try
                        {
                                int pos = 0;
                                        
                                PreparedStatement statement = con.prepareStatement("SELECT SUM(chr.points), SUM(it.count), ch.char_name, ch.pkkills, ch.pvpkills, ch.onlinetime, ch.base_class, ch.online FROM characters ch LEFT JOIN character_raid_points chr ON ch.obj_Id=chr.char_id LEFT OUTER JOIN items it ON ch.obj_Id=it.owner_id WHERE item_id=57 GROUP BY ch.obj_Id ORDER BY SUM(chr.points) DESC LIMIT " + Config.TOP_PLAYER_RESULTS);
                                ResultSet result = statement.executeQuery();
                                while (result.next())
                                {
                                        pos++;
                                    boolean status = false;
                                    if (result.getInt("online") == 1)
                                    {
                                        status = true;
                                    }
                                    String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
                                    String adenas = getAdenas(result.getInt("SUM(it.count)"));
                                        
                                    _raidList.append("<table border=0 cellspacing=0 cellpadding=2 height=" + Config.TOP_PLAYER_ROW_HEIGHT + " width=610><tr><td FIXWIDTH=5></td>");
                                    _raidList.append("<td FIXWIDTH=25>" + pos + "</td>");
                                    _raidList.append("<td FIXWIDTH=180>" + result.getString("ch.char_name") + "</td>");
                                    _raidList.append("<td FIXWIDTH=175>" + className(result.getInt("base_class")) + "</td>");
                                    _raidList.append("<td FIXWIDTH=60>" + result.getInt("ch.pvpkills") + "</td>");
                                    _raidList.append("<td FIXWIDTH=60>" + result.getInt("ch.pkkills") + "</td>");
                                    _raidList.append("<td FIXWIDTH=70>" + result.getInt("SUM(chr.points)") + "</td>");
                                    _raidList.append("<td FIXWIDTH=140>" + adenas + "</td>");
                                    _raidList.append("<td FIXWIDTH=150>" + timeon + "</td>");
                                    _raidList.append("<td FIXWIDTH=65>" + (status ? "<font color=99FF00>Online</font>" : "<font color=CC0000>Offline</font>") + "</td>");
                                    _raidList.append("</tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
                                }
                                result.close();
                                statement.close();
                        }
                        catch (Throwable localThrowable1)
                        {
                                localThrowable3 = localThrowable1;throw localThrowable1;
                        }
                        finally
                        {
                                if (con != null)
                                {
                                        if (localThrowable3 != null)
                                        {
                                                try
                                                {
                                                        con.close();
                                                }
                                                catch (Throwable localThrowable2)
                                            {
                                                        localThrowable3.addSuppressed(localThrowable2);
                                            }
                                        }
                                        else
                                        {
                                                con.close();
                                        }
                                }
                        }
                }
                catch (Exception e)
                {
                        _log.log(Level.WARNING, "Failed to update raid list!");
                        e.printStackTrace();
                }
        }
        
        static void updateAdenaList()
        {
                try
                {
                        Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
                        try
                        {
                                int pos = 0;
                                
                            PreparedStatement statement = con.prepareStatement("SELECT SUM(chr.points), SUM(it.count), ch.char_name, ch.pkkills, ch.pvpkills, ch.onlinetime, ch.base_class, ch.online FROM characters ch LEFT JOIN character_raid_points chr ON ch.obj_Id=chr.char_id LEFT OUTER JOIN items it ON ch.obj_Id=it.owner_id WHERE item_id=57 GROUP BY ch.obj_Id ORDER BY SUM(it.count) DESC LIMIT " + Config.TOP_PLAYER_RESULTS);
                            ResultSet result = statement.executeQuery();
                            while (result.next())
                            {
                                pos++;
                                boolean status = false;
                                if (result.getInt("online") == 1)
                                {
                                        status = true;
                                }
                                String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
                                String adenas = getAdenas(result.getInt("SUM(it.count)"));
                                
                                _adenaList.append("<table border=0 cellspacing=0 cellpadding=2 height=" + Config.TOP_PLAYER_ROW_HEIGHT + " width=610><tr><td FIXWIDTH=5></td>");
                                _adenaList.append("<td FIXWIDTH=25>" + pos + "</td>");
                                _adenaList.append("<td FIXWIDTH=180>" + result.getString("ch.char_name") + "</td>");
                                _adenaList.append("<td FIXWIDTH=175>" + className(result.getInt("base_class")) + "</td>");
                                _adenaList.append("<td FIXWIDTH=60>" + result.getInt("ch.pvpkills") + "</td>");
                                _adenaList.append("<td FIXWIDTH=60>" + result.getInt("ch.pkkills") + "</td>");
                                _adenaList.append("<td FIXWIDTH=70>" + result.getInt("SUM(chr.points)") + "</td>");
                                _adenaList.append("<td FIXWIDTH=140>" + adenas + "</td>");
                                _adenaList.append("<td FIXWIDTH=150>" + timeon + "</td>");
                                _adenaList.append("<td FIXWIDTH=65>" + (status ? "<font color=99FF00>Online</font>" : "<font color=CC0000>Offline</font>") + "</td>");
                                _adenaList.append("</tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");                                                                                             
                            }
                            result.close();
                            statement.close();
                        }
                        catch (Throwable localThrowable1)
                        {
                                localThrowable3 = localThrowable1;throw localThrowable1;
                        }
                        finally
                        {
                                if (con != null)
                                {
                                        if (localThrowable3 != null)
                                        {
                                                try
                                                {
                                                        con.close();
                                                }
                                                catch (Throwable localThrowable2)
                                                {
                                                        localThrowable3.addSuppressed(localThrowable2);
                                                }
                                        }
                                        else
                                        {
                                                con.close();
                                        }
                                }
                        }
                }
                catch (Exception e)
                {
                        _log.log(Level.WARNING, "Failed to update adena list!");
                        e.printStackTrace();
                }
        }
        
        static void updateOnlineList()
        {
                try
                {
                        Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
                        try
                        {
                                int pos = 0;
                            PreparedStatement statement = con.prepareStatement("SELECT SUM(chr.points), SUM(it.count), ch.char_name, ch.pkkills, ch.pvpkills, ch.onlinetime, ch.base_class, ch.online FROM characters ch LEFT JOIN character_raid_points chr ON ch.obj_Id=chr.char_id LEFT OUTER JOIN items it ON ch.obj_Id=it.owner_id WHERE item_id=57 GROUP BY ch.obj_Id ORDER BY onlinetime DESC LIMIT " + Config.TOP_PLAYER_RESULTS);
                            ResultSet result = statement.executeQuery();
                            while (result.next())     
                            {
                                pos++;
                                boolean status = false;
                                if (result.getInt("online") == 1)
                                {
                                        status = true;
                                }
                                String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
                                String adenas = getAdenas(result.getInt("SUM(it.count)"));
                                
                                _onlineList.append("<table border=0 cellspacing=0 cellpadding=2 height=" + Config.TOP_PLAYER_ROW_HEIGHT + " width=610><tr><td FIXWIDTH=5></td>");
                                _onlineList.append("<td FIXWIDTH=25>" + pos + "</td>");
                                _onlineList.append("<td FIXWIDTH=180>" + result.getString("ch.char_name") + "</td>");
                                _onlineList.append("<td FIXWIDTH=175>" + className(result.getInt("base_class")) + "</td>");
                                _onlineList.append("<td FIXWIDTH=60>" + result.getInt("ch.pvpkills") + "</td>");
                                _onlineList.append("<td FIXWIDTH=60>" + result.getInt("ch.pkkills") + "</td>");
                                _onlineList.append("<td FIXWIDTH=70>" + result.getInt("SUM(chr.points)") + "</td>");
                                _onlineList.append("<td FIXWIDTH=140>" + adenas + "</td>");
                                _onlineList.append("<td FIXWIDTH=150>" + timeon + "</td>");
                                _onlineList.append("<td FIXWIDTH=65>" + (status ? "<font color=99FF00>Online</font>" : "<font color=CC0000>Offline</font>") + "</td>");
                                _onlineList.append("</tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");                            
                            }
                            result.close();
                            statement.close();
                        }
                        catch (Throwable localThrowable1)
                        {
                                localThrowable3 = localThrowable1;throw localThrowable1;
                        }
                        finally
                        {
                                if (con != null)
                                {
                                        if (localThrowable3 != null)
                                        {
                                                try
                                                {
                                                        con.close();
                                                }
                                                catch (Throwable localThrowable2)
                                                {
                                                        localThrowable3.addSuppressed(localThrowable2);
                                                }
                                        }
                                        else
                                        {
                                                con.close();
                                        }
                                }
                        }
                }
                catch (Exception e)
                {
                        _log.log(Level.WARNING, "Failed to update online time list!");
                    e.printStackTrace();
                }
        }
        
        public static String pvpList()
        {
                return _pvpList.toString();
        }
        
        public static String pkList()
        {
            return _pkList.toString();
        }
        
        public static String raidList()
        {
            return _raidList.toString();
        }
        
        public static String adenaList()
        {
            return _adenaList.toString();
        }
        
        public static String onlineList()
        {
            return _onlineList.toString();
        }
        
        static void lastUpdate(String format)
        {
            _lastUpdate = format;
        }
        
        public static String getLastUpdate()
        {
            return _lastUpdate;
        }       
        
        public static final String className(int classid)
        {
                Map<Integer, String> classList = new HashMap<>();
                
                classList.put(Integer.valueOf(0), "Fighter");
            classList.put(Integer.valueOf(1), "Warrior");
                classList.put(Integer.valueOf(2), "Gladiator");
                classList.put(Integer.valueOf(3), "Warlord");
                classList.put(Integer.valueOf(4), "Knight");
                classList.put(Integer.valueOf(5), "Paladin");
                classList.put(Integer.valueOf(6), "Dark Avenger");
                classList.put(Integer.valueOf(7), "Rogue");
                classList.put(Integer.valueOf(8), "Treasure Hunter");
            classList.put(Integer.valueOf(9), "Hawkeye");
                classList.put(Integer.valueOf(10), "Mage");
                classList.put(Integer.valueOf(11), "Wizard");
                classList.put(Integer.valueOf(12), "Sorcerer");
                classList.put(Integer.valueOf(13), "Necromancer");
                classList.put(Integer.valueOf(14), "Warlock");
                classList.put(Integer.valueOf(15), "Cleric");
                classList.put(Integer.valueOf(16), "Bishop");
                classList.put(Integer.valueOf(17), "Prophet");
                classList.put(Integer.valueOf(18), "Elven Fighter");
                classList.put(Integer.valueOf(19), "Elven Knight");
                classList.put(Integer.valueOf(20), "Temple Knight");
                classList.put(Integer.valueOf(21), "Swordsinger");
                classList.put(Integer.valueOf(22), "Elven Scout");
                classList.put(Integer.valueOf(23), "Plains Walker");
                classList.put(Integer.valueOf(24), "Silver Ranger");
                classList.put(Integer.valueOf(25), "Elven Mage");
                classList.put(Integer.valueOf(26), "Elven Wizard");
                classList.put(Integer.valueOf(27), "Spellsinger");
                classList.put(Integer.valueOf(28), "Elemental Summoner");
                classList.put(Integer.valueOf(29), "Oracle");
                classList.put(Integer.valueOf(30), "Elder");
                classList.put(Integer.valueOf(31), "Dark Fighter");
                classList.put(Integer.valueOf(32), "Palus Knightr");
                classList.put(Integer.valueOf(33), "Shillien Knight");
                classList.put(Integer.valueOf(34), "Bladedancer");
                classList.put(Integer.valueOf(35), "Assasin");
                classList.put(Integer.valueOf(36), "Abyss Walker");
                classList.put(Integer.valueOf(37), "Phantom Ranger");
                classList.put(Integer.valueOf(38), "Dark Mage");
                classList.put(Integer.valueOf(39), "Dark Wizard");
                classList.put(Integer.valueOf(40), "Spellhowler");
                classList.put(Integer.valueOf(41), "Phantom Summoner");
                classList.put(Integer.valueOf(42), "Shillien Oracle");
                classList.put(Integer.valueOf(43), "Shilien Elder");
                classList.put(Integer.valueOf(44), "Orc Fighter");
                classList.put(Integer.valueOf(45), "Orc Raider");
                classList.put(Integer.valueOf(46), "Destroyer");
                classList.put(Integer.valueOf(47), "Orc Monk");
                classList.put(Integer.valueOf(48), "Tyrant");
                classList.put(Integer.valueOf(49), "Orc Mage");
                classList.put(Integer.valueOf(50), "Orc Shaman");
                classList.put(Integer.valueOf(51), "Overlord");
                classList.put(Integer.valueOf(52), "Warcryer");
                classList.put(Integer.valueOf(53), "Dwarven Fighter");
                classList.put(Integer.valueOf(54), "Scavenger");
                classList.put(Integer.valueOf(55), "Bounty Hunter");
                classList.put(Integer.valueOf(56), "Artisan");
                classList.put(Integer.valueOf(57), "Warsmith");
                classList.put(Integer.valueOf(88), "Duelist");
                classList.put(Integer.valueOf(89), "Dreadnought");
                classList.put(Integer.valueOf(90), "Phoenix Knight");
                classList.put(Integer.valueOf(91), "Hell Knight");
                classList.put(Integer.valueOf(92), "Sagittarius");
                classList.put(Integer.valueOf(93), "Adventurer");
                classList.put(Integer.valueOf(94), "Archmage");
                classList.put(Integer.valueOf(95), "Soultaker");
                classList.put(Integer.valueOf(96), "Arcana Lord");
                classList.put(Integer.valueOf(97), "Cardinal");
                classList.put(Integer.valueOf(98), "Hierophant");
                classList.put(Integer.valueOf(99), "Evas Templar");
                classList.put(Integer.valueOf(100), "Sword Muse");
                classList.put(Integer.valueOf(101), "Wind Rider");
                classList.put(Integer.valueOf(102), "Moonlight Sentinel");
                classList.put(Integer.valueOf(103), "Mystic Muse");
                classList.put(Integer.valueOf(104), "Elemental Master");
                classList.put(Integer.valueOf(105), "Evas Saint");
                classList.put(Integer.valueOf(106), "Shillien Templar");
                classList.put(Integer.valueOf(107), "Spectral Dancer");
                classList.put(Integer.valueOf(108), "Ghost Hunter");
                classList.put(Integer.valueOf(109), "Ghost Sentinel");
                classList.put(Integer.valueOf(110), "Storm Screamer");
                classList.put(Integer.valueOf(111), "Spectral Master");
                classList.put(Integer.valueOf(112), "Shillien Saint");
                classList.put(Integer.valueOf(113), "Titan");
                classList.put(Integer.valueOf(114), "Grand Khavatari");
                classList.put(Integer.valueOf(115), "Dominator");
                classList.put(Integer.valueOf(116), "Doomcryer");
                classList.put(Integer.valueOf(117), "Fortune Seeker");
                classList.put(Integer.valueOf(118), "Maestro");
                  
                return classList.get(Integer.valueOf(classid));                 
        }
        
        static String getPlayerRunTime(int secs)
        {
                String timeResult = "";
                if (secs >= 86400)
                {
                        timeResult = Integer.toString(secs / 86400) + " Days " + Integer.toString(secs % 86400 / 3600) + " hours";
                }
                else
                {
                        timeResult = Integer.toString(secs / 3600) + " Hours " + Integer.toString(secs % 3600 / 60) + " mins";
                }
                return timeResult;
        }
        
        static String getAdenas(int adena)
        {
                String adenas = "";
                if (adena >= 1000000000)
                {
                        adenas = Integer.toString(adena / 1000000000) + " Billion " + Integer.toString(adena % 1000000000 / 1000000) + " million";
                }
                else
                {
                        adenas = Integer.toString(adena / 1000000) + " Million " + Integer.toString(adena % 1000000 / 1000) + " k";
                }
                return adenas;
        }
}

2 answers to this question

Recommended Posts

  • 0
Posted (edited)
try to change
String timeon = getPlayerRunTime(result.getInt("ch.onlinetime"));
String adenas = getAdenas(result.getInt("SUM(it.count)")); 

to

String timeon = getPlayerRunTime(result.getLong("ch.onlinetime"));
String adenas = getAdenas(result.getLong("SUM(it.count)")); 

you also need to change

static String getPlayerRunTime

and

static String getAdenas

to long

 

Edited by Zacapa
Guest
This topic is now closed to further replies.


  • Posts

    • package ai.npc.NFWalker; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import l2r.gameserver.enums.CtrlIntention; import l2r.gameserver.model.Location; import l2r.gameserver.model.actor.L2Npc; import l2r.gameserver.model.quest.Quest; import l2r.gameserver.network.clientpackets.Say2; import l2r.gameserver.network.serverpackets.NpcSay; public class NFWalkerAI extends Quest { private static final int WALKER_NPC_ID = 20116; private final Map<String, Route> routes = new HashMap<>(); private final Map<Integer, Integer> npcIndexes = new HashMap<>(); private final Map<Integer, Boolean> npcReverse = new HashMap<>(); private final Map<Integer, String> npcCurrentRoute = new HashMap<>(); public NFWalkerAI() { super(-1, NFWalkerAI.class.getSimpleName(), "ai/npc/NFWalker"); loadRoutes(); addSpawnId(WALKER_NPC_ID); } private void loadRoutes() { // Route 1 Data Route route1 = new Route("route1"); route1.addPoint(new RoutePoint(0, 149363, 172341, -941, 0, false, "")); route1.addPoint(new RoutePoint(1, 148568, 172328, -980, 5, true, "Puff")); route1.addPoint(new RoutePoint(2, 148536, 172792, -980, 0, false, "")); // Route 2 Data Route route2 = new Route("route2"); route2.addPoint(new RoutePoint(0, 149363, 172341, -941, 0, false, "")); route2.addPoint(new RoutePoint(1, 150248, 172328, -980, 5, true, "Rise my children! Bring me the servants of the god! Let them be offered to our god Bifrons!")); route2.addPoint(new RoutePoint(2, 150248, 172776, -980, 0, false, "")); // Add routes to the map routes.put("route1", route1); routes.put("route2", route2); } @Override public String onSpawn(L2Npc npc) { if (npc.getId() == WALKER_NPC_ID) { selectInitialRouteForNpc(npc); } return super.onSpawn(npc); } @Override public String onAdvEvent(String event, L2Npc npc, l2r.gameserver.model.actor.instance.L2PcInstance player) { if (event.equalsIgnoreCase("move")) { moveNpc(npc); } else if (event.equalsIgnoreCase("check_reached")) { checkIfReached(npc); } return null; } private void moveNpc(L2Npc npc) { String routeName = npcCurrentRoute.get(npc.getObjectId()); Route route = routes.get(routeName); Integer pointIndex = npcIndexes.get(npc.getObjectId()); if (route != null && pointIndex != null) { RoutePoint point = route.getPoints().get(pointIndex); if (point.isRun()) { npc.setRunning(); } else { npc.setWalking(); } if (!point.getChat().isEmpty()) { npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), point.getChat())); } npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(point.getX(), point.getY(), point.getZ())); // Log movement intention System.out.println("NPC " + npc.getObjectId() + " moving to " + point.getX() + ", " + point.getY() + ", " + point.getZ()); // Schedule a check to see if the NPC has reached its destination startQuestTimer("check_reached", 1000, npc, null); } } private void checkIfReached(L2Npc npc) { String routeName = npcCurrentRoute.get(npc.getObjectId()); Route route = routes.get(routeName); Integer pointIndex = npcIndexes.get(npc.getObjectId()); if (route != null && pointIndex != null) { RoutePoint point = route.getPoints().get(pointIndex); Location currentLocation = npc.getLocation(); Location targetLocation = new Location(point.getX(), point.getY(), point.getZ()); // Check if the NPC has reached the target location if (currentLocation.equals(targetLocation)) { // Log that the NPC has reached the target System.out.println("NPC " + npc.getObjectId() + " reached target " + targetLocation); // Schedule the next movement startQuestTimer("move", point.getDelay() * 1000, npc, null); if (!npcReverse.get(npc.getObjectId())) { pointIndex++; if (pointIndex >= route.getPoints().size()) { npcReverse.put(npc.getObjectId(), true); pointIndex = route.getPoints().size() - 1; } } else { pointIndex--; if (pointIndex < 0) { npcReverse.put(npc.getObjectId(), false); pointIndex = 0; // Choose a new route after completing the current one in both directions switchRouteForNpc(npc); return; } } npcIndexes.put(npc.getObjectId(), pointIndex); } else { // Check again after 1 second startQuestTimer("check_reached", 1000, npc, null); } } } private void selectInitialRouteForNpc(L2Npc npc) { // Randomly select either route1 or route2 String selectedRouteName = "route" + (new Random().nextInt(2) + 1); npcCurrentRoute.put(npc.getObjectId(), selectedRouteName); npcIndexes.put(npc.getObjectId(), 0); npcReverse.put(npc.getObjectId(), false); startQuestTimer("move", 5000, npc, null); // Log initial route selection System.out.println("NPC " + npc.getObjectId() + " selected initial route " + selectedRouteName); } private void switchRouteForNpc(L2Npc npc) { String currentRoute = npcCurrentRoute.get(npc.getObjectId()); String newRoute = currentRoute.equals("route1") ? "route2" : "route1"; npcCurrentRoute.put(npc.getObjectId(), newRoute); npcIndexes.put(npc.getObjectId(), 0); npcReverse.put(npc.getObjectId(), false); startQuestTimer("move", 5000, npc, null); // Log route switching System.out.println("NPC " + npc.getObjectId() + " switched to route " + newRoute); } private static class Route { private List<RoutePoint> points = new ArrayList<>(); public Route(String name) { } public void addPoint(RoutePoint point) { points.add(point); } public List<RoutePoint> getPoints() { return points; } } private static class RoutePoint { private int id; private int x, y, z, delay; private boolean run; private String chat; public RoutePoint(int id, int x, int y, int z, int delay, boolean run, String chat) { this.id = id; this.x = x; this.y = y; this.z = z; this.delay = delay; this.run = run; this.chat = chat; } public int getId() { return id; } public int getX() { return x; } public int getY() { return y; } public int getZ() { return z; } public int getDelay() { return delay; } public boolean isRun() { return run; } public String getChat() { return chat; } } } I looking for help, with this, the npc not start to move. Im trying to create, an NPC wich have multiple walk routes basic logic is  random pick a route complite the route  like Route 1 start form zero (0 -> 1 -> 2(or more) -> 1 -> 0) When the npc return to 0, the script should pic the other route and start again.  And if there is a message like point 1 here     "route1.addPoint(new RoutePoint(1, 148568, 172328, -980, 5, true, "Puff"));" The npc should display the chat message. Currently my problem is the npc not moving, but if I manage it to start moving its randomly move between the route 1 and 2 set of coordinates. Currently for me its  a nightmare. I hope anyone can help somhow.
    • We are certainly not an ambulance, but we will definitely cure you of blacklists and empty pockets. Live freely with SX! Each of you will receive a trial version of SX to familiarize yourself with the product, all you have to do is post in this thread
    • qual e o valor pra atualizar o java da soucer ?
    • qual e o valor pra atualizar o java ?
    • estou tentndo colocar em meu servidor mais nao estou onseguindo me parece esta faltndo algumas configurcoes 
  • Topics

×
×
  • Create New...