Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

Npc Top Pvp y PK

Iniciado por Swarlog, Ago 11, 2022, 12:59 AM

Tema anterior - Siguiente tema

Swarlog


### Eclipse Workspace Patch 1.0
#P aCis_gameserver
Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/TopCommands.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/usercommandhandlers/TopCommands.java (revision 0)
+++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/TopCommands.java (revision 0)
@@ -0,0 +1,50 @@
+/*
+ * 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.handler.usercommandhandlers;
+
+import net.sf.l2j.gameserver.handler.IUserCommandHandler;
+import net.sf.l2j.gameserver.model.Top;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author Lioy
+ *
+ */
+public class TopCommands implements IUserCommandHandler
+{
+
+   private static final int[] COMMAND_IDS =
+   {
+       114
+   };
+   
+   @Override
+   public boolean useUserCommand(int id, L2PcInstance activeChar)
+   {
+       if (id != COMMAND_IDS[0])
+           return false;
+       
+       Top.sendMainWindow(activeChar);
+       
+       return true;
+   }
+
+   @Override
+   public int[] getUserCommandList()
+   {
+       return COMMAND_IDS;
+   }
+   
+}
Index: java/net/sf/l2j/gameserver/GameServer.java
===================================================================
--- java/net/sf/l2j/gameserver/GameServer.java  (revision 1)
+++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
@@ -90,6 +90,7 @@
 import net.sf.l2j.gameserver.model.L2World;
 import net.sf.l2j.gameserver.model.PartyMatchRoomList;
 import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
+import net.sf.l2j.gameserver.model.Top;
 import net.sf.l2j.gameserver.model.entity.Castle;
 import net.sf.l2j.gameserver.model.entity.Hero;
 import net.sf.l2j.gameserver.model.olympiad.Olympiad;
@@ -243,6 +244,7 @@
        Util.printSection("Quests & Scripts");
        QuestManager.getInstance();
        BoatManager.getInstance();
