Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2J_Mobius_C6_Interlude
- diff --git dist/game/config/General.ini dist/game/config/General.ini
- index 2c9ca99..95ed0c2 100644
- --- dist/game/config/General.ini
- +++ dist/game/config/General.ini
- @@ -711,3 +711,9 @@
- RandomCraftConsumeRefresh = 50000
- RandromCraftConsumeCreate = 300000
- +
- +#======================================================================================
- +# BLACK COUPON RECOVERY 1 ITEM ENCHANT FAILED - ID ITEM CONSUME AFTER RECOVER ITEM
- +#======================================================================================
- +
- +BlackCouponId = 6392
- diff --git java/Base/RecoverySystem/ItemRecoveryManager.java java/Base/RecoverySystem/ItemRecoveryManager.java
- new file mode 100644
- index 0000000..f1097da
- --- /dev/null
- +++ java/Base/RecoverySystem/ItemRecoveryManager.java
- @@ -0,0 +1,286 @@
- +package Base.RecoverySystem;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.commons.database.DatabaseFactory;
- +import org.l2jmobius.gameserver.data.ItemTable;
- +import org.l2jmobius.gameserver.model.actor.Player;
- +import org.l2jmobius.gameserver.model.item.instance.Item;
- +
- +public class ItemRecoveryManager
- +{
- + private final Map<Integer, Integer> validEnchantLevels;
- +
- + public ItemRecoveryManager()
- + {
- + validEnchantLevels = new HashMap<>();
- + loadValidEnchantLevels();
- + }
- +
- + public void recoverSelectedItem(Player player, int itemId, int enchantLevel)
- + {
- +
- + Item recoveryItem = player.getInventory().getItemByItemId(Config.BLACK_COUPON_ID);
- + if ((recoveryItem == null) || (recoveryItem.getCount() < 1))
- + {
- + player.sendMessage("No tienes suficientes items para recuperar este item.");
- + return;
- + }
- +
- + if (!isValidEnchantLevel(itemId, enchantLevel, player.getObjectId()))
- + {
- + player.sendMessage("No puedes recuperar este item con ese nivel de enchant.");
- + return;
- + }
- +
- + if (!isValidRecoveryItem(itemId, player.getObjectId()))
- + {
- + player.sendMessage("No puedes recuperar este item.");
- + return;
- + }
- +
- + Item recoveredItem = ItemTable.getInstance().createItem("RecoverItem", itemId, 1, player, null);
- + recoveredItem.setEnchantLevel(enchantLevel);
- +
- + player.getInventory().addItem("RecoverItem", recoveredItem, player, player);
- +
- + player.destroyItemByItemId("RecoveryCost", Config.BLACK_COUPON_ID, 1, null, true);
- +
- + player.sendPacket(new ItemList(player, true));
- +
- + removeRecoverableItem(itemId, player.getObjectId());
- +
- + String itemName = recoveredItem.getItemName();
- + String message = "Has recuperado el item " + itemName;
- + if (enchantLevel > 0)
- + {
- + message += " +" + enchantLevel;
- + }
- + player.sendMessage(message);
- + }
- +
- + public boolean isValidRecoveryItem(int itemId, int objectId)
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- + ResultSet resultSet = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "SELECT item_id FROM item_recover WHERE object_id = ? AND item_id = ?";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, objectId);
- + statement.setInt(2, itemId);
- + resultSet = statement.executeQuery();
- +
- + return resultSet.next();
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (resultSet != null)
- + {
- + resultSet.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- +
- + try
- + {
- + if (statement != null)
- + {
- + statement.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- +
- + try
- + {
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + return false;
- + }
- +
- + public boolean isValidEnchantLevel(int itemId, int enchantLevel, int objectId)
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- + ResultSet resultSet = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "SELECT enchant_level FROM item_recover WHERE object_id = ? AND item_id = ?";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, objectId);
- + statement.setInt(2, itemId);
- + resultSet = statement.executeQuery();
- +
- + if (resultSet.next())
- + {
- + int validEnchantLevel = resultSet.getInt("enchant_level");
- + return enchantLevel == validEnchantLevel;
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (resultSet != null)
- + {
- + resultSet.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + try
- + {
- + if (statement != null)
- + {
- + statement.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + try
- + {
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + return false;
- + }
- +
- + public void removeRecoverableItem(int itemId, int objectId)
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "DELETE FROM item_recover WHERE item_id = ? AND object_id = ?";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, itemId);
- + statement.setInt(2, objectId);
- + statement.executeUpdate();
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (statement != null)
- + {
- + statement.close();
- + }
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + }
- + }
- +
- + private void loadValidEnchantLevels()
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- + ResultSet resultSet = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "SELECT item_id, enchant_level FROM item_recover";
- + statement = con.prepareStatement(sql);
- + resultSet = statement.executeQuery();
- +
- + while (resultSet.next())
- + {
- + int itemId = resultSet.getInt("item_id");
- + int enchantLevel = resultSet.getInt("enchant_level");
- +
- + validEnchantLevels.put(itemId, enchantLevel);
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (resultSet != null)
- + {
- + resultSet.close();
- + }
- + if (statement != null)
- + {
- + statement.close();
- + }
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + }
- + }
- +
- +}
- \ No newline at end of file
- diff --git java/Base/RecoverySystem/RecoverableItem.java java/Base/RecoverySystem/RecoverableItem.java
- new file mode 100644
- index 0000000..379e9d6
- --- /dev/null
- +++ java/Base/RecoverySystem/RecoverableItem.java
- @@ -0,0 +1,111 @@
- +package Base.RecoverySystem;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.SQLException;
- +
- +import org.l2jmobius.commons.database.DatabaseFactory;
- +import org.l2jmobius.gameserver.data.ItemTable;
- +import org.l2jmobius.gameserver.model.item.ItemTemplate;
- +
- +public class RecoverableItem
- +{
- + private final int objectId;
- + private final int itemId;
- + private final String itemName;
- + private final int enchantLevel;
- + private boolean selected;
- +
- + public RecoverableItem(int objectId, int itemId, String itemName, int enchantLevel)
- + {
- + this.objectId = objectId;
- + this.itemId = itemId;
- + this.itemName = itemName;
- + this.enchantLevel = enchantLevel;
- + this.selected = false;
- + }
- +
- + public int getObjectId()
- + {
- + return objectId;
- + }
- +
- + public int getItemId()
- + {
- + return itemId;
- + }
- +
- + public String getItemName()
- + {
- + return itemName;
- + }
- +
- + public int getEnchantLevel()
- + {
- + return enchantLevel;
- + }
- +
- + public void saveBrokenItemInfo()
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "INSERT INTO item_recover (object_id, item_id, item_name, enchant_level) VALUES (?, ?, ?, ?)";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, objectId);
- + statement.setInt(2, itemId);
- + statement.setString(3, itemName);
- + statement.setInt(4, enchantLevel);
- + statement.execute();
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + finally
- + {
- +
- + try
- + {
- + if (statement != null)
- + {
- + statement.close();
- + }
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + }
- + }
- +
- + public boolean isSelected()
- + {
- + return selected;
- + }
- +
- + public void setSelected(boolean selected)
- + {
- + this.selected = selected;
- + }
- +
- + public String getIcon()
- + {
- + return getItem().getIcon(itemId);
- + }
- +
- + public ItemTemplate getItem()
- + {
- + return ItemTable.getInstance().getTemplate(itemId);
- + }
- +
- +}
- \ No newline at end of file
- diff --git java/org/l2jmobius/Config.java java/org/l2jmobius/Config.java
- index 66735d1..290d922 100644
- --- java/org/l2jmobius/Config.java
- +++ java/org/l2jmobius/Config.java
- @@ -128,6 +128,8 @@
- public static int RANDOM_CRAFT_ITEM_ID_CONSUME;
- public static int RANDOM_CRAFT_ITEM_CONSUME_REFRESH;
- public static int RANDOM_CRAFT_ITEM_CONSUME_CREATE;
- +
- + public static int BLACK_COUPON_ID;
- public static boolean SHOW_GM_LOGIN;
- public static boolean GM_STARTUP_INVISIBLE;
- public static boolean GM_SPECIAL_EFFECT;
- @@ -1301,7 +1303,7 @@
- RANDOM_CRAFT_ITEM_CONSUME_REFRESH = generalConfig.getInt("RandomCraftConsumeRefresh", 50000);
- RANDOM_CRAFT_ITEM_CONSUME_CREATE = generalConfig.getInt("RandromCraftConsumeCreate", 300000);
- -
- + BLACK_COUPON_ID = generalConfig.getInt("BlackCouponId", 6392);
- ALT_DEV_NO_QUESTS = generalConfig.getBoolean("AltDevNoQuests", false);
- ALT_DEV_NO_SPAWNS = generalConfig.getBoolean("AltDevNoSpawns", false);
- ALT_DEV_NO_SCRIPT = generalConfig.getBoolean("AltDevNoScript", false);
- diff --git java/org/l2jmobius/gameserver/handler/ItemHandler.java java/org/l2jmobius/gameserver/handler/ItemHandler.java
- index 6af36f0..4d7df14 100644
- --- java/org/l2jmobius/gameserver/handler/ItemHandler.java
- +++ java/org/l2jmobius/gameserver/handler/ItemHandler.java
- @@ -40,6 +40,7 @@
- import org.l2jmobius.gameserver.handler.itemhandlers.FishShots;
- import org.l2jmobius.gameserver.handler.itemhandlers.Harvester;
- import org.l2jmobius.gameserver.handler.itemhandlers.HeroCustomItem;
- +import org.l2jmobius.gameserver.handler.itemhandlers.Item_Recover;
- import org.l2jmobius.gameserver.handler.itemhandlers.JackpotSeed;
- import org.l2jmobius.gameserver.handler.itemhandlers.MOSKey;
- import org.l2jmobius.gameserver.handler.itemhandlers.MapForestOfTheDead;
- @@ -124,6 +125,7 @@
- registerItemHandler(new SpecialXMas());
- registerItemHandler(new SpiritShot());
- registerItemHandler(new SummonItems());
- + registerItemHandler(new Item_Recover());
- LOGGER.info("ItemHandler: Loaded " + _datatable.size() + " handlers.");
- }
- diff --git java/org/l2jmobius/gameserver/handler/itemhandlers/Item_Recover.java java/org/l2jmobius/gameserver/handler/itemhandlers/Item_Recover.java
- new file mode 100644
- index 0000000..880fec9
- --- /dev/null
- +++ java/org/l2jmobius/gameserver/handler/itemhandlers/Item_Recover.java
- @@ -0,0 +1,169 @@
- +package org.l2jmobius.gameserver.handler.itemhandlers;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.commons.database.DatabaseFactory;
- +import org.l2jmobius.gameserver.handler.IItemHandler;
- +import org.l2jmobius.gameserver.model.actor.Playable;
- +import org.l2jmobius.gameserver.model.actor.Player;
- +import org.l2jmobius.gameserver.model.item.instance.Item;
- +import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
- +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- +
- +import Base.RecoverySystem.RecoverableItem;
- +
- +/**
- + * @author Terius
- + */
- +public class Item_Recover implements IItemHandler
- +{
- +
- + private static final int[] ITEM_IDS =
- + {
- + Config.BLACK_COUPON_ID
- + };
- +
- + @Override
- + public void useItem(Playable playable, Item item)
- + {
- + if (!(playable instanceof Player))
- + {
- + return;
- + }
- +
- + Player activeChar = (Player) playable;
- +
- + openRecoveryWindow(activeChar);
- + }
- +
- + private static void openRecoveryWindow(Player player)
- + {
- +
- + List<RecoverableItem> recoverableItems = getRecoverableItems(player.getObjectId());
- +
- + if (recoverableItems.isEmpty())
- + {
- +
- + player.sendMessage("No hay items recuperables disponibles.");
- + return;
- + }
- +
- + NpcHtmlMessage html = new NpcHtmlMessage(1);
- +
- + String content = generateRecoveryList(recoverableItems);
- + html.setHtml(content);
- +
- + player.sendPacket(html);
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + }
- +
- + private static String generateRecoveryList(List<RecoverableItem> recoverableItems)
- + {
- +
- + StringBuilder sb = new StringBuilder();
- + sb.append("<html><body><center><font color=\"LEVEL\">Items Recuperables</font><br><br>");
- +
- + sb.append("<font color=\"FF0000\">Solo puedes recuperar 1 item a la vez.</font><br>");
- +
- + for (RecoverableItem item : recoverableItems)
- + {
- + sb.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + sb.append("<table>");
- +
- + sb.append("<tr>");
- + sb.append("<td>");
- + sb.append("<img src=\"").append(item.getIcon()).append("\" width=32 height=32>");
- + sb.append("</td>");
- + sb.append("<td width=210><font color=\"FFFFFF\">").append(item.getItemName()).append("</font>");
- +
- + int enchantLevel = item.getEnchantLevel();
- + if (enchantLevel > 0)
- + {
- + sb.append(" <font color=\"00FF00\">+").append(enchantLevel).append("</font>");
- + }
- +
- + sb.append("</td>");
- +
- + int itemId = item.getItemId();
- + sb.append("<td><button value=\"Recuperar\" action=\"bypass -h recoverSelectedItem ").append(itemId).append(" ").append(enchantLevel).append("\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\"></td>");
- +
- + sb.append("</tr>");
- +
- + sb.append("</table>");
- + sb.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
- + sb.append("<br>");
- + }
- +
- + sb.append("</center></body></html>");
- + return sb.toString();
- + }
- +
- + private static List<RecoverableItem> getRecoverableItems(int objectId)
- + {
- + List<RecoverableItem> recoverableItems = new ArrayList<>();
- + Connection con = null;
- + PreparedStatement statement = null;
- + ResultSet resultSet = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "SELECT item_id, item_name, enchant_level FROM item_recover WHERE object_id = ? ORDER BY id DESC LIMIT 10";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, objectId);
- + resultSet = statement.executeQuery();
- +
- + while (resultSet.next())
- + {
- + int itemId = resultSet.getInt("item_id");
- + String itemName = resultSet.getString("item_name");
- + int enchantLevel = resultSet.getInt("enchant_level");
- +
- + RecoverableItem item = new RecoverableItem(objectId, itemId, itemName, enchantLevel);
- + recoverableItems.add(item);
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (resultSet != null)
- + {
- + resultSet.close();
- + }
- + if (statement != null)
- + {
- + statement.close();
- + }
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + }
- +
- + return recoverableItems;
- + }
- +
- + @Override
- + public int[] getItemIds()
- + {
- + return ITEM_IDS;
- + }
- +}
- \ No newline at end of file
- diff --git java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- index 1b2276f..990f455 100644
- --- java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- +++ java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- @@ -39,6 +39,8 @@
- import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- import org.l2jmobius.gameserver.util.GMAudit;
- +import Base.RecoverySystem.ItemRecoveryManager;
- +
- public class RequestBypassToServer implements ClientPacket
- {
- // S
- @@ -120,6 +122,19 @@
- npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(player.getX(), player.getY(), player.getZ(), 0));
- }
- }
- + else if (_command.startsWith("recoverSelectedItem"))
- + {
- + String[] bypassParts = _command.split(" ");
- + if (bypassParts.length >= 3)
- + {
- + int itemId = Integer.parseInt(bypassParts[1]);
- + int enchantLevel = Integer.parseInt(bypassParts[2]);
- +
- + ItemRecoveryManager itemRecoveryManager = new ItemRecoveryManager();
- + itemRecoveryManager.recoverSelectedItem(player, itemId, enchantLevel);
- + }
- + }
- +
- else if (_command.startsWith("player_help "))
- {
- final String path = _command.substring(12);
- diff --git java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java
- index 296484a..9430db4 100644
- --- java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java
- +++ java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java
- @@ -16,7 +16,12 @@
- */
- package org.l2jmobius.gameserver.network.clientpackets;
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.SQLException;
- +
- import org.l2jmobius.Config;
- +import org.l2jmobius.commons.database.DatabaseFactory;
- import org.l2jmobius.commons.network.ReadablePacket;
- import org.l2jmobius.commons.util.Rnd;
- import org.l2jmobius.gameserver.enums.IllegalActionPunishmentType;
- @@ -733,6 +738,8 @@
- player.broadcastUserInfo();
- final World world = World.getInstance();
- + saveBrokenItemInfo(player.getObjectId(), item.getItemId(), item.getItemName(), item.getEnchantLevel());
- +
- world.removeObject(destroyItem);
- }
- else if (blessedScroll)
- @@ -756,4 +763,47 @@
- player.sendPacket(new ItemList(player, false)); // TODO update only the enchanted item
- player.broadcastUserInfo();
- }
- +
- + private static void saveBrokenItemInfo(int objectId, int itemId, String itemName, int enchantLevel)
- + {
- + Connection con = null;
- + PreparedStatement statement = null;
- +
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + String sql = "INSERT INTO item_recover (object_id, item_id, item_name, enchant_level) VALUES (?, ?, ?, ?)";
- + statement = con.prepareStatement(sql);
- + statement.setInt(1, objectId);
- + statement.setInt(2, itemId);
- + statement.setString(3, itemName);
- + statement.setInt(4, enchantLevel);
- + statement.execute();
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + finally
- + {
- +
- + try
- + {
- + if (statement != null)
- + {
- + statement.close();
- + }
- + if (con != null)
- + {
- + con.close();
- + }
- + }
- + catch (SQLException e)
- + {
- +
- + e.printStackTrace();
- + }
- + }
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement