L2JLisvus

Would you like to react to this message? Create an account in a few clicks or log in to continue.

    Store Dwarven Manufacture shoplist

    Karakan
    Karakan


    Posts : 756
    Join date : 2013-10-04

    Store Dwarven Manufacture shoplist  Empty Store Dwarven Manufacture shoplist

    Post  Karakan 14th May 2019, 01:42

    Greetings.

    This gives the option to store the Manufacture list when a charakter logs out.
    So poor dwarves dont need to add them manualy again.
    Also works when the charakter is in offline shop modus.

    Original code made by Gnacik for L2j.
    I adapted it to our latest revision.


    Have fun. Cool





    Config.java

    Code:

    Index: Config.java
    ===================================================================
    --- Config.java (revision 609)
    +++ Config.java (working copy)
    @@ -1125,6 +1137,8 @@
     /** Define the cutoff point value for the "percentage" method */
     public static double PARTY_XP_CUTOFF_PERCENT;
     
    + public static boolean STORE_RECIPE_SHOPLIST;
    +
     /** Percent HP is restore on respawn */
     public static double RESPAWN_RESTORE_HP;
     

    @@ -2082,7 +2113,9 @@
     CHAMPION_REWARD_HIGHER_CHANCE = Integer.parseInt(customSettings.getProperty("ChampionRewardHigherLvlItemChance", "0"));
     CHAMPION_REWARD_ID = Integer.parseInt(customSettings.getProperty("ChampionRewardItemID", "6393"));
     CHAMPION_REWARD_QTY = Integer.parseInt(customSettings.getProperty("ChampionRewardItemQty", "1"));
    -
    + /* Option to save recipe list when charakter logs out */
    + STORE_RECIPE_SHOPLIST = Boolean.parseBoolean(customSettings.getProperty("StoreRecipeShopList", "False"));
    +
     ALLOW_AUTO_REWARDER = Boolean.valueOf(customSettings.getProperty("AllowAutoRewarder", "False"));
     AUTO_REWARD_DELAY = Integer.parseInt(customSettings.getProperty("AutoRewardDelay", "1200"));
     AUTO_REWARD_ID = Integer.parseInt(customSettings.getProperty("AutoRewardID", "57"));



    IdFactory.java

    Code:

    Index: IdFactory.java
    ===================================================================
    --- IdFactory.java (revision 609)
    +++ IdFactory.java (working copy)
    @@ -48,6 +48,7 @@
     "UPDATE character_friends     SET friend_id = ?       WHERE friend_id = ?",
     "UPDATE character_hennas      SET char_obj_id = ?     WHERE char_obj_id = ?",
     "UPDATE character_recipebook  SET char_id = ?         WHERE char_id = ?",
    + "UPDATE character_recipeshoplist  SET char_id = ? WHERE char_id = ?",
     "UPDATE character_shortcuts   SET char_obj_id = ?     WHERE char_obj_id = ?",
     "UPDATE character_shortcuts   SET shortcut_id = ?     WHERE shortcut_id = ? AND type = 1", // items
     "UPDATE character_macroses    SET char_obj_id = ?     WHERE char_obj_id = ?",
    @@ -79,6 +80,7 @@
     "SELECT char_id     FROM character_friends     WHERE friend_id >= ?   AND friend_id < ?",
     "SELECT char_obj_id FROM character_hennas      WHERE char_obj_id >= ? AND char_obj_id < ?",
     "SELECT char_id     FROM character_recipebook  WHERE char_id >= ?     AND char_id < ?",
    + "SELECT char_id     FROM character_recipeshoplist  WHERE char_id >= ?     AND char_id < ?",
     "SELECT char_obj_id FROM character_shortcuts   WHERE char_obj_id >= ? AND char_obj_id < ?",
     "SELECT char_obj_id FROM character_macroses    WHERE char_obj_id >= ? AND char_obj_id < ?",
     "SELECT char_obj_id FROM character_skills      WHERE char_obj_id >= ? AND char_obj_id < ?",
    @@ -166,6 +168,7 @@
                 cleanCount += stmt.executeUpdate("DELETE FROM character_macroses WHERE character_macroses.char_obj_id NOT IN (SELECT obj_Id FROM characters);");
                 cleanCount += stmt.executeUpdate("DELETE FROM character_quests WHERE character_quests.char_id NOT IN (SELECT obj_Id FROM characters);");
                 cleanCount += stmt.executeUpdate("DELETE FROM character_recipebook WHERE character_recipebook.char_id NOT IN (SELECT obj_Id FROM characters);");
    + cleanCount += stmt.executeUpdate("DELETE FROM character_recipeshoplist WHERE character_recipeshoplist.char_id NOT IN (SELECT obj_Id FROM characters);");
                 cleanCount += stmt.executeUpdate("DELETE FROM character_shortcuts WHERE character_shortcuts.char_obj_id NOT IN (SELECT obj_Id FROM characters);");
                 cleanCount += stmt.executeUpdate("DELETE FROM character_skills WHERE character_skills.char_obj_id NOT IN (SELECT obj_Id FROM characters);");
                 cleanCount += stmt.executeUpdate("DELETE FROM character_skills_save WHERE character_skills_save.char_obj_id NOT IN (SELECT obj_Id FROM characters);");



    L2PcInstance.java


    Code:

    Index: L2PcInstance.java
    ===================================================================
    --- L2PcInstance.java (revision 609)
    +++ L2PcInstance.java (working copy)
    @@ -21,6 +21,7 @@
     import java.sql.Connection;
     import java.sql.PreparedStatement;
     import java.sql.ResultSet;
    +import java.sql.SQLException;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Calendar;
     
    @@ -90,6 +91,7 @@
     import net.sf.l2j.gameserver.model.L2HennaInstance;
     import net.sf.l2j.gameserver.model.L2ItemInstance;
     import net.sf.l2j.gameserver.model.L2Macro;
    +import net.sf.l2j.gameserver.model.L2ManufactureItem;
     import net.sf.l2j.gameserver.model.L2ManufactureList;
     import net.sf.l2j.gameserver.model.L2Object;
     import net.sf.l2j.gameserver.model.L2Party;

     
    @@ -6692,7 +6707,13 @@
     // Retrieve from the database the recipe book of this L2PcInstance.
     restoreRecipeBook(true);
    -
    +
    + // Restore Recipe Shop list
    + if(Config.STORE_RECIPE_SHOPLIST)
    + {
    + restoreRecipeShopList();
    + }
    +
     // Retrieve from the database all friends
     restoreFriends();
     }
    @@ -6758,6 +6779,10 @@
     storeCharBase();
     storeCharSub();
     storeEffect(true);
    + if(Config.STORE_RECIPE_SHOPLIST)
    + {
    + storeRecipeShopList();
    + }
     }
     
     private void storeCharBase()

    @@ -9338,6 +9371,92 @@
     sendPacket(new EtcStatusUpdate(this));
     }
     
    + private void storeRecipeShopList()
    + {
    + Connection con = null;
    +
    + try
    + {
    + con = L2DatabaseFactory.getInstance().getConnection();
    + PreparedStatement statement;
    + L2ManufactureList list = getCreateList();
    +
    + if (list != null && list.size() > 0)
    + {
    + int _position = 1;
    + statement = con.prepareStatement("DELETE FROM character_recipeshoplist WHERE char_Id=? ");
    + statement.setInt(1, getObjectId());
    + statement.execute();
    + statement.close();
    + for (L2ManufactureItem item : list.getList())
    + {
    + statement = con.prepareStatement("INSERT INTO character_recipeshoplist (char_Id, Recipeid, Price, Pos) VALUES (?, ?, ?, ?)");
    + statement.setInt(1, getObjectId());
    + statement.setInt(2, item.getRecipeId());
    + statement.setLong(3, item.getCost());
    + statement.setInt(4, _position);
    + statement.execute();
    + statement.close();
    + _position++;
    + }
    + }
    + }
    + catch (Exception e)
    + {
    + _log.log(Level.SEVERE, "Could not store recipe shop for playerID " + getObjectId() + ": ", e);
    + }
    + finally
    + {
    + try
    + {
    + if (con != null)
    + con.close();
    + }
    + catch (SQLException e)
    + {
    + e.printStackTrace();
    + }
    + }
    + }
    +
    + private void restoreRecipeShopList()
    + {
    + Connection con = null;
    +
    + try
    + {
    + con = L2DatabaseFactory.getInstance().getConnection();
    + PreparedStatement statement = con.prepareStatement("SELECT Recipeid,Price FROM character_recipeshoplist WHERE char_Id=? ORDER BY Pos ASC");
    + statement.setInt(1, getObjectId());
    + ResultSet rset = statement.executeQuery();
    +
    + L2ManufactureList createList = new L2ManufactureList();
    + while (rset.next())
    + {
    + createList.add(new L2ManufactureItem(rset.getInt("Recipeid"), (int) rset.getLong("Price")));
    + }
    + setCreateList(createList);
    + rset.close();
    + statement.close();
    + }
    + catch (Exception e)
    + {
    + _log.log(Level.SEVERE, "Could not restore recipe shop list data for playerId: "+getObjectId(), e);
    + }
    + finally
    + {
    + try
    + {
    + if (con != null)
    + con.close();
    + }
    + catch (SQLException e)
    + {
    + e.printStackTrace();
    + }
    + }
    + }
    +
     public void setDietMode(boolean mode)
     {
     _dietMode = mode;





    Custom.properties

    Code:

    Index: custom.properties
    ===================================================================
    --- custom.properties (revision 609)
    +++ custom.properties (working copy)
    @@ -102,6 +102,11 @@
     # Specified reward item rnd qty
     ChampionRewardItemQty = 1
     
    +# Store/Restore Dwarven Manufacture list
    +# Keep manufacture shoplist after relog
    +# Default: False
    +StoreRecipeShopList = True
    +
     # ------------------------------------------------------------
     # Skill Duration List
     # --


    RecipeShopManageList.java

    Code:

    Index: RecipeShopManageList.java
    ===================================================================
    --- RecipeShopManageList.java (revision 609)
    +++ RecipeShopManageList.java (working copy)
    @@ -49,19 +49,16 @@
     }
     
     // clean previous recipes
    -
     if (_seller.getCreateList() != null)
    - {
    - L2ManufactureList list = _seller.getCreateList();
    -
    - for (L2ManufactureItem item : list.getList())
     {
    - if (item.isDwarven() != _isDwarven)
    + L2ManufactureList list = _seller.getCreateList();
    +
    + for (L2ManufactureItem item : list.getList())
     {
    - list.getList().remove(item);
    + if (item.isDwarven() != _isDwarven || !seller.hasRecipeList(item.getRecipeId()))
    + list.getList().remove(item);
     }
    - }
    - }
    + }
     }
     
     @Override



    SQL part


    Code:
    CREATE TABLE IF NOT EXISTS `character_recipeshoplist` (
      char_id decimal(11) NOT NULL default 0,
      Recipeid decimal(11) NOT NULL default 0,
      Price bigint(20) NOT NULL DEFAULT '0',
      Pos int(5) NOT NULL DEFAULT '0',
      PRIMARY KEY (`char_id`,`Recipeid`)
    );



    Regards Cool

      Current date/time is 19th May 2024, 15:10