|
wrote this in less than 30mins, some1 could prolly use this.
Code could be improved.
Pics/gifs
Spoiler for click here fella:
NOTE: the reason u see 0 coins displayed in the interface, is because when u send a negative amount to the client it displays it as 0, and the reason its negative is because of overflow - feel free to read more about it here: https://www.tutorialspoint.com/Java-...-and-underflow
However this is easily fixable, and theres several ways to go about it.
Also, the interface is nothing special, i just used some sprites for it that i had in my cache.
Code:
Client:
Server:Code:private static void dropSimulator(TextDrawingArea[] tda) { RSInterface main = addInterface(57392); addSpriteLoader(57393, 1079); addSpriteLoader(57394, 1098); addHoverButtonWSpriteLoader(57650, 1095, 147, 32, "Set simulation amount", -1, 57651, 1); addHoveredImageWSpriteLoader(57651, 1096, 147, 32, 57652); addHoverButtonWSpriteLoader(57653, 1095, 147, 32, "Simulate drops", -1, 57654, 1); addHoveredImageWSpriteLoader(57654, 1096, 147, 32, 57655); addText(57656, "Set simulation amount", tda, 1, ColorConstants.WHITE); addText(57657, "Simulate drops", tda, 1, ColorConstants.WHITE); addText(57658, "Drop Simulator", tda, 2, ColorConstants.SKY_BLUE); addCloseButtonSmall(57659, 57660, 57661); main.totalChildren(13); main.child(0, 57393, 10, 10); main.child(1, 57394, 140, 105); main.child(2, 57399, 140, 110); main.child(3, 57410, 20, 50); main.child(4, 57650, 162, 65); main.child(5, 57651, 162, 65); main.child(6, 57653, 322, 65); main.child(7, 57654, 322, 65); main.child(8, 57656, 175, 72); main.child(9, 57657, 350, 72); main.child(10, 57658, 220, 20); main.child(11, 57659, 475, 19); main.child(12, 57660, 475, 19); RSInterface loot = addTabInterface(57399); loot.width = 330; loot.height = 190; loot.scrollMax = 400; addToItemGroup(57400, 8, 60, 9, 8, true, new String[] {null, null, null, null, null}); loot.totalChildren(1); loot.child(0, 57400, 9, 7); RSInterface npcs = addTabInterface(57410); npcs.width = 100; npcs.height = 255; npcs.scrollMax = 2500; npcs.totalChildren(150); int id = 57420; int childStart = 0; int yPos = 7; for(int i = 0; i < 150; i++) { addHoverableText(id, "", "Select", tda, 0, false, true, 100, ColorConstants.ORANGE, ColorConstants.WHITE); npcs.child(childStart, id, 0, yPos); id++; childStart++; yPos += 13; } }
Button stuff:Code:package com.arlania.world.content; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import com.arlania.model.Item; import com.arlania.model.definitions.DropUtils; import com.arlania.model.definitions.NPCDrops; import com.arlania.model.definitions.NPCDrops.DropChance; import com.arlania.model.definitions.NPCDrops.NpcDropItem; import com.arlania.model.definitions.NpcDefinition; import com.arlania.util.RandomUtility; import com.arlania.world.entity.impl.player.Player; public class DropSimulator { private Player player; public DropSimulator(Player player) { this.player = player; } public int npcId = 0, amount = 0; private Map<Integer, Integer> simulatedDrops = new HashMap<>(); public void simulateDrops() { NPCDrops npcDrops = NPCDrops.forId(npcId); NpcDropItem[] drops = npcDrops.getDropList(); // player.getPacketSender().resetItemsOnInterface(57400, simulatedDrops.size()); simulatedDrops.clear(); for (int i = 0; i < amount; i++) { getDrop(drops); } player.getPacketSender().sendItemsOnInterface(57400, simulatedDrops, true); } private static List<NpcDefinition> validNpcs = new ArrayList<>(); public void open() { player.getPacketSender().sendInterface(57392); displayNpcs(); } public boolean handleButton(int id) { if (!(id >= -8116 && id <= -8068)) { return false; } int index = -1; if (id >= -8116) { index = 8116 + id; } npcId = validNpcs.get(index).getId(); return true; } public static void initializeNpcs() { for (int i = 0; i < NpcDefinition.getDefinitions().length; i++) { NpcDefinition def = NpcDefinition.getDefinitions()[i]; if (def == null) { continue; } NPCDrops npcDrops = NPCDrops.forId(def.getId()); if (npcDrops == null) { System.out.println(def.getId() + " Has no drops"); continue; } if (def.getHitpoints() >= 10000) { validNpcs.add(NpcDefinition.getDefinitions()[i]); } } final Comparator<NpcDefinition> hitpointsDescComp = Comparator.comparing(NpcDefinition::getHitpoints) .reversed(); Collections.sort(validNpcs, hitpointsDescComp); } private void displayNpcs() { int id = 57420; for (NpcDefinition npc : validNpcs) { player.getPacketSender().sendString(id++, npc.getName()); } } private void getDrop(NpcDropItem[] drops) { boolean hasRecievedDrop = false; int playerDr = DropUtils.drBonus(player); for (int i = 0; i < drops.length; i++) { int chance = drops[i].getChance().getRandom(); int adjustedDr = (int) Math.floor(chance / (playerDr > 0 ? (DropUtils.drBonus(player) / 100.0) + 1 : 1)) + (playerDr > 0 ? 1 : 0); // to account for player's drop rate bonus, when simulating the drops if (drops[i].getChance() == DropChance.ALWAYS || adjustedDr == 1) { Item drop = drops[i].getItem(); simulatedDrops.merge(drop.getId(), drop.getAmount(), Integer::sum); } else if (RandomUtility.getRandom(adjustedDr) == 1 && !hasRecievedDrop) { Item drop = drops[i].getItem(); simulatedDrops.merge(drop.getId(), drop.getAmount(), Integer::sum); hasRecievedDrop = true; } } } }
this also accounts for drop rate(since i had it on my server) so feel free to delete it if u don't want itCode:if (player.getDropSimulator().handleButton(id)) { return true; } /** * Drop simulator */ case -7886: if (!player.getClickDelay().elapsed(3000)) { player.sendMessage("@red@Please wait atleast 3 seconds between each simulation"); return; } else { player.getPacketSender().sendEnterInputPrompt("How many would you like to simulate drops for?"); player.setInputHandling(new SetDropSimulationAmount()); player.getClickDelay().reset(); } break; case -7883: player.getDropSimulator().simulateDrops(); break;
Sprites: https://www.sendspace.com/file/st2g4e
Credit to: https://www.rune-server.ee/members/lethalleonard/ as i used a part of his method that he wrote for picking the drops.
Last edited by Suic; 09-30-2019 at 03:44 PM. Reason: Edited simulateDrops method no longer sends more than 1 packet per simulation
Very nice contribute mate, Someone will definetely use this.
should make it so you search the npc name in some sort of input field instead of every single one right there
and this doesnt edit the drops in real time just makes it so 'as if you killed the npc' ?
???
Code:case -7886:
thank u sooic
Edited simulateDrops method, no longer sends more than 1 packet per simulation
Code:public void simulateDrops() { NPCDrops npcDrops = NPCDrops.forId(npcId); NpcDropItem[] drops = npcDrops.getDropList(); // player.getPacketSender().resetItemsOnInterface(57400, simulatedDrops.size()); simulatedDrops.clear(); for (int i = 0; i < amount; i++) { getDrop(drops); } player.getPacketSender().sendItemsOnInterface(57400, simulatedDrops, true); }
Nice, I might actually edit this and use it. Saves me some effort
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |