Ir para conteúdo
  • Cadastre-se
  • 0

AJUDA MUDAR UM JAVA MOUD DO FROZEN PRO PROJETO X ESSE CODIGO


ariane

Pergunta

Index: config/functions/l2jfrozen.properties
===================================================================
--- config/functions/l2jfrozen.properties    (revision 1132)
+++ config/functions/l2jfrozen.properties    (working copy)
@@ -69,6 +69,18 @@
 # Hero for X days, 0 forever.
 HeroCustomDay = 0
 
+#--------------------------------------------------
+#  Hero Command Configuration .hero | .renovar
+#--------------------------------------------------
+# Enable / Disable Hero Command 
+AllowHeroCommand = False
+# Item ID to make Hero
+HeroItemId = 57
+# How many of this item will it take?
+HeroItemCount = 1
+# Number of times you can become Hero
+HeroMaxQuantityBuy = 2
+
 # --------------------------------------------
 # Custom hero subclass skill -
 # --------------------------------------------
Index: head-src/com/l2jfrozen/Config.java
===================================================================
--- head-src/com/l2jfrozen/Config.java    (revision 1132)
+++ head-src/com/l2jfrozen/Config.java    (working copy)
@@ -56,6 +56,10 @@
     private static final Logger LOGGER = Logger.getLogger(Config.class);
     
     // ============================================================
+    public static boolean ALLOW_HERO_COMMAND;
+    public static int HERO_ITEM_ID_NEED;
+    public static int HERO_ITEM_COUNT;
+    public static int HERO_QUANTITY;
     public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
     public static boolean SHOW_GM_LOGIN;
     public static boolean GM_STARTUP_INVISIBLE;
@@ -2504,6 +2508,12 @@
             HERO_CUSTOM_ITEM_ID = Integer.parseInt(L2JFrozenSettings.getProperty("HeroCustomItemId", "3481"));
             HERO_CUSTOM_DAY = Integer.parseInt(L2JFrozenSettings.getProperty("HeroCustomDay", "0"));
             
+            /** Hero Command */
+            ALLOW_HERO_COMMAND = Boolean.parseBoolean(L2JFrozenSettings.getProperty("AllowHeroCommand", "true"));
+            HERO_ITEM_ID_NEED = Integer.parseInt(L2JFrozenSettings.getProperty("HeroItemId", "57"));
+            HERO_ITEM_COUNT = Integer.parseInt(L2JFrozenSettings.getProperty("HeroItemCount", "100000"));
+            HERO_QUANTITY = Integer.parseInt(L2JFrozenSettings.getProperty("HeroMaxQuantityBuy", "2"));
+
             ALLOW_CREATE_LVL = Boolean.parseBoolean(L2JFrozenSettings.getProperty("CustomStartingLvl", "False"));
             CHAR_CREATE_LVL = Integer.parseInt(L2JFrozenSettings.getProperty("CharLvl", "80"));
             SPAWN_CHAR = Boolean.parseBoolean(L2JFrozenSettings.getProperty("CustomSpawn", "false"));
Index: head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java    (revision 1132)
+++ head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java    (working copy)
@@ -33,6 +31,7 @@
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.CTFCmd;
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.DMCmd;
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.FarmPvpCmd;
+import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Heroes;
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.OfflineShop;
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Online;
 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.StatsCmd;
@@ -121,6 +122,11 @@
             registerVoicedCommandHandler(new OfflineShop());
         }
         
+        if (Config.ALLOW_HERO_COMMAND)
+        {
+            registerVoicedCommandHandler(new Heroes());
+        }
+        
         LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
         
     }
Index: head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/Heroes.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/Heroes.java    (nonexistent)
+++ head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/Heroes.java    (working copy)
@@ -0,0 +1,287 @@
+package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import com.l2jfrozen.Config;
+import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.network.serverpackets.SocialAction;
+import com.l2jfrozen.util.CloseUtil;
+import com.l2jfrozen.util.database.DatabaseUtils;
+import com.l2jfrozen.util.database.L2DatabaseFactory;
+
+/**
+ * @author Tayran.JavaDev
+ * @version 1
+ */
+public class Heroes implements IVoicedCommandHandler
+{
+    protected static final Logger LOGGER = Logger.getLogger(Heroes.class);
+    private static final String INSERT_HEROES = "INSERT INTO character_heroes_custom (char_name,Obj_Id,quantity) VALUES (?,?,?)";
+    private static final String SELECT_HEROE = "SELECT * FROM character_heroes_custom WHERE Obj_Id=?";
+    private static final String SELECT_ALL_HEROES = "SELECT * FROM character_heroes_custom";
+    private static final String UPDATE_HEROES = "UPDATE character_heroes_custom SET quantity=?";
+    private Map<String, String> heroes;
+    private final int quantidadeVezesHero = Config.HERO_QUANTITY;
+    
+    public Heroes()
+    {
+        heroes = new HashMap<>();
+        selectAllHeroes();
+    }
+    
+    private void selectAllHeroes()
+    {
+        Connection con = null;
+        
+        try
+        {
+            con = L2DatabaseFactory.getInstance().getConnection(false);
+            PreparedStatement statement = null;
+            
+            statement = con.prepareStatement(SELECT_ALL_HEROES);
+            ResultSet rset = statement.executeQuery();
+            while (rset.next())
+            {
+                final String nome = rset.getString("char_name");
+                final int objId = rset.getInt("Obj_Id");
+                
+                heroes.put(nome, String.valueOf(objId));
+                
+            }
+            DatabaseUtils.close(rset);
+            DatabaseUtils.close(statement);
+        }
+        catch (final Exception e)
+        {
+            if (Config.ENABLE_ALL_EXCEPTIONS)
+                e.printStackTrace();
+            
+            LOGGER.warn("Error could not restore Heroes DB : " + e);
+        }
+        finally
+        {
+            CloseUtil.close(con);
+        }
+    }
+    
+    public boolean hasHeroes()
+    {
+        return heroes.size() > 0;
+    }
+    
+    public Map<String, String> getHeroes()
+    {
+        return heroes;
+    }
+    
+    private static final String[] VOICED_COMMANDS =
+    {
+        "hero",
+        "renovar"
+    };
+    
+    @Override
+    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+    {
+        if (command.equalsIgnoreCase("hero"))
+        {
+            if (activeChar.getInventory().getItemByItemId(Config.HERO_ITEM_ID_NEED) != null && activeChar.getInventory().getItemByItemId(Config.HERO_ITEM_ID_NEED).getCount() >= Config.HERO_ITEM_COUNT)
+            {
+                adicionaHero(activeChar);
+            }
+            else
+            {
+                activeChar.sendMessage("Desculpe, voce nao tem a quantia de itens para se tornar Hero.");
+                return true;
+            }
+        }
+        else if (command.equalsIgnoreCase("renovar"))
+        {
+            if (activeChar.getInventory().getItemByItemId(Config.HERO_ITEM_ID_NEED) != null && activeChar.getInventory().getItemByItemId(Config.HERO_ITEM_ID_NEED).getCount() >= Config.HERO_ITEM_COUNT)
+            {
+                renovaHero(activeChar);
+            }
+            else
+            {
+                activeChar.sendMessage("Desculpe, voce nao tem a quantia de itens para se tornar Hero.");
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    /**
+     * @author Tayran.JavaDev
+     * @param activeChar - Player requesting the Hero
+     * @return 
+     */
+    private boolean adicionaHero(L2PcInstance activeChar)
+    {
+        if (activeChar.isHero())
+        {
+            activeChar.sendMessage("Voce ja e um Hero.");
+            return false;
+        }
+        else if (heroes.containsKey(activeChar.getName()))
+        {
+            activeChar.sendMessage("Voce ja se tornou Hero uma vez , use o comando .renovar para voltar a ser Hero.");
+            return false;
+        }
+        activeChar.getInventory().destroyItemByItemId("Hero Item ID", Config.HERO_ITEM_ID_NEED, Config.HERO_ITEM_COUNT, activeChar, activeChar.getTarget());
+        activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 16));
+        activeChar.setHero(true);
+        activeChar.sendMessage("Parabens, Voce acabou de se tornar Hero ate seu proximo restart.");
+        activeChar.broadcastUserInfo();
+        heroes.put(activeChar.getName(), String.valueOf(activeChar.getObjectId()));
+        
+        Connection con = null;
+        
+        try
+        {
+            con = L2DatabaseFactory.getInstance().getConnection(false);
+            PreparedStatement statement = null;
+            
+            statement = con.prepareStatement(INSERT_HEROES);
+            statement.setString(1, activeChar.getName());
+            statement.setInt(2, activeChar.getObjectId());
+            statement.setInt(3, quantidadeVezesHero);
+            statement.execute();
+            DatabaseUtils.close(statement);
+        }
+        catch (final Exception e)
+        {
+            if (Config.ENABLE_ALL_EXCEPTIONS)
+                e.printStackTrace();
+            
+            LOGGER.warn("Error could not store Hero : " + e);
+            return false;
+        }
+        finally
+        {
+            CloseUtil.close(con);
+        }
+        
+        return true;
+    }
+    
+    /**
+     * @author Tayran.JavaDev
+     * @param activeChar - Player requesting renewal hero
+     * @return 
+     */
+    private boolean renovaHero(L2PcInstance activeChar)
+    {
+        if (activeChar.isHero())
+        {
+            activeChar.sendMessage("Voce ja e um Hero.");
+            return false;
+        }
+        else if (!heroes.containsKey(activeChar.getName()))
+        {
+            activeChar.sendMessage("Para renovar o Hero voce precisa usar o comando .hero primeiro.");
+            return false;
+        }
+        Connection con = null;
+        
+        try
+        {
+            con = L2DatabaseFactory.getInstance().getConnection(false);
+            PreparedStatement statement = null;
+            
+            statement = con.prepareStatement(SELECT_HEROE);
+            statement.setInt(1, activeChar.getObjectId());
+            ResultSet rset = statement.executeQuery();
+            while (rset.next())
+            {
+                // final String nome = rset.getString("char_name");
+                // final int objId = rset.getInt("Obj_Id");
+                int quantidadesRestantes = rset.getInt("quantity");
+                
+                if (quantidadesRestantes > 0)
+                {
+                    quantidadesRestantes--;
+                    renovaUpdateDB(activeChar, quantidadesRestantes);
+                    activeChar.getInventory().destroyItemByItemId("Hero Item ID", Config.HERO_ITEM_ID_NEED, Config.HERO_ITEM_COUNT, activeChar, activeChar.getTarget());
+                    activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), 16));
+                    activeChar.setHero(true);
+                    if (quantidadesRestantes > 0)
+                    {
+                        activeChar.sendMessage("Parabens, Voce acabou de renovar seu Hero ate seu proximo restart, voce ainda pode renovar por mais " + quantidadesRestantes + " vez.");
+                    }
+                    else
+                    {
+                        activeChar.sendMessage("Parabens, Voce acabou de renovar seu Hero ate seu proximo restart, aproveite essa sera a ultima vez.");
+                    }
+                    activeChar.broadcastUserInfo();
+                }
+                else
+                {
+                    activeChar.sendMessage("Voce ja atingiu o limite de vezes que pode se tornar Hero.");
+                }
+            }
+            DatabaseUtils.close(rset);
+            DatabaseUtils.close(statement);
+        }
+        catch (final Exception e)
+        {
+            if (Config.ENABLE_ALL_EXCEPTIONS)
+                e.printStackTrace();
+            
+            LOGGER.warn("Error could not store Hero : " + e);
+            return false;
+        }
+        finally
+        {
+            CloseUtil.close(con);
+        }
+        
+        return true;
+    }
+    
+    /**
+     * @author Tayran.JavaDev
+     * @param activeChar - Player for update in DB
+     * @param quantidadesRestantes - Remaining quantities requests Hero
+     */
+    private void renovaUpdateDB(L2PcInstance activeChar, int quantidadesRestantes)
+    {
+        Connection con = null;
+        
+        try
+        {
+            con = L2DatabaseFactory.getInstance().getConnection(false);
+            PreparedStatement statement = null;
+            
+            statement = con.prepareStatement(UPDATE_HEROES);
+            statement.setInt(1, quantidadesRestantes);
+            statement.execute();
+            DatabaseUtils.close(statement);
+        }
+        catch (final Exception e)
+        {
+            if (Config.ENABLE_ALL_EXCEPTIONS)
+                e.printStackTrace();
+            
+            LOGGER.warn("Error could not store Hero : " + e);
+        }
+        finally
+        {
+            CloseUtil.close(con);
+        }
+        
+    }
+    
+    @Override
+    public String[] getVoicedCommandList()
+    {
+        return VOICED_COMMANDS;
+    }
+}
 

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts recomendados


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Processando...




×
×
  • Criar Novo...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.