+       Top.getInstance();
         
        if (!Config.ALT_DEV_NO_SCRIPTS)
        {
Index: java/net/sf/l2j/gameserver/network/clientpackets/Say2.java
===================================================================
--- java/net/sf/l2j/gameserver/network/clientpackets/Say2.java  (revision 1)
+++ java/net/sf/l2j/gameserver/network/clientpackets/Say2.java  (working copy)
@@ -21,6 +21,7 @@
 import net.sf.l2j.Config;
 import net.sf.l2j.gameserver.handler.ChatHandler;
 import net.sf.l2j.gameserver.handler.IChatHandler;
+import net.sf.l2j.gameserver.model.Top;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
Index: java/net/sf/l2j/gameserver/handler/UserCommandHandler.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/UserCommandHandler.java  (revision 1)
+++ java/net/sf/l2j/gameserver/handler/UserCommandHandler.java  (working copy)
@@ -31,6 +31,7 @@
 import net.sf.l2j.gameserver.handler.usercommandhandlers.OlympiadStat;
 import net.sf.l2j.gameserver.handler.usercommandhandlers.PartyInfo;
 import net.sf.l2j.gameserver.handler.usercommandhandlers.Time;
+import net.sf.l2j.gameserver.handler.usercommandhandlers.TopCommands;
 
 public class UserCommandHandler
 {
@@ -54,6 +55,7 @@
        registerUserCommandHandler(new Mount());
        registerUserCommandHandler(new PartyInfo());
        registerUserCommandHandler(new Time());
+       registerUserCommandHandler(new TopCommands());
        registerUserCommandHandler(new OlympiadStat());
        registerUserCommandHandler(new ChannelLeave());
        registerUserCommandHandler(new ChannelDelete());
Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
===================================================================
--- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 1)
+++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
@@ -24,6 +24,7 @@
 import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
 import net.sf.l2j.gameserver.model.L2Object;
 import net.sf.l2j.gameserver.model.L2World;
+import net.sf.l2j.gameserver.model.Top;
 import net.sf.l2j.gameserver.model.actor.L2Npc;
 import net.sf.l2j.gameserver.model.actor.instance.L2OlympiadManagerInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
@@ -129,6 +130,20 @@
            {
                CommunityBoard.getInstance().handleCommands(getClient(), _command);
            }
+           else if(_command.startsWith("topcom"))
+           {
+               String num = _command.substring(6);
+               int type = Integer.parseInt(num);
+               
+               if(type==1) //pvp
+               {
+                   Top.sendData(activeChar, 15,true);
+               }
+               else //pk
+               {
+                   Top.sendData(activeChar, 15 , false);
+               }
+           }
            else if (_command.startsWith("Quest "))
            {
                if (!activeChar.validateBypass(_command))
Index: java/net/sf/l2j/gameserver/model/Top.java
===================================================================
--- java/net/sf/l2j/gameserver/model/Top.java   (revision 0)
+++ java/net/sf/l2j/gameserver/model/Top.java   (revision 0)
@@ -0,0 +1,198 @@
+/*
+ * 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.model;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
+
+/**
+ * @author Lioy
+ *
+ */
+public class Top
+{
+   private static final ConcurrentHashMap<String,Integer> playersPvpKills = new ConcurrentHashMap<>();
+   private static final ConcurrentHashMap<String,Integer> playersPkKills = new ConcurrentHashMap<>();
+   protected static final Logger _log = Logger.getLogger(Top.class.getName());
+   
+   public static void sendData(L2PcInstance player,int topWhat,boolean pvp)
+   {
+       Map<String,Integer> sortedPlayersPvpKills = sortByValue(playersPvpKills);
+       Map<String,Integer> sortedPlayersPkKills = sortByValue(playersPkKills);
+
+       NpcHtmlMessage htm = new NpcHtmlMessage(0);
+       StringBuilder sb;
+       if(pvp)
+       {
+            sb = new StringBuilder("<html><head><title>Top Pvp</title></head><body>");
+           sb.append("<center><font color=\"LEVEL\">Pvp Ranking by Lioy</font></center><br><br>");
+       }
+       else
+       {
+            sb = new StringBuilder("<html><head><title>Top Pk</title></head><body>");
+           sb.append("<center><font color=\"LEVEL\">Pk Ranking by Lioy</font></center><br><br>");
+       }
+       
+           ArrayList<String> names = new ArrayList<>();
+           ArrayList<Integer> pvps = new ArrayList<>();
+           ArrayList<Integer> pks = new ArrayList<>();
+           if(pvp)
+           {
+            pvps = new ArrayList<>();
+           for(String key : sortedPlayersPvpKills.keySet())
+           {
+               names.add(key);
+               pvps.add(sortedPlayersPvpKills.get(key));
+           }
+           }
+           else
+           {
+            pks = new ArrayList<>();
+           for(String key : sortedPlayersPvpKills.keySet())
+           {
+               names.add(key);
+               pks.add(sortedPlayersPkKills.get(key));
+           }
+           }
+           sb.append("<table>");
+           sb.append("<tr> <td width=70 height=20>Rank</td> <td width=70 height=20>Name</td> <td width=70 height=20>Kills</td>  </tr>");
+           int counter=1;
+           for(int i=names.size()-1; i>=names.size()-topWhat; i--)
+           {
+               try
+               {   
+                   if(pvp)
+                       sb.append("<tr> <td width=70 height=20> "+counter+"  </td> <td width=70 height=20>"+names.get(i)+"</td> <td width=70 height=20> " +pvps.get(i) + "</td>  </tr>");
+                   else
+                       sb.append("<tr> <td width=70 height=20> "+counter+"  </td> <td width=70 height=20>"+names.get(i)+"</td> <td width=70 height=20> " +pks.get(i) + "</td>  </tr>");   
+                   counter++;
+               }
+               catch(Exception e)
+               {
+                   sb.append("");
+                   break;
+               }
+               
+           }
+           
+       
+       sb.append("</table>");
+       sb.append("</body></html>");
+       htm.setHtml(sb.toString());
+       player.sendPacket(htm);
+           
+   }
+   
+   public static void addDataPvp(String charName , int pvpKills)
+   {
+       playersPvpKills.put(charName, pvpKills);
+   }
+   
+   public static void addDataPk(String charName , int pkKills)
+   {
+       playersPkKills.put(charName, pkKills);
+   }
+   
+   protected static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map)
+   {
+       List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
+       Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
+           @Override
+           public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
+               return (o1.getValue()).compareTo(o2.getValue());
+           }
+       });
+
+       Map<K, V> result = new LinkedHashMap<>();
+       for (Map.Entry<K, V> entry : list) {
+           result.put(entry.getKey(), entry.getValue());
+       }
+       return result;
+   }
+   
+   protected Top()
+   {
+       retrieveData();
+   }
+   
+   protected void retrieveData()
+   {
+       
+       String charName;
+       int pvpKills;
+       int pkKills;
+       try(Connection con = L2DatabaseFactory.getInstance().getConnection())
+       {
+           PreparedStatement st = con.prepareStatement("SELECT char_name,pvpkills,pkkills FROM characters WHERE pvpkills>0;");
+           ResultSet rset = st.executeQuery();
+           
+           while(rset.next())
+           {
+               charName = rset.getString("char_name");
+               pvpKills = rset.getInt("pvpkills");
+               pkKills = rset.getInt("pkkills");
+               playersPvpKills.put(charName, pvpKills);
+               playersPkKills.put(charName, pkKills);
+           }
+           rset.close();
+           st.close();
+           
+       }
+       catch(Exception e)
+       {
+           _log.warning("Could not store data of players kills " + e);
+       }
+   }
+   
+   public static Top getInstance()
+   {
+       return SingletonHolder._instance;
+   }
+   
+   private static class SingletonHolder
+   {
+       protected static  Top _instance = new Top();
+   }
+   
+   public static void sendMainWindow(L2PcInstance player)
+   {
+       NpcHtmlMessage nhm = new NpcHtmlMessage(0);
+       StringBuilder sb = new StringBuilder("<html><head><title>Pvp/Pk Ranking by Lioy</title></head><body>");
+       sb.append("<center><font color=\"LEVEL\">Choose what would you like</font></center><br<br>");
+       sb.append("<table><center>");
+       sb.append("<tr><td><button value=\"Top Pvp\" action=\"bypass -h topcom1\" width=204 height=45 </td></tr>");
+       sb.append("<tr><td></td></tr>");
+       sb.append("<tr><td><button value=\"Top Pk\" action=\"bypass -h topcom2\" width=204 height=45 </td></tr>");
+       sb.append("</center></table></body></html>");
+       
+       nhm.setHtml(sb.toString());
+       player.sendPacket(nhm);
+   }
+   
+}
Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (revision 1)
+++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (working copy)
@@ -105,6 +105,7 @@
 import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
 import net.sf.l2j.gameserver.model.ShortCuts;
 import net.sf.l2j.gameserver.model.ShotType;
+import net.sf.l2j.gameserver.model.Top;
 import net.sf.l2j.gameserver.model.TradeList;
 import net.sf.l2j.gameserver.model.actor.L2Attackable;
 import net.sf.l2j.gameserver.model.actor.L2Character;
@@ -1566,6 +1567,7 @@
    public void setPkKills(int pkKills)
    {
        _pkKills = pkKills;
+       Top.addDataPk(getName(), getPkKills());
    }
     
    /**
@@ -1917,6 +1919,7 @@
    public void setPvpKills(int pvpKills)
    {
        _pvpKills = pvpKills;
+       Top.addDataPvp(getName(),getPvpKills());
    }
     
    /**
@@ -4299,7 +4302,6 @@
        {
            // Add PvP point to attacker.
            setPvpKills(getPvpKills() + 1);
-           
            // Send a Server->Client UserInfo packet to attacker with its Karma and PK Counter
            sendPacket(new UserInfo(this));
        }