Thread: NPC Drop simulator w/ interface

Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1 NPC Drop simulator w/ interface 
    nice


    Join Date
    Jul 2014
    Posts
    740
    Thanks given
    382
    Thanks received
    562
    Rep Power
    4239
    wrote this in less than 30mins, some1 could prolly use this.
    Code could be improved.

    Pics/gifs

    Spoiler for click here fella:

    Attached image
    Attached image
    Attached image


    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:
    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;
    		}
    		
    	}
    Server:

    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;
    			}
    
    		}
    
    	}
    
    }
    Button stuff:

    Code:
    		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;
    this also accounts for drop rate(since i had it on my server) so feel free to delete it if u don't want it

    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
    Reply With Quote  
     


  2. #2  
    Banned NPC Drop simulator w/ interface Market Banned

    Join Date
    Jun 2019
    Posts
    90
    Thanks given
    5
    Thanks received
    28
    Rep Power
    0
    Very nice contribute mate, Someone will definetely use this.
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    Join Date
    Jan 2017
    Posts
    195
    Thanks given
    13
    Thanks received
    27
    Rep Power
    13
    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' ?
    Reply With Quote  
     

  5. #4  
    Rune-Server Affiliate

    Join Date
    Apr 2014
    Posts
    1,761
    Thanks given
    75
    Thanks received
    714
    Rep Power
    1073
    ???
    Code:
    case -7886:
    Reply With Quote  
     

  6. #5  
    nice


    Join Date
    Jul 2014
    Posts
    740
    Thanks given
    382
    Thanks received
    562
    Rep Power
    4239
    Quote Originally Posted by Zion View Post
    ???
    Code:
    case -7886:
    317 n negative button ids :l
    p much the client writes an unsigned short, but server reads a signed short, causing overflow.

    Quote Originally Posted by socklol View Post
    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' ?
    ye could use client-sided input field, also indeed, this just generates a random drop, as if u killed the npc.
    Reply With Quote  
     

  7. #6  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    thank u sooic
    Reply With Quote  
     

  8. Thankful user:


  9. #7  
    nice


    Join Date
    Jul 2014
    Posts
    740
    Thanks given
    382
    Thanks received
    562
    Rep Power
    4239
    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);
    
    	}
    Reply With Quote  
     

  10. #8  
    Extreme Donator


    Join Date
    Aug 2016
    Posts
    597
    Thanks given
    109
    Thanks received
    96
    Rep Power
    254
    Nice, I might actually edit this and use it. Saves me some effort
    Reply With Quote  
     

  11. Thankful user:


  12. #9  
    Donator


    Join Date
    Jan 2010
    Age
    29
    Posts
    4,122
    Thanks given
    274
    Thanks received
    551
    Rep Power
    738
    Quote Originally Posted by Suic View Post
    317 n negative button ids :l
    p much the client writes an unsigned short, but server reads a signed short, causing overflow.



    ye could use client-sided input field, also indeed, this just generates a random drop, as if u killed the npc.
    Then fix it to not overflow
    Reply With Quote  
     

  13. Thankful user:


  14. #10  
    Registered Member
    Tamatea's Avatar
    Join Date
    Aug 2010
    Posts
    1,317
    Thanks given
    401
    Thanks received
    357
    Rep Power
    2457
    Quote Originally Posted by Nighel View Post
    Then fix it to not overflow
    As simple as it would be to fix it, i don't think people can be bothered going through and fixing the hundreds of botched case labels.

    OT:
    I'd probs use a Singleton, but that's just me. Nice contribution
    Spoiler for sig too large:


    Attached image
    Attached image
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Boss Pets: NPC, Drop & Interface [718]
    By zabix18 in forum Snippets
    Replies: 30
    Last Post: 01-11-2020, 10:04 PM
  2. Request npc drop table system +interface
    By nike123 in forum Requests
    Replies: 1
    Last Post: 03-23-2018, 10:54 PM
  3. Adding NPC Drop's
    By newservermaker in forum Tutorials
    Replies: 4
    Last Post: 03-26-2008, 07:02 PM
  4. adding npc drops (the real noob way)
    By fabjan in forum Tutorials
    Replies: 9
    Last Post: 10-26-2007, 01:41 PM
  5. Npc drops change when...
    By Frozen in forum Tutorials
    Replies: 7
    Last Post: 09-30-2007, 04:05 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •