Thread: NPC Drop simulator w/ interface

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28
  1. #11  
    nice


    Join Date
    Jul 2014
    Posts
    665
    Thanks given
    288
    Thanks received
    341
    Discord
    View profile
    Rep Power
    2952
    Quote Originally Posted by Nighel View Post
    Then fix it to not overflow
    thats what i did, after the comment, i even released a snippet to fix negative id's in a switch statement.

    Quote Originally Posted by Tamatea View Post
    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
    yeh, wrote a simple program that does it for me thought.
    and Singleton in this scenario wouldn't even be a bad idea tbf.
    Reply With Quote  
     

  2. #12  
    Extreme Donator
    Noah's Avatar
    Join Date
    Jul 2019
    Posts
    85
    Thanks given
    9
    Thanks received
    20
    Discord
    View profile
    Rep Power
    66
    Thanks this looks awesome!
    Reply With Quote  
     

  3. Thankful user:


  4. #13  
    Registered Member
    Join Date
    Jun 2010
    Posts
    632
    Thanks given
    61
    Thanks received
    22
    Rep Power
    49
    Quote Originally Posted by Suic View Post
    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: [Only registered and activated users can see links. ]
    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("@[email protected] 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: [Only registered and activated users can see links. ]

    Credit to: [Only registered and activated users can see links. ] as i used a part of his method that he wrote for picking the drops.
    can u give me your addToItemGroup method?


    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  5. #14  
    nice


    Join Date
    Jul 2014
    Posts
    665
    Thanks given
    288
    Thanks received
    341
    Discord
    View profile
    Rep Power
    2952
    Quote Originally Posted by MarkQ View Post
    can u give me your addToItemGroup method?
    Sure I'm not in pc atm tho (2am here) ill edit my post tomorrow unless I'll forget
    Reply With Quote  
     

  6. #15  
    Registered Member
    Join Date
    Jun 2010
    Posts
    632
    Thanks given
    61
    Thanks received
    22
    Rep Power
    49
    Quote Originally Posted by Suic View Post
    Sure I'm not in pc atm tho (2am here) ill edit my post tomorrow unless I'll forget
    okay nice thank you


    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  7. #16  
    Registered Member
    Join Date
    Aug 2019
    Posts
    51
    Thanks given
    9
    Thanks received
    4
    Rep Power
    11
    thank you
    Reply With Quote  
     

  8. #17  
    Registered Member
    Join Date
    Jun 2010
    Posts
    632
    Thanks given
    61
    Thanks received
    22
    Rep Power
    49
    and which drop System are u using? im too stupid to rewrite it to mine xd


    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  9. #18  
    nice


    Join Date
    Jul 2014
    Posts
    665
    Thanks given
    288
    Thanks received
    341
    Discord
    View profile
    Rep Power
    2952
    Quote Originally Posted by MarkQ View Post
    and which drop System are u using? im too stupid to rewrite it to mine xd
    Ruses but half of it is rewritten
    Reply With Quote  
     

  10. #19  
    Registered Member
    Join Date
    Jun 2010
    Posts
    632
    Thanks given
    61
    Thanks received
    22
    Rep Power
    49
    Quote Originally Posted by Suic View Post
    Ruses but half of it is rewritten
    still Need your addToItemGroup method, would be nice


    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  11. #20  
    Donator


    Join Date
    Aug 2012
    Posts
    2,479
    Thanks given
    312
    Thanks received
    459
    Rep Power
    457
    Algorithm kinda slow, it'd probably cause lag on other players who were also running simulators. Cool non the less nice release


    Reply With Quote  
     

  12. Thankful user:


Page 2 of 3 FirstFirst 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
  •