Thread: 718 Changing NPC drops

Results 1 to 6 of 6
  1. #1 718 Changing NPC drops 
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    26
    Posts
    1,552
    Thanks given
    544
    Thanks received
    435
    Rep Power
    189
    It seems that the NPC drops are packed... but there is no unpacked in the data folder. Does anyone mind telling me how to edit the npc drops?
    Reply With Quote  
     

  2. #2  
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    26
    Posts
    1,552
    Thanks given
    544
    Thanks received
    435
    Rep Power
    189
    bump...
    Reply With Quote  
     

  3. #3  
    Gunner4Life Market Banned Market Banned



    Join Date
    Jun 2011
    Posts
    2,357
    Thanks given
    132
    Thanks received
    666
    Rep Power
    648
    you need to add you own .txt lol
    Reply With Quote  
     

  4. #4  
    Registered Member Sherlock's Avatar
    Join Date
    Jun 2014
    Posts
    101
    Thanks given
    8
    Thanks received
    7
    Rep Power
    14
    src/com/rs/tools make a folder called DropEditor

    Put this into it
    Code:
    package com.rs.tools;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.Map.Entry;
    import java.util.Random;
    import java.util.SortedMap;
    import java.util.TreeMap;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.tree.*;
    
    import com.rs.Settings;
    import com.rs.cache.Cache;
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.cache.loaders.NPCDefinitions;
    import com.rs.game.npc.Drop;
    import com.rs.utils.NPCDrops;
    import com.rs.utils.Utils;
    import com.rs.utils.console.Console;
    import com.rs.utils.console.ConsoleLogger;
    
    
    
    
    /**
     * @author Marvin
     */
    public class DropEditor extends JFrame {
    
    	private static final long serialVersionUID = 1L;
    	private DefaultMutableTreeNode dropsNode = new DefaultMutableTreeNode("Drops");
    	private DefaultTreeModel dropsTreeModel = new DefaultTreeModel(dropsNode);
    	private NPCDrops loader = new NPCDrops();
    	Random random = new Random();
    	private JMenuItem dumpSpecificDropMenuItem;
    	private JProgressBar progressBar;
    	private JPopupMenu tablePopup;
    	private JMenuItem testItem;
    
    	/**
    	 * Creates new form DropEditor
    	 */
    	public DropEditor() {
    		try {
    			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    		} catch (ClassNotFoundException | InstantiationException
    				| IllegalAccessException | UnsupportedLookAndFeelException ex) {
    		}
    		try {
    			Cache.init();
    			NPCDrops.init();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    		SortedMap<Integer, ArrayList<Drop>> values = new TreeMap<Integer, ArrayList<Drop>>(
    				new Comparator<Integer>() {
    
    					@Override
    					public int compare(Integer o1, Integer o2) {
    						if (o1 > o2) {
    							return 1;
    						} else if (o1 < o2) {
    							return -1;
    						}
    						return 0;
    					}
    				});
    
    		values.putAll(loader.getDropArray());
    
    		loader.getDropArray().putAll(values);
    
    		for (Entry<Integer, ArrayList<Drop>> s : loader.getDropArray().entrySet()) {
    			dropsNode.add(new DefaultMutableTreeNode(s.getKey()));
    		}
    		initComponents();
    	}
    
    	/**
    	 * This method is called from within the constructor to initialize the form.
    	 * WARNING: Do NOT modify this code. The content of this method is always
    	 * regenerated by the Form Editor.
    	 */
    
    	// <editor-fold defaultstate="collapsed"
    	// desc="Generated Code">//GEN-BEGIN:initComponents
    	private void initComponents() {
    
    		treeScroll = new JScrollPane();
    		dropsTree = new JTree();
    		searchField = new JTextField();
    		searchIdLabel = new JLabel();
    		middleSeparator = new JSeparator();
    		dropsPanel = new JPanel();
    		dropsForLabel = new JLabel();
    		headerSeparator = new JSeparator();
    		npcIdLabel = new JLabel();
    		tableScroll = new JScrollPane();
    		dropTable = new JTable();
    		tablePopup = new JPopupMenu();
    		testItem = new JMenuItem("Test Rate");
    		addNew = new JButton();
    		deleteSelected = new JButton();
    		repackDrop = new JButton();
    		scanButton = new JButton();
    		addNewButton = new JButton();
    		removeDrop = new JButton();
    		fileMenu = new JMenuBar();
    		jMenu1 = new JMenu();
    		scan = new JMenuItem();
    		dumpDropMenuItem = new JMenuItem();
    		dumpSpecificDropMenuItem = new JMenuItem();
    		progressBar = new JProgressBar(-1, Utils.getNPCDefinitionsSize());
    		progressBar.setStringPainted(true);
    
    		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    		setIconImage(new ImageIcon("./data/tools/icon.png").getImage());
    		setTitle(Settings.SERVER_NAME + " Drop Editor");
    
    		dropsTree.setModel(dropsTreeModel);
    		dropsTree.addTreeSelectionListener(new TreeSelectionListener() {
    					public void valueChanged(TreeSelectionEvent evt) {
    						dropsTreeValueChanged(evt);
    					}
    				});
    		treeScroll.setViewportView(dropsTree);
    
    		searchField.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				searchFieldActionPerformed(evt);
    			}
    		});
    
    		searchIdLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    		searchIdLabel.setText("Search ID:");
    
    		middleSeparator.setOrientation(SwingConstants.VERTICAL);
    
    		dropsForLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		dropsForLabel.setText("Drops for NPC ID:");
    
    		npcIdLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		npcIdLabel.setText(" ");
    
    		dropTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] {}));
    		testItem.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				testDropRate(arg0);
    
    			}
    		});
    		tablePopup.add(testItem);
    
    		dropTable.addMouseListener(new MouseListener() {
    
    			@Override
    			public void mouseClicked(MouseEvent arg0) {
    				if (arg0.getButton() == MouseEvent.BUTTON3) {
    					int row = dropTable.rowAtPoint(arg0.getPoint());
    					dropTable.changeSelection(row, dropTable.getSelectedColumn(), false, false);
    					tablePopup.show(dropTable, arg0.getX(), arg0.getY());
    				}
    
    			}
    
    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    		});
    		tableScroll.setViewportView(dropTable);
    
    		addNew.setText("Add New Drop");
    		addNew.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent evt) {
    				addNewActionPerformed(evt);
    			}
    		});
    
    		deleteSelected.setText("Delete Selected Drop");
    		deleteSelected.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				deleteSelectedActionPerformed(evt);
    			}
    		});
    
    		repackDrop.setText("Repack");
    		repackDrop.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				repackDropActionPerformed(evt);
    			}
    		});
    
    		scanButton.setText("Scan");
    		scanButton.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				scanListActionPerformed(evt);
    			}
    		});
    		
    		GroupLayout dropsPanelLayout = new GroupLayout(dropsPanel);
    		dropsPanel.setLayout(dropsPanelLayout);
    		dropsPanelLayout
    				.setHorizontalGroup(dropsPanelLayout
    						.createParallelGroup(
    								GroupLayout.Alignment.LEADING)
    						.addGroup(
    								GroupLayout.Alignment.TRAILING,
    								dropsPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.TRAILING)
    														.addComponent(
    																headerSeparator,
    																GroupLayout.Alignment.LEADING,
    																GroupLayout.DEFAULT_SIZE,
    																424,
    																Short.MAX_VALUE)
    														.addGroup(GroupLayout.Alignment.LEADING, dropsPanelLayout.createSequentialGroup().addComponent(dropsForLabel)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
    															.addComponent(npcIdLabel, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
    														.addComponent( tableScroll, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
    														.addGroup(GroupLayout.Alignment.LEADING,dropsPanelLayout.createSequentialGroup()
    															.addComponent(addNew, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addComponent(deleteSelected,GroupLayout.DEFAULT_SIZE,101,Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addComponent(repackDrop, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															//.addComponent(scanButton, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addContainerGap()))));
    		dropsPanelLayout
    				.setVerticalGroup(dropsPanelLayout
    						.createParallelGroup(
    								GroupLayout.Alignment.LEADING)
    						.addGroup(
    								dropsPanelLayout
    										.createSequentialGroup()
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																dropsForLabel)
    														.addComponent(
    																npcIdLabel))
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.RELATED)
    										.addComponent(
    												headerSeparator,
    												GroupLayout.PREFERRED_SIZE,
    												9,
    												GroupLayout.PREFERRED_SIZE)
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.UNRELATED)
    										.addComponent(
    												tableScroll,
    												GroupLayout.DEFAULT_SIZE,
    												327, Short.MAX_VALUE)
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.RELATED)
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(addNew)
    														.addComponent(
    																deleteSelected)
    														.addComponent(
    																repackDrop))
    										.addContainerGap()));
    
    		addNewButton.setText("Add New NPC Drop");
    		addNewButton.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				addNewButtonActionPerformed(evt);
    			}
    		});
    
    		removeDrop.setText("Remove NPC Drop");
    		removeDrop.setToolTipText("Removes the currently Selected NPC Drop");
    		removeDrop.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				removeDropActionPerformed(evt);
    			}
    		});
    
    		jMenu1.setText("File");
    
    		scan.setText("Scan for High Amounts");
    		scan.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				scanListActionPerformed(evt);
    			}
    		});
    		jMenu1.add(scan);
    		dumpDropMenuItem.setText("Dump all monster drops");
    		dumpDropMenuItem.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				dumpDropMenuItemActionPerformed(evt);
    			}
    		});
    		jMenu1.add(dumpDropMenuItem);
    		dumpSpecificDropMenuItem.setText("Dump specific monster drop");
    		dumpSpecificDropMenuItem
    				.addActionListener(new java.awt.event.ActionListener() {
    
    					public void actionPerformed(java.awt.event.ActionEvent evt) {
    						dumpSpecificDropMenuItemActionPerformed(evt);
    					}
    				});
    		jMenu1.add(dumpSpecificDropMenuItem);
    
    		fileMenu.add(jMenu1);
    
    		setJMenuBar(fileMenu);
    
    		GroupLayout layout = new GroupLayout(
    				getContentPane());
    		getContentPane().setLayout(layout);
    		layout.setHorizontalGroup(layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addContainerGap()
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.LEADING,
    												false)
    												.addComponent(
    														removeDrop,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														Short.MAX_VALUE)
    												.addGroup(
    														layout.createSequentialGroup()
    																.addComponent(
    																		searchIdLabel)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.UNRELATED)
    																.addComponent(
    																		searchField,
    																		GroupLayout.PREFERRED_SIZE,
    																		67,
    																		GroupLayout.PREFERRED_SIZE))
    												.addComponent(
    														progressBar,
    														GroupLayout.PREFERRED_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.PREFERRED_SIZE)
    												.addComponent(
    														treeScroll,
    														GroupLayout.DEFAULT_SIZE,
    														134, Short.MAX_VALUE)
    												.addComponent(
    														addNewButton,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														Short.MAX_VALUE))
    								.addPreferredGap(
    										LayoutStyle.ComponentPlacement.UNRELATED)
    								.addComponent(middleSeparator,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addGap(18, 18, 18)
    								.addComponent(dropsPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addContainerGap()));
    		layout.setVerticalGroup(layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.TRAILING)
    												.addGroup(
    														GroupLayout.Alignment.LEADING,
    														layout.createSequentialGroup()
    																.addContainerGap()
    																.addGroup(
    																		layout.createParallelGroup(
    																				GroupLayout.Alignment.LEADING)
    																				.addComponent(
    																						dropsPanel,
    																						GroupLayout.Alignment.TRAILING,
    																						GroupLayout.DEFAULT_SIZE,
    																						GroupLayout.DEFAULT_SIZE,
    																						Short.MAX_VALUE)
    																				.addComponent(
    																						middleSeparator,
    																						GroupLayout.DEFAULT_SIZE,
    																						410,
    																						Short.MAX_VALUE)))
    												.addGroup(
    														layout.createSequentialGroup()
    																.addGap(15, 15,
    																		15)
    																.addComponent(
    																		treeScroll)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		addNewButton)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		removeDrop)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addGroup(
    																		layout.createParallelGroup(
    																				GroupLayout.Alignment.TRAILING)
    																				.addComponent(
    																						searchIdLabel)
    																				.addComponent(
    																						searchField,
    																						GroupLayout.PREFERRED_SIZE,
    																						GroupLayout.DEFAULT_SIZE,
    																						GroupLayout.PREFERRED_SIZE))
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		progressBar,
    																		GroupLayout.PREFERRED_SIZE,
    																		GroupLayout.DEFAULT_SIZE,
    																		GroupLayout.PREFERRED_SIZE)))
    								.addContainerGap()));
    
    		pack();
    	}// </editor-fold>//GEN-END:initComponents
    
    	protected void testDropRate(ActionEvent arg0) {
    		ArrayList<Drop> drops = loader.getDropArray().get(
    		Integer.parseInt(dropsTree.getLastSelectedPathComponent().toString()));
    		Drop drop = drops.get(dropTable.getSelectedRow());
    		String testAmount = JOptionPane.showInputDialog(this, "Enter the amount of times you want to test(0 to test till it drops)");
    		int testAmt = 0;
    		try {
    			testAmt = Integer.parseInt(testAmount);
    		} catch (Exception e) {
    			testAmt = 0;
    		}
    		if (testAmt > 0) {
    			int successfullDrops = 0;
    			for (int i = 0; i < testAmt; i++) {
    				int chance = random.nextInt(100);
    				if (chance <= drop.getRate()) {
    					successfullDrops++;
    				}
    			}
    			JOptionPane.showMessageDialog(this, "Received the drop " + successfullDrops + " out of " + testAmt + " times");
    		} else {
    			boolean didntReceive = true;
    			int times = 0;
    			while (didntReceive) {
    				int chance = random.nextInt(100);
    				if (chance <= drop.getRate()) {
    					didntReceive = false;
    				} else {
    					times++;
    				}
    			}
    			JOptionPane.showMessageDialog(this, "Received the drop after "
    					+ times + " times");
    		}
    
    	}
    
    	protected void dumpSpecificDropMenuItemActionPerformed(ActionEvent evt) {
    		try {
    			//dump(Integer.parseInt(JOptionPane.showInputDialog(this, "Enter the NPC ID")));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	protected void dumpDropMenuItemActionPerformed(ActionEvent evt) {
    		Thread dumpThread = new Thread() {
    
    			int index = -1;
    
    			public void run() {
    				while (index < Utils.getNPCDefinitionsSize()) {
    					try {
    						progressBar.setString(NPCDefinitions.getNPCDefinitions(index).name);
    						//dump(index);
    						index++;
    						progressBar.setValue(index);
    						Thread.sleep(1);
    					} catch (Exception e) {
    						System.out.println("Problem with npc id " + index + ".");
    						index++;
    						progressBar.setValue(index);
    					}
    				}
    				packFile();
    				progressBar.setString("");
    				progressBar.setValue(-1);
    			}
    		};
    		dumpThread.start();
    	}
    
    	public DefaultMutableTreeNode searchNode(String nodeStr) {
    		DefaultMutableTreeNode nodeToSearch = null;
    		Enumeration<?> e = dropsNode.breadthFirstEnumeration();
    		while (e.hasMoreElements()) {
    			nodeToSearch = (DefaultMutableTreeNode) e.nextElement();
    			if (nodeStr.equals(nodeToSearch.getUserObject().toString())) {
    				return nodeToSearch;
    			}
    		}
    		return null;
    	}
    
    	private void searchFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_searchFieldActionPerformed
    		try {
    			DefaultMutableTreeNode n = searchNode(searchField.getText());
    			TreePath path = new TreePath(dropsTreeModel.getPathToRoot(n));
    			dropsTree.scrollPathToVisible(path);
    			dropsTree.setSelectionPath(path);
    		} catch (Exception e) {
    			JOptionPane.showMessageDialog(this, "Could not find the item.");
    		}
    	}// GEN-LAST:event_searchFieldActionPerformed
    
    	private void dropsTreeValueChanged(TreeSelectionEvent evt) {// GEN-FIRST:event_dropsTreeValueChanged
    		if (dropsTree.getLastSelectedPathComponent() != null
    				&& !"Drops".equals(dropsTree.getLastSelectedPathComponent()
    						.toString())) {
    			loadDrop(Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    					.toString()));
    		}
    	}// GEN-LAST:event_dropsTreeValueChanged
    
    	private void deleteSelectedActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSelectedActionPerformed
    		try {
    			int npcID = Integer.parseInt(dropsTree
    					.getLastSelectedPathComponent().toString());
    			ArrayList<Drop> drops = loader.getDropArray().get(npcID);
    			drops.remove(dropTable.getSelectedRow());
    			Drop[] d = new Drop[drops.size()];
    			drops.toArray(d);
    			loader.getDropMap().put(npcID, d);
    
    			loadDrop(Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    					.toString()));
    		} catch (NullPointerException e) {
    			JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		}
    	}// GEN-LAST:event_deleteSelectedActionPerformed
    
    	private void addNewActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addNewActionPerformed
    		// try {
    		int npcid = Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    				.toString());
    		// ArrayList<Drop> drops = loader.getDropArray().get(npcid);
    		loader.insertDrop(npcid, Drop.create(Integer.parseInt(JOptionPane
    				.showInputDialog("Please enter the item ID for this drop.")),
    				(int) 100.0, 1, 1, false));
    
    		loadDrop(npcid);
    		// } catch (NullPointerException e) {
    
    		// JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		// }
    	}// GEN-LAST:event_addNewActionPerformed
    
    	private void addNewButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addNewButtonActionPerformed
    		String id = JOptionPane
    				.showInputDialog("Please enter the NPC ID for this drop.");
    		if (id == null) {
    			id = "0";
    		}
    		loader.getDropArray().put(Integer.parseInt(id), new ArrayList<Drop>());
    		packFile();
    	}// GEN-LAST:event_addNewButtonActionPerformed
    
    	private void removeDropActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_removeDropActionPerformed
    		try {
    			if (!dropsTree.getLastSelectedPathComponent().toString().equals("")) {
    				loader.getDropMap().remove(
    						Integer.parseInt(dropsTree
    								.getLastSelectedPathComponent().toString()));
    				packFile();
    			}
    		} catch (NullPointerException e) {
    			JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		}
    	}// GEN-LAST:event_removeDropActionPerformed
    
    	private void repackDropActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_repackDropActionPerformed
    		packFile();
    	}// GEN-LAST:event_repackDropActionPerformed
    
    	private void scanListActionPerformed(ActionEvent evt) {
    		System.out.println("Started Scanning.");
    		
    		final int amountToFind = 100;
    		
    		java.awt.EventQueue.invokeLater(new Runnable() {
    			int count = 0;
    			public void run() {
    				for (Entry<Integer, ArrayList<Drop>> e : loader.getDropArray().entrySet()) {
    					int npcId = e.getKey();
    					for (Drop d : e.getValue()) {
    						if (d.getMinAmount()> amountToFind && d.getMaxAmount() > amountToFind) {
    							System.out.println("NPC Id:"+npcId+"");
    							System.out.println("Item Id: "+d.getItemId()+"");
    							System.out.println("Min Amount: "+Utils.formatNumber(d.getMinAmount())+"");
    							System.out.println("Max Amount: "+Utils.formatNumber(d.getMaxAmount())+"");
    							System.out.println("---------------------------------------------------------------------------------------");
    							count++;
    						}
    					}
    				}
    				System.out.println("Scanning Completed.");
    			}
    		});
    	}
    	
    	/**
    	 * @param args
    	 *            the command line arguments
    	 */
    	public static void main(String args[]) {
    		
    		Console.getInstance().setVisible(true);
    		
    		java.awt.EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				new DropEditor().setVisible(true);
    			}
    		});
    		
    		System.setOut(new ConsoleLogger(System.out));
    		System.setErr(new ConsoleLogger(System.err));
    		Console.getInstance().setVisible(true);
    	}
    
    	// Variables declaration - do not modify//GEN-BEGIN:variables
    	private JButton addNew;
    	private JButton addNewButton;
    	private JButton deleteSelected;
    	private JTable dropTable;
    	private JLabel dropsForLabel;
    	private JPanel dropsPanel;
    	private JTree dropsTree;
    	private JMenuItem scan;
    	private JMenuItem dumpDropMenuItem;
    	private JMenuBar fileMenu;
    	private JSeparator headerSeparator;
    	private JMenu jMenu1;
    	private JSeparator middleSeparator;
    	private JLabel npcIdLabel;
    	private JButton removeDrop;
    	private JButton repackDrop;
    	private JButton scanButton;
    	private JTextField searchField;
    	private JLabel searchIdLabel;
    	private JScrollPane tableScroll;
    	private JScrollPane treeScroll;
    
    	// End of variables declaration//GEN-END:variables
    
    	private void loadDrop(final int npcId) {
    		npcIdLabel.setText(Integer.toString(npcId) + " " + NPCDefinitions.getNPCDefinitions(npcId).name);
    		ArrayList<Drop> drops = loader.getDropArray().get(npcId);
    		DefaultTableModel model = new DefaultTableModel();
    		model.addTableModelListener(new TableModelListener() {
    
    			public void tableChanged(TableModelEvent e) {
    				try {
    					if (e.getColumn() != -1) {
    						if (dropTable.getValueAt(dropTable.getSelectedRow(), 0).equals("Rare")) {
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setItemId((short) -1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setRate(-1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(1);
    
    						} else {
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setItemId(Short.parseShort((String) dropTable.getValueAt(dropTable.getSelectedRow(), 0).toString()));
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setRate(Double.parseDouble((String) dropTable.getValueAt(dropTable.getSelectedRow(),1).toString()));
    							String amount = (String) dropTable.getValueAt(dropTable.getSelectedRow(), 2);
    							if (amount.contains("-")) {
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(Integer.parseInt(amount.substring(0, amount.indexOf("-"))));
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(Integer.parseInt(amount.substring(amount.indexOf("-") + 1)));
    							} else {
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(Integer.parseInt(amount));
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(Integer.parseInt(amount));
    
    							}
    						}
    					}
    				} catch (Exception f) {
    					f.printStackTrace();
    				}
    			}
    		});
    		model.addColumn("Item ID");
    		model.addColumn("Percent Chance");
    		model.addColumn("Amount");
    		for (Drop d : drops) {
    			if (d == null) {
    				continue;
    			}
    			if (!d.isFromRareTable()) {
    				model.addRow(new Object[] { (d.getItemId()), Double.toString(d.getRate()), Integer.toString(d.getMinAmount()) + (d.getMinAmount() == d.getMaxAmount() || d.getMaxAmount() == 0 ? "" : "-" + d.getMaxAmount()) });
    			} else {
    				model.addRow(new Object[] { "Rare", "100.0", "1" });
    			}
    		}
    		dropTable.setModel(model);
    	}
    
    	private void packFile() {
    		try { // //drops.bin
    			RandomAccessFile raf = new RandomAccessFile("data/npcs/packedDrops.d", "rw");
    			raf.writeShort(loader.getDropMap().size());
    			for (Entry<Integer, ArrayList<Drop>> e : loader.getDropArray().entrySet()) {
    				raf.writeShort(e.getKey());
    				raf.writeShort(e.getValue().size());
    				for (Drop d : e.getValue()) {
    
    					raf.writeByte(d.isFromRareTable() ? 1 : 0);
    					if (!d.isFromRareTable()) {
    						int itemID = d.getItemId();
    						if (ItemDefinitions.getItemDefinitions(itemID).getName().equals("Coins")) {
    							itemID = 995;
    						}
    						raf.writeShort(itemID);
    						raf.writeDouble(d.getRate());
    						if (d.getMinAmount() > d.getMaxAmount()) {
    							int min = d.getMinAmount();
    							d.setMinAmount(d.getMaxAmount());
    							d.setMaxAmount(min);
    						}
    						raf.writeInt(d.getMinAmount());
    						raf.writeInt(d.getMaxAmount());
    					}
    				}
    			}
    			raf.close();
    			System.out.println("Repacking succesful!");
    		} catch (IOException ex) {
    			System.err.println(ex);
    		}
    		reload();
    	}
    
    	private void reload() {
    		dropsNode.removeAllChildren();
    		// loader = new NPCDropLoader();
    		// loader.load();
    		for (Entry<Integer, ArrayList<Drop>> s : loader.getDropArray()
    				.entrySet()) {
    			dropsNode.add(new DefaultMutableTreeNode(s.getKey()));
    		}
    		dropsTreeModel.reload(dropsNode);
    	}
    }
    and in the source make a DropEditor.bat
    and put this in it

    @echo off
    title Npc Drop Editor
    start javaw -client -Xmx512m -cp bin;lib/* com.rs.tools.DropEditor


    Reply With Quote  
     

  5. #5  
    Success is the worst teacher

    Santa Hat's Avatar
    Join Date
    Oct 2012
    Age
    24
    Posts
    3,337
    Thanks given
    801
    Thanks received
    1,185
    Rep Power
    189
    Quote Originally Posted by _cheese View Post
    src/com/rs/tools make a folder called DropEditor

    Put this into it
    Code:
    package com.rs.tools;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.Map.Entry;
    import java.util.Random;
    import java.util.SortedMap;
    import java.util.TreeMap;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.tree.*;
    
    import com.rs.Settings;
    import com.rs.cache.Cache;
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.cache.loaders.NPCDefinitions;
    import com.rs.game.npc.Drop;
    import com.rs.utils.NPCDrops;
    import com.rs.utils.Utils;
    import com.rs.utils.console.Console;
    import com.rs.utils.console.ConsoleLogger;
    
    
    
    
    /**
     * @author Marvin
     */
    public class DropEditor extends JFrame {
    
    	private static final long serialVersionUID = 1L;
    	private DefaultMutableTreeNode dropsNode = new DefaultMutableTreeNode("Drops");
    	private DefaultTreeModel dropsTreeModel = new DefaultTreeModel(dropsNode);
    	private NPCDrops loader = new NPCDrops();
    	Random random = new Random();
    	private JMenuItem dumpSpecificDropMenuItem;
    	private JProgressBar progressBar;
    	private JPopupMenu tablePopup;
    	private JMenuItem testItem;
    
    	/**
    	 * Creates new form DropEditor
    	 */
    	public DropEditor() {
    		try {
    			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    		} catch (ClassNotFoundException | InstantiationException
    				| IllegalAccessException | UnsupportedLookAndFeelException ex) {
    		}
    		try {
    			Cache.init();
    			NPCDrops.init();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    		SortedMap<Integer, ArrayList<Drop>> values = new TreeMap<Integer, ArrayList<Drop>>(
    				new Comparator<Integer>() {
    
    					@Override
    					public int compare(Integer o1, Integer o2) {
    						if (o1 > o2) {
    							return 1;
    						} else if (o1 < o2) {
    							return -1;
    						}
    						return 0;
    					}
    				});
    
    		values.putAll(loader.getDropArray());
    
    		loader.getDropArray().putAll(values);
    
    		for (Entry<Integer, ArrayList<Drop>> s : loader.getDropArray().entrySet()) {
    			dropsNode.add(new DefaultMutableTreeNode(s.getKey()));
    		}
    		initComponents();
    	}
    
    	/**
    	 * This method is called from within the constructor to initialize the form.
    	 * WARNING: Do NOT modify this code. The content of this method is always
    	 * regenerated by the Form Editor.
    	 */
    
    	// <editor-fold defaultstate="collapsed"
    	// desc="Generated Code">//GEN-BEGIN:initComponents
    	private void initComponents() {
    
    		treeScroll = new JScrollPane();
    		dropsTree = new JTree();
    		searchField = new JTextField();
    		searchIdLabel = new JLabel();
    		middleSeparator = new JSeparator();
    		dropsPanel = new JPanel();
    		dropsForLabel = new JLabel();
    		headerSeparator = new JSeparator();
    		npcIdLabel = new JLabel();
    		tableScroll = new JScrollPane();
    		dropTable = new JTable();
    		tablePopup = new JPopupMenu();
    		testItem = new JMenuItem("Test Rate");
    		addNew = new JButton();
    		deleteSelected = new JButton();
    		repackDrop = new JButton();
    		scanButton = new JButton();
    		addNewButton = new JButton();
    		removeDrop = new JButton();
    		fileMenu = new JMenuBar();
    		jMenu1 = new JMenu();
    		scan = new JMenuItem();
    		dumpDropMenuItem = new JMenuItem();
    		dumpSpecificDropMenuItem = new JMenuItem();
    		progressBar = new JProgressBar(-1, Utils.getNPCDefinitionsSize());
    		progressBar.setStringPainted(true);
    
    		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    		setIconImage(new ImageIcon("./data/tools/icon.png").getImage());
    		setTitle(Settings.SERVER_NAME + " Drop Editor");
    
    		dropsTree.setModel(dropsTreeModel);
    		dropsTree.addTreeSelectionListener(new TreeSelectionListener() {
    					public void valueChanged(TreeSelectionEvent evt) {
    						dropsTreeValueChanged(evt);
    					}
    				});
    		treeScroll.setViewportView(dropsTree);
    
    		searchField.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				searchFieldActionPerformed(evt);
    			}
    		});
    
    		searchIdLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    		searchIdLabel.setText("Search ID:");
    
    		middleSeparator.setOrientation(SwingConstants.VERTICAL);
    
    		dropsForLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		dropsForLabel.setText("Drops for NPC ID:");
    
    		npcIdLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		npcIdLabel.setText(" ");
    
    		dropTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] {}));
    		testItem.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				testDropRate(arg0);
    
    			}
    		});
    		tablePopup.add(testItem);
    
    		dropTable.addMouseListener(new MouseListener() {
    
    			@Override
    			public void mouseClicked(MouseEvent arg0) {
    				if (arg0.getButton() == MouseEvent.BUTTON3) {
    					int row = dropTable.rowAtPoint(arg0.getPoint());
    					dropTable.changeSelection(row, dropTable.getSelectedColumn(), false, false);
    					tablePopup.show(dropTable, arg0.getX(), arg0.getY());
    				}
    
    			}
    
    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    
    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    			}
    		});
    		tableScroll.setViewportView(dropTable);
    
    		addNew.setText("Add New Drop");
    		addNew.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent evt) {
    				addNewActionPerformed(evt);
    			}
    		});
    
    		deleteSelected.setText("Delete Selected Drop");
    		deleteSelected.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				deleteSelectedActionPerformed(evt);
    			}
    		});
    
    		repackDrop.setText("Repack");
    		repackDrop.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				repackDropActionPerformed(evt);
    			}
    		});
    
    		scanButton.setText("Scan");
    		scanButton.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				scanListActionPerformed(evt);
    			}
    		});
    		
    		GroupLayout dropsPanelLayout = new GroupLayout(dropsPanel);
    		dropsPanel.setLayout(dropsPanelLayout);
    		dropsPanelLayout
    				.setHorizontalGroup(dropsPanelLayout
    						.createParallelGroup(
    								GroupLayout.Alignment.LEADING)
    						.addGroup(
    								GroupLayout.Alignment.TRAILING,
    								dropsPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.TRAILING)
    														.addComponent(
    																headerSeparator,
    																GroupLayout.Alignment.LEADING,
    																GroupLayout.DEFAULT_SIZE,
    																424,
    																Short.MAX_VALUE)
    														.addGroup(GroupLayout.Alignment.LEADING, dropsPanelLayout.createSequentialGroup().addComponent(dropsForLabel)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
    															.addComponent(npcIdLabel, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
    														.addComponent( tableScroll, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
    														.addGroup(GroupLayout.Alignment.LEADING,dropsPanelLayout.createSequentialGroup()
    															.addComponent(addNew, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addComponent(deleteSelected,GroupLayout.DEFAULT_SIZE,101,Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addComponent(repackDrop, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															//.addComponent(scanButton, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
    															//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    															.addContainerGap()))));
    		dropsPanelLayout
    				.setVerticalGroup(dropsPanelLayout
    						.createParallelGroup(
    								GroupLayout.Alignment.LEADING)
    						.addGroup(
    								dropsPanelLayout
    										.createSequentialGroup()
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																dropsForLabel)
    														.addComponent(
    																npcIdLabel))
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.RELATED)
    										.addComponent(
    												headerSeparator,
    												GroupLayout.PREFERRED_SIZE,
    												9,
    												GroupLayout.PREFERRED_SIZE)
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.UNRELATED)
    										.addComponent(
    												tableScroll,
    												GroupLayout.DEFAULT_SIZE,
    												327, Short.MAX_VALUE)
    										.addPreferredGap(
    												LayoutStyle.ComponentPlacement.RELATED)
    										.addGroup(
    												dropsPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(addNew)
    														.addComponent(
    																deleteSelected)
    														.addComponent(
    																repackDrop))
    										.addContainerGap()));
    
    		addNewButton.setText("Add New NPC Drop");
    		addNewButton.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				addNewButtonActionPerformed(evt);
    			}
    		});
    
    		removeDrop.setText("Remove NPC Drop");
    		removeDrop.setToolTipText("Removes the currently Selected NPC Drop");
    		removeDrop.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				removeDropActionPerformed(evt);
    			}
    		});
    
    		jMenu1.setText("File");
    
    		scan.setText("Scan for High Amounts");
    		scan.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent evt) {
    				scanListActionPerformed(evt);
    			}
    		});
    		jMenu1.add(scan);
    		dumpDropMenuItem.setText("Dump all monster drops");
    		dumpDropMenuItem.addActionListener(new java.awt.event.ActionListener() {
    
    			public void actionPerformed(java.awt.event.ActionEvent evt) {
    				dumpDropMenuItemActionPerformed(evt);
    			}
    		});
    		jMenu1.add(dumpDropMenuItem);
    		dumpSpecificDropMenuItem.setText("Dump specific monster drop");
    		dumpSpecificDropMenuItem
    				.addActionListener(new java.awt.event.ActionListener() {
    
    					public void actionPerformed(java.awt.event.ActionEvent evt) {
    						dumpSpecificDropMenuItemActionPerformed(evt);
    					}
    				});
    		jMenu1.add(dumpSpecificDropMenuItem);
    
    		fileMenu.add(jMenu1);
    
    		setJMenuBar(fileMenu);
    
    		GroupLayout layout = new GroupLayout(
    				getContentPane());
    		getContentPane().setLayout(layout);
    		layout.setHorizontalGroup(layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addContainerGap()
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.LEADING,
    												false)
    												.addComponent(
    														removeDrop,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														Short.MAX_VALUE)
    												.addGroup(
    														layout.createSequentialGroup()
    																.addComponent(
    																		searchIdLabel)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.UNRELATED)
    																.addComponent(
    																		searchField,
    																		GroupLayout.PREFERRED_SIZE,
    																		67,
    																		GroupLayout.PREFERRED_SIZE))
    												.addComponent(
    														progressBar,
    														GroupLayout.PREFERRED_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.PREFERRED_SIZE)
    												.addComponent(
    														treeScroll,
    														GroupLayout.DEFAULT_SIZE,
    														134, Short.MAX_VALUE)
    												.addComponent(
    														addNewButton,
    														GroupLayout.DEFAULT_SIZE,
    														GroupLayout.DEFAULT_SIZE,
    														Short.MAX_VALUE))
    								.addPreferredGap(
    										LayoutStyle.ComponentPlacement.UNRELATED)
    								.addComponent(middleSeparator,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addGap(18, 18, 18)
    								.addComponent(dropsPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addContainerGap()));
    		layout.setVerticalGroup(layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.TRAILING)
    												.addGroup(
    														GroupLayout.Alignment.LEADING,
    														layout.createSequentialGroup()
    																.addContainerGap()
    																.addGroup(
    																		layout.createParallelGroup(
    																				GroupLayout.Alignment.LEADING)
    																				.addComponent(
    																						dropsPanel,
    																						GroupLayout.Alignment.TRAILING,
    																						GroupLayout.DEFAULT_SIZE,
    																						GroupLayout.DEFAULT_SIZE,
    																						Short.MAX_VALUE)
    																				.addComponent(
    																						middleSeparator,
    																						GroupLayout.DEFAULT_SIZE,
    																						410,
    																						Short.MAX_VALUE)))
    												.addGroup(
    														layout.createSequentialGroup()
    																.addGap(15, 15,
    																		15)
    																.addComponent(
    																		treeScroll)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		addNewButton)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		removeDrop)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addGroup(
    																		layout.createParallelGroup(
    																				GroupLayout.Alignment.TRAILING)
    																				.addComponent(
    																						searchIdLabel)
    																				.addComponent(
    																						searchField,
    																						GroupLayout.PREFERRED_SIZE,
    																						GroupLayout.DEFAULT_SIZE,
    																						GroupLayout.PREFERRED_SIZE))
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		progressBar,
    																		GroupLayout.PREFERRED_SIZE,
    																		GroupLayout.DEFAULT_SIZE,
    																		GroupLayout.PREFERRED_SIZE)))
    								.addContainerGap()));
    
    		pack();
    	}// </editor-fold>//GEN-END:initComponents
    
    	protected void testDropRate(ActionEvent arg0) {
    		ArrayList<Drop> drops = loader.getDropArray().get(
    		Integer.parseInt(dropsTree.getLastSelectedPathComponent().toString()));
    		Drop drop = drops.get(dropTable.getSelectedRow());
    		String testAmount = JOptionPane.showInputDialog(this, "Enter the amount of times you want to test(0 to test till it drops)");
    		int testAmt = 0;
    		try {
    			testAmt = Integer.parseInt(testAmount);
    		} catch (Exception e) {
    			testAmt = 0;
    		}
    		if (testAmt > 0) {
    			int successfullDrops = 0;
    			for (int i = 0; i < testAmt; i++) {
    				int chance = random.nextInt(100);
    				if (chance <= drop.getRate()) {
    					successfullDrops++;
    				}
    			}
    			JOptionPane.showMessageDialog(this, "Received the drop " + successfullDrops + " out of " + testAmt + " times");
    		} else {
    			boolean didntReceive = true;
    			int times = 0;
    			while (didntReceive) {
    				int chance = random.nextInt(100);
    				if (chance <= drop.getRate()) {
    					didntReceive = false;
    				} else {
    					times++;
    				}
    			}
    			JOptionPane.showMessageDialog(this, "Received the drop after "
    					+ times + " times");
    		}
    
    	}
    
    	protected void dumpSpecificDropMenuItemActionPerformed(ActionEvent evt) {
    		try {
    			//dump(Integer.parseInt(JOptionPane.showInputDialog(this, "Enter the NPC ID")));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	protected void dumpDropMenuItemActionPerformed(ActionEvent evt) {
    		Thread dumpThread = new Thread() {
    
    			int index = -1;
    
    			public void run() {
    				while (index < Utils.getNPCDefinitionsSize()) {
    					try {
    						progressBar.setString(NPCDefinitions.getNPCDefinitions(index).name);
    						//dump(index);
    						index++;
    						progressBar.setValue(index);
    						Thread.sleep(1);
    					} catch (Exception e) {
    						System.out.println("Problem with npc id " + index + ".");
    						index++;
    						progressBar.setValue(index);
    					}
    				}
    				packFile();
    				progressBar.setString("");
    				progressBar.setValue(-1);
    			}
    		};
    		dumpThread.start();
    	}
    
    	public DefaultMutableTreeNode searchNode(String nodeStr) {
    		DefaultMutableTreeNode nodeToSearch = null;
    		Enumeration<?> e = dropsNode.breadthFirstEnumeration();
    		while (e.hasMoreElements()) {
    			nodeToSearch = (DefaultMutableTreeNode) e.nextElement();
    			if (nodeStr.equals(nodeToSearch.getUserObject().toString())) {
    				return nodeToSearch;
    			}
    		}
    		return null;
    	}
    
    	private void searchFieldActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_searchFieldActionPerformed
    		try {
    			DefaultMutableTreeNode n = searchNode(searchField.getText());
    			TreePath path = new TreePath(dropsTreeModel.getPathToRoot(n));
    			dropsTree.scrollPathToVisible(path);
    			dropsTree.setSelectionPath(path);
    		} catch (Exception e) {
    			JOptionPane.showMessageDialog(this, "Could not find the item.");
    		}
    	}// GEN-LAST:event_searchFieldActionPerformed
    
    	private void dropsTreeValueChanged(TreeSelectionEvent evt) {// GEN-FIRST:event_dropsTreeValueChanged
    		if (dropsTree.getLastSelectedPathComponent() != null
    				&& !"Drops".equals(dropsTree.getLastSelectedPathComponent()
    						.toString())) {
    			loadDrop(Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    					.toString()));
    		}
    	}// GEN-LAST:event_dropsTreeValueChanged
    
    	private void deleteSelectedActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSelectedActionPerformed
    		try {
    			int npcID = Integer.parseInt(dropsTree
    					.getLastSelectedPathComponent().toString());
    			ArrayList<Drop> drops = loader.getDropArray().get(npcID);
    			drops.remove(dropTable.getSelectedRow());
    			Drop[] d = new Drop[drops.size()];
    			drops.toArray(d);
    			loader.getDropMap().put(npcID, d);
    
    			loadDrop(Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    					.toString()));
    		} catch (NullPointerException e) {
    			JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		}
    	}// GEN-LAST:event_deleteSelectedActionPerformed
    
    	private void addNewActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addNewActionPerformed
    		// try {
    		int npcid = Integer.parseInt(dropsTree.getLastSelectedPathComponent()
    				.toString());
    		// ArrayList<Drop> drops = loader.getDropArray().get(npcid);
    		loader.insertDrop(npcid, Drop.create(Integer.parseInt(JOptionPane
    				.showInputDialog("Please enter the item ID for this drop.")),
    				(int) 100.0, 1, 1, false));
    
    		loadDrop(npcid);
    		// } catch (NullPointerException e) {
    
    		// JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		// }
    	}// GEN-LAST:event_addNewActionPerformed
    
    	private void addNewButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addNewButtonActionPerformed
    		String id = JOptionPane
    				.showInputDialog("Please enter the NPC ID for this drop.");
    		if (id == null) {
    			id = "0";
    		}
    		loader.getDropArray().put(Integer.parseInt(id), new ArrayList<Drop>());
    		packFile();
    	}// GEN-LAST:event_addNewButtonActionPerformed
    
    	private void removeDropActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_removeDropActionPerformed
    		try {
    			if (!dropsTree.getLastSelectedPathComponent().toString().equals("")) {
    				loader.getDropMap().remove(
    						Integer.parseInt(dropsTree
    								.getLastSelectedPathComponent().toString()));
    				packFile();
    			}
    		} catch (NullPointerException e) {
    			JOptionPane.showMessageDialog(this, "Please select a drop first!");
    		}
    	}// GEN-LAST:event_removeDropActionPerformed
    
    	private void repackDropActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_repackDropActionPerformed
    		packFile();
    	}// GEN-LAST:event_repackDropActionPerformed
    
    	private void scanListActionPerformed(ActionEvent evt) {
    		System.out.println("Started Scanning.");
    		
    		final int amountToFind = 100;
    		
    		java.awt.EventQueue.invokeLater(new Runnable() {
    			int count = 0;
    			public void run() {
    				for (Entry<Integer, ArrayList<Drop>> e : loader.getDropArray().entrySet()) {
    					int npcId = e.getKey();
    					for (Drop d : e.getValue()) {
    						if (d.getMinAmount()> amountToFind && d.getMaxAmount() > amountToFind) {
    							System.out.println("NPC Id:"+npcId+"");
    							System.out.println("Item Id: "+d.getItemId()+"");
    							System.out.println("Min Amount: "+Utils.formatNumber(d.getMinAmount())+"");
    							System.out.println("Max Amount: "+Utils.formatNumber(d.getMaxAmount())+"");
    							System.out.println("---------------------------------------------------------------------------------------");
    							count++;
    						}
    					}
    				}
    				System.out.println("Scanning Completed.");
    			}
    		});
    	}
    	
    	/**
    	 * @param args
    	 *            the command line arguments
    	 */
    	public static void main(String args[]) {
    		
    		Console.getInstance().setVisible(true);
    		
    		java.awt.EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				new DropEditor().setVisible(true);
    			}
    		});
    		
    		System.setOut(new ConsoleLogger(System.out));
    		System.setErr(new ConsoleLogger(System.err));
    		Console.getInstance().setVisible(true);
    	}
    
    	// Variables declaration - do not modify//GEN-BEGIN:variables
    	private JButton addNew;
    	private JButton addNewButton;
    	private JButton deleteSelected;
    	private JTable dropTable;
    	private JLabel dropsForLabel;
    	private JPanel dropsPanel;
    	private JTree dropsTree;
    	private JMenuItem scan;
    	private JMenuItem dumpDropMenuItem;
    	private JMenuBar fileMenu;
    	private JSeparator headerSeparator;
    	private JMenu jMenu1;
    	private JSeparator middleSeparator;
    	private JLabel npcIdLabel;
    	private JButton removeDrop;
    	private JButton repackDrop;
    	private JButton scanButton;
    	private JTextField searchField;
    	private JLabel searchIdLabel;
    	private JScrollPane tableScroll;
    	private JScrollPane treeScroll;
    
    	// End of variables declaration//GEN-END:variables
    
    	private void loadDrop(final int npcId) {
    		npcIdLabel.setText(Integer.toString(npcId) + " " + NPCDefinitions.getNPCDefinitions(npcId).name);
    		ArrayList<Drop> drops = loader.getDropArray().get(npcId);
    		DefaultTableModel model = new DefaultTableModel();
    		model.addTableModelListener(new TableModelListener() {
    
    			public void tableChanged(TableModelEvent e) {
    				try {
    					if (e.getColumn() != -1) {
    						if (dropTable.getValueAt(dropTable.getSelectedRow(), 0).equals("Rare")) {
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setItemId((short) -1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setRate(-1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(1);
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(1);
    
    						} else {
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setItemId(Short.parseShort((String) dropTable.getValueAt(dropTable.getSelectedRow(), 0).toString()));
    							loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setRate(Double.parseDouble((String) dropTable.getValueAt(dropTable.getSelectedRow(),1).toString()));
    							String amount = (String) dropTable.getValueAt(dropTable.getSelectedRow(), 2);
    							if (amount.contains("-")) {
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(Integer.parseInt(amount.substring(0, amount.indexOf("-"))));
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(Integer.parseInt(amount.substring(amount.indexOf("-") + 1)));
    							} else {
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMinAmount(Integer.parseInt(amount));
    								loader.getDropArray().get(npcId).get(dropTable.getSelectedRow()).setMaxAmount(Integer.parseInt(amount));
    
    							}
    						}
    					}
    				} catch (Exception f) {
    					f.printStackTrace();
    				}
    			}
    		});
    		model.addColumn("Item ID");
    		model.addColumn("Percent Chance");
    		model.addColumn("Amount");
    		for (Drop d : drops) {
    			if (d == null) {
    				continue;
    			}
    			if (!d.isFromRareTable()) {
    				model.addRow(new Object[] { (d.getItemId()), Double.toString(d.getRate()), Integer.toString(d.getMinAmount()) + (d.getMinAmount() == d.getMaxAmount() || d.getMaxAmount() == 0 ? "" : "-" + d.getMaxAmount()) });
    			} else {
    				model.addRow(new Object[] { "Rare", "100.0", "1" });
    			}
    		}
    		dropTable.setModel(model);
    	}
    
    	private void packFile() {
    		try { // //drops.bin
    			RandomAccessFile raf = new RandomAccessFile("data/npcs/packedDrops.d", "rw");
    			raf.writeShort(loader.getDropMap().size());
    			for (Entry<Integer, ArrayList<Drop>> e : loader.getDropArray().entrySet()) {
    				raf.writeShort(e.getKey());
    				raf.writeShort(e.getValue().size());
    				for (Drop d : e.getValue()) {
    
    					raf.writeByte(d.isFromRareTable() ? 1 : 0);
    					if (!d.isFromRareTable()) {
    						int itemID = d.getItemId();
    						if (ItemDefinitions.getItemDefinitions(itemID).getName().equals("Coins")) {
    							itemID = 995;
    						}
    						raf.writeShort(itemID);
    						raf.writeDouble(d.getRate());
    						if (d.getMinAmount() > d.getMaxAmount()) {
    							int min = d.getMinAmount();
    							d.setMinAmount(d.getMaxAmount());
    							d.setMaxAmount(min);
    						}
    						raf.writeInt(d.getMinAmount());
    						raf.writeInt(d.getMaxAmount());
    					}
    				}
    			}
    			raf.close();
    			System.out.println("Repacking succesful!");
    		} catch (IOException ex) {
    			System.err.println(ex);
    		}
    		reload();
    	}
    
    	private void reload() {
    		dropsNode.removeAllChildren();
    		// loader = new NPCDropLoader();
    		// loader.load();
    		for (Entry<Integer, ArrayList<Drop>> s : loader.getDropArray()
    				.entrySet()) {
    			dropsNode.add(new DefaultMutableTreeNode(s.getKey()));
    		}
    		dropsTreeModel.reload(dropsNode);
    	}
    }
    and in the source make a DropEditor.bat
    and put this in it

    @echo off
    title Npc Drop Editor
    start javaw -client -Xmx512m -cp bin;lib/* com.rs.tools.DropEditor
    congrats, your only 2 years late, how did you even find this thread?

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    Registered Member Sherlock's Avatar
    Join Date
    Jun 2014
    Posts
    101
    Thanks given
    8
    Thanks received
    7
    Rep Power
    14
    Quote Originally Posted by Santa Hat View Post
    congrats, your only 2 years late, how did you even find this thread?
    haha, i just scrolled down the bottom and found it, i replied, and then i realized it was 2 years ago haha


    Reply With Quote  
     


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. 718 Npc Drops
    By Gaaz in forum Help
    Replies: 0
    Last Post: 07-30-2012, 03:11 PM
  2. [PI] Adding/changing NPC drops
    By Ags Pride in forum Help
    Replies: 6
    Last Post: 12-08-2011, 10:41 PM
  3. Specific Drops From an Npc (.cgf drops)
    By Soulevoker in forum Configuration
    Replies: 10
    Last Post: 01-07-2009, 10:28 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •