From d5562a2727f72aa2234b4d206473d6a59c801bc1 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:20:37 -0500 Subject: [PATCH 1/7] Added drops command --- .../rs2/game/npcs/drops/NPCDropsHandler.java | 5 ++ .../com/rs2/net/packets/impl/Commands.java | 73 +++++++++++++++++++ .../org/apollo/cache/def/ItemDefinition.java | 12 +++ 3 files changed, 90 insertions(+) diff --git a/2006Scape Server/src/main/java/com/rs2/game/npcs/drops/NPCDropsHandler.java b/2006Scape Server/src/main/java/com/rs2/game/npcs/drops/NPCDropsHandler.java index 3542999c4..7218793c4 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/npcs/drops/NPCDropsHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/game/npcs/drops/NPCDropsHandler.java @@ -14,6 +14,7 @@ */ public class NPCDropsHandler { + private static NpcDrop[] npcDrops; /*public static int // found on http://runescape.wikia.com/wiki/Drop rate @@ -63,4 +64,8 @@ public static int r(int max) { return Misc.random(max); } + public static NpcDrop[] getNpcDrops() { + return npcDrops; + } + } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index 6b7617936..44e52d5ec 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import static com.rs2.game.npcs.drops.NPCDropsHandler.*; import static com.rs2.util.GameLogger.writeLog; import java.util.*; @@ -10,13 +11,17 @@ import com.rs2.game.bots.BotHandler; import com.rs2.game.npcs.NPCDefinition; import com.rs2.game.npcs.NpcHandler; +import com.rs2.game.npcs.drops.ItemDrop; +import com.rs2.game.npcs.drops.NPCDropsHandler; import com.rs2.game.players.*; import com.rs2.game.players.antimacro.AntiSpam; import com.rs2.integrations.discord.JavaCord; import com.rs2.net.Packet; import com.rs2.net.packets.PacketType; import com.rs2.util.Misc; +import com.rs2.util.NpcDrop; import com.rs2.world.clip.Region; +import org.apollo.cache.def.ItemDefinition; import java.util.Calendar; import java.util.GregorianCalendar; @@ -48,6 +53,74 @@ public void processPacket(Player player, Packet packet) { public static void playerCommands(Player player, String playerCommand, String[] arguments) { switch (playerCommand.toLowerCase()) { + case "drops": + boolean found = false; + + // Check if arguments are provided (item ID or name) + if (arguments.length < 1) { + player.getPacketSender().sendMessage("Please provide an item ID or name."); + break; + } + + // If the argument can be parsed as an integer, treat it as an item ID + try { + int itemId = Integer.parseInt(arguments[0]); + + // Search by item ID + for (NpcDrop npcDrop : NPCDropsHandler.getNpcDrops()) { + for (ItemDrop itemDrop : npcDrop.getItems()) { + if (itemDrop.item_id == itemId) { // Check if the item ID matches + // Get NPC info + String npcName = NPCDefinition.forId(npcDrop.getId()).getName(); + int npcCombatLevel = NPCDefinition.forId(npcDrop.getId()).getCombat(); + if (npcCombatLevel > 0) { + // Display NPC details with println + System.out.println("NPC ID: " + npcDrop.getId() + + " | Name: " + npcName + + " | Combat Level: " + npcCombatLevel + + " | Item ID: " + itemDrop.item_id + + " | Drop Chance: " + itemDrop.chance); + found = true; + } + } + } + } + + } catch (NumberFormatException e) { + // If the argument is not a valid integer, assume it's an item name and search by name + String itemName = arguments[0].toLowerCase(); + + // Search by item name + for (NpcDrop npcDrop : NPCDropsHandler.getNpcDrops()) { + for (ItemDrop itemDrop : npcDrop.getItems()) { + // Assuming you have a method to get an item name from the item ID + String dropItemName = ItemDefinition.forId(itemDrop.item_id).getName().toLowerCase(); + if (dropItemName.contains(itemName)) { // Check if the name matches (case insensitive) + // Get NPC info + String npcName = NPCDefinition.forId(npcDrop.getId()).getName(); + int npcCombatLevel = NPCDefinition.forId(npcDrop.getId()).getCombat(); + if (npcCombatLevel > 0) { + // Display NPC details with println + System.out.println("NPC ID: " + npcDrop.getId() + + " | Name: " + npcName + + " | Combat Level: " + npcCombatLevel + + " | Item ID: " + itemDrop.item_id + + " | Item Name: " + dropItemName + + " | Drop Chance: " + itemDrop.chance); + found = true; + } + } + } + } + } + + if (!found) { + player.getPacketSender().sendMessage("No NPCs found with the specified item ID or name."); + } + // Print message indicating drops info was sent + player.getPacketSender().sendMessage("Sent drops info"); + + break; case "stuck": if(JavaCord.token != null) { if (JavaCord.api != null && JavaCord.api.getTextChannelById(JavaCord.logChannelId).isPresent()) diff --git a/2006Scape Server/src/main/java/org/apollo/cache/def/ItemDefinition.java b/2006Scape Server/src/main/java/org/apollo/cache/def/ItemDefinition.java index b20b38ae0..9d3163171 100644 --- a/2006Scape Server/src/main/java/org/apollo/cache/def/ItemDefinition.java +++ b/2006Scape Server/src/main/java/org/apollo/cache/def/ItemDefinition.java @@ -98,6 +98,18 @@ public static ItemDefinition lookup(int id) { } return definitions[id]; } + + /** + * Alias for lookup(id) + * Gets the item definition for the specified id. + * + * @param id The id. + * @return The definition. + * @throws IndexOutOfBoundsException If the id is out of bounds. + */ + public static ItemDefinition forId(int id) { + return lookup(id); + } /** * Converts a noted id to the normal item id. From 60ecce51d9df569cf149c165f12f53dfb350aa24 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:24:44 -0500 Subject: [PATCH 2/7] Fixed drops command NPE --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index 44e52d5ec..a716ba5d9 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -93,7 +93,10 @@ public static void playerCommands(Player player, String playerCommand, String[] // Search by item name for (NpcDrop npcDrop : NPCDropsHandler.getNpcDrops()) { for (ItemDrop itemDrop : npcDrop.getItems()) { - // Assuming you have a method to get an item name from the item ID + if (ItemDefinition.forId(itemDrop.item_id) == null || ItemDefinition.forId(itemDrop.item_id).getName() == null) { + System.out.println("Skipping null item ID: " + itemDrop.item_id); + continue; + } String dropItemName = ItemDefinition.forId(itemDrop.item_id).getName().toLowerCase(); if (dropItemName.contains(itemName)) { // Check if the name matches (case insensitive) // Get NPC info From 8f9c5909c935bd41218f17f74042d5eda18415ea Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:25:50 -0500 Subject: [PATCH 3/7] Added comment --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index a716ba5d9..0fb90bf85 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -93,7 +93,7 @@ public static void playerCommands(Player player, String playerCommand, String[] // Search by item name for (NpcDrop npcDrop : NPCDropsHandler.getNpcDrops()) { for (ItemDrop itemDrop : npcDrop.getItems()) { - if (ItemDefinition.forId(itemDrop.item_id) == null || ItemDefinition.forId(itemDrop.item_id).getName() == null) { + if (ItemDefinition.forId(itemDrop.item_id) == null || ItemDefinition.forId(itemDrop.item_id).getName() == null) { // Check if the item is null, since there can be placeholder items System.out.println("Skipping null item ID: " + itemDrop.item_id); continue; } From c168417576d6add67477d00a6b9249a619b11bdc Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:27:11 -0500 Subject: [PATCH 4/7] Updated drops command comment --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index 0fb90bf85..1572f7e77 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -93,7 +93,7 @@ public static void playerCommands(Player player, String playerCommand, String[] // Search by item name for (NpcDrop npcDrop : NPCDropsHandler.getNpcDrops()) { for (ItemDrop itemDrop : npcDrop.getItems()) { - if (ItemDefinition.forId(itemDrop.item_id) == null || ItemDefinition.forId(itemDrop.item_id).getName() == null) { // Check if the item is null, since there can be placeholder items + if (ItemDefinition.forId(itemDrop.item_id) == null || ItemDefinition.forId(itemDrop.item_id).getName() == null) { // Check if the item is null, since there can be placeholder items in the cache System.out.println("Skipping null item ID: " + itemDrop.item_id); continue; } From 970a92a83682175ac56310251f66638ea6cf582c Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:27:39 -0500 Subject: [PATCH 5/7] Added aliases for drops command --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index 1572f7e77..e7ea31459 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -53,6 +53,9 @@ public void processPacket(Player player, Packet packet) { public static void playerCommands(Player player, String playerCommand, String[] arguments) { switch (playerCommand.toLowerCase()) { + case "npcdrops": + case "searchdrops": + case "searchnpcdrops": case "drops": boolean found = false; From da59a3510ecac14b9319a9dcbb54dd8e5d1c310e Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:28:46 -0500 Subject: [PATCH 6/7] Added comment for drops command --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index e7ea31459..bb14aca9c 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -56,7 +56,7 @@ public static void playerCommands(Player player, String playerCommand, String[] case "npcdrops": case "searchdrops": case "searchnpcdrops": - case "drops": + case "drops": // Possible usage: ::drops dragon boolean found = false; // Check if arguments are provided (item ID or name) From f776f85a545767b352b076e3a45ed8ed297de9e1 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Sun, 19 Jan 2025 16:40:46 -0500 Subject: [PATCH 7/7] Updated example drops command --- .../src/main/java/com/rs2/net/packets/impl/Commands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index bb14aca9c..ce1626f67 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -56,7 +56,7 @@ public static void playerCommands(Player player, String playerCommand, String[] case "npcdrops": case "searchdrops": case "searchnpcdrops": - case "drops": // Possible usage: ::drops dragon + case "drops": // Possible usage: ::drops scim boolean found = false; // Check if arguments are provided (item ID or name)