Thread: RuneScape NPCCombatDefinitions Dumper

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 RuneScape NPCCombatDefinitions Dumper 
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Meh why not, I'm done with RSPS so might as well release some snippets here and there of some stuff that people may find useful. This dumps data from RuneScape's website about all the NPCs. This will produce a very large amount of NPC data which would take a while to fill out and makes sure that almost every single NPC has proper data. This can get certain animations, poison types, weaknesses (VERY useful for making accurate combat formulas in PvM), and a bunch of other cool things which RuneScape just has laying around on the website. Have fun, also you need to modify the code to what data you want to dump. This version here is fit to dump data that follows the default Matrix NPCCombatDefinitions format, although I highly suggest dumping more data and adjusting the formats so that you can implement those important things like weakness, aggro ratio, etc.

    Code:
    package net.nocturne.tools;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import net.nocturne.cache.Cache;
    import net.nocturne.utils.Utils;
    
    public class BeastDumper {
    
    	private String jsonData;
    	private static BufferedWriter writer;
    	private static BufferedReader reader;
    	private static final String BESTIARY_URL = "http://services.runescape.com/m=itemdb_rs/bestiary/bestiary/beastData.json?beastid=";
    	private HashMap<String, String> values;
    	private static HashMap<Integer, String> combinations;
    	private static ArrayList<String> definitions;
    	private static final Pattern JSON_PATTERN = Pattern
    			.compile("\"(\\w+?)\":\\[?\"?([\\w ]+)+\"?\\]?");
    
    	public BeastDumper(final int id, int realId) throws NullPointerException {
    		try {
    			System.out.println("Attempting ID: " + realId);
    			jsonData = getData(id);
    			if (jsonData.equalsIgnoreCase(""))
    				new BeastDumper(id - 1, id);
    			Matcher matcher = JSON_PATTERN.matcher(jsonData);
    			values = new HashMap<String, String>();
    			while (matcher.find()) {
    				String key = matcher.group(1);
    				String value = matcher.group(2);
    				values.put(key, value);
    			}
    			if (values == null || values.get("attack") == null
    					|| values.get("attack").equalsIgnoreCase("null"))
    				return;
    			writer.newLine();
    			writer.append(realId + " - " + values.get("lifepoints") + " "
    					+ values.get("attack") + " -1 " + values.get("death")
    					+ " 30 -1 -1 " + values.get("xp") + " true false "
    					+ values.get("poisonous") + " " + values.get("aggressive")
    					+ " 20");
    			writer.flush();
    			System.out.println("Completed NPC: " + values.get("name") + "("
    					+ realId + ")");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public int getDeathAnimation() {
    		return Integer.parseInt(values.get("death"));
    	}
    
    	public int getAttackAnimation() {
    		return Integer.parseInt(values.get("attack"));
    	}
    
    	public int getSize() {
    		return Integer.parseInt(values.get("size"));
    	}
    
    	public String getName() {
    		return values.get("name");
    	}
    
    	public String getWeakness() {
    		return values.get("weakness");
    	}
    
    	public String getProperty(String a) {
    		return values.get(a);
    	}
    
    	public int getLifepoints() {
    		return Integer.parseInt(values.get("lifepoints"));
    	}
    
    	public int getId() {
    		return Integer.parseInt(values.get("id"));
    	}
    
    	public String getDescription() {
    		return getProperty("description");
    	}
    
    	public boolean getPoisonous() {
    		return Boolean.parseBoolean(getProperty("poisonous"));
    	}
    
    	public boolean getAttackable() {
    		return Boolean.parseBoolean(getProperty("attackable"));
    	}
    
    	public boolean getMembers() {
    		return Boolean.parseBoolean(getProperty("members"));
    	}
    
    	public int getDefence() {
    		return Integer.parseInt(values.get("defence"));
    	}
    
    	public int getMagic() {
    		return Integer.parseInt(values.get("magic"));
    	}
    
    	public int getRanged() {
    		return Integer.parseInt(getProperty("ranged"));
    	}
    
    	public String getAreas() {
    		return getProperty("areas");
    	}
    
    	public static void main(String[] args) {
    		try { 
    			Cache.init(); 
    			File file = new File("./information/beastDump.txt"); 
    			if (file.exists())
    				file.delete(); 
    			else 
    				file.createNewFile(); 
    			writer = new BufferedWriter(new FileWriter(file)); 
    			for (int i = 0; i < Utils.getNPCDefinitionsSize(); i++) 
    				new BeastDumper(i, i);
    			writer.close(); 
    			combineData(); 
    		} catch (IOException e) {
    			e.printStackTrace(); 
    		}
    	}
    
    	public static void combineData() {
    		combinations = new HashMap<Integer, String>();
    		definitions = new ArrayList<String>();
    		try {
    			reader = new BufferedReader(new FileReader(new File(
    					"./data/npcs/oldDefs.txt")));
    			String data;
    			while ((data = reader.readLine()) != null) {
    				if (data.contains("//"))
    					continue;
    				String[] npc = data.split(" - ");
    				String[] fields = npc[1].split(" ");
    				combinations.put(Integer.parseInt(npc[0]), fields[8] + " "
    						+ fields[9] + " " + fields[10] + " " + fields[11] + " "
    						+ fields[12]);
    			}
    			reader.close();
    			reader = new BufferedReader(new FileReader(new File(
    					"./data/npcs/unpackedCombatDefinitionsList.txt")));
    			while ((data = reader.readLine()) != null) {
    				if (data.contains("//"))
    					continue;
    				String[] npc = data.split(" - ");
    				String[] fields = npc[1].split(" ");
    				if (combinations.containsKey(Integer.parseInt(npc[0])))
    					definitions.add(Integer.parseInt(npc[0]) + " - "
    							+ fields[0] + " " + fields[1] + " " + fields[2]
    							+ " " + fields[3] + " " + fields[4] + " "
    							+ fields[5] + " " + fields[6] + " " + fields[7]
    							+ " " + combinations.get(Integer.parseInt(npc[0])));
    				else
    					definitions.add(Integer.parseInt(npc[0]) + " - "
    							+ fields[0] + " " + fields[1] + " " + fields[2]
    							+ " " + fields[3] + " " + fields[4] + " "
    							+ fields[5] + " " + fields[6] + " " + fields[7]
    							+ " " + fields[8] + " " + fields[9] + " "
    							+ fields[10] + " " + fields[11] + " " + fields[12]);
    			}
    			reader.close();
    			writer = new BufferedWriter(new FileWriter(new File(
    					"./data/npcs/test.txt")));
    			for (String def : definitions) {
    				System.out.println(def);
    				writer.newLine();
    				writer.write(def);
    				writer.flush();
    			}
    			writer.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static String getData(final int id) throws IOException {
    		URL url = new URL(BESTIARY_URL + id);
    		final InputStream in = url.openStream();
    		byte[] buffer = new byte[1024];
    		ByteArrayOutputStream bos = new ByteArrayOutputStream();
    		int read;
    		while ((read = in.read(buffer)) != -1) {
    			bos.write(buffer, 0, read);
    		}
    		bos.flush();
    		in.close();
    		return new String(bos.toByteArray());
    	}
    }
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Thanks.
    [Today 01:29 AM] RSTrials: Nice 0.97 Win/Loss Ratio luke. That's pretty bad.
    [Today 01:30 AM] Luke132: Ok u fucking moron i forgot i could influence misc.random
    Reply With Quote  
     

  4. #3  
    Registered Member
    Zivik's Avatar
    Join Date
    Oct 2007
    Age
    28
    Posts
    4,421
    Thanks given
    891
    Thanks received
    1,527
    Rep Power
    3285
    Thanks for the share.
    Reply With Quote  
     

  5. #4  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Quote Originally Posted by Professor Oak View Post
    Thanks.
    Quote Originally Posted by Zivik View Post
    Thanks for the share.
    Heh accidently posted the outdated code, just updated it so re grab dat shit
    Reply With Quote  
     

  6. #5  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,818
    Thanks received
    1,767
    Rep Power
    2438
    the code is pretty messy tbh, but i didnt know they had animation ids publicly available, so thx for that =]]
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  7. #6  
    Registered Member
    thing1's Avatar
    Join Date
    Aug 2008
    Posts
    2,111
    Thanks given
    131
    Thanks received
    1,099
    Rep Power
    2402
    Thank you for your contribution. Most of it is too new for my revision but it is still a very nice tool for the community.
    Reply With Quote  
     

  8. #7  
    Finland

    Zoltus's Avatar
    Join Date
    Dec 2015
    Age
    24
    Posts
    977
    Thanks given
    671
    Thanks received
    779
    Rep Power
    5000
    Thanks for sharing
    Attached image

    Spoiler for God:
    Attached image
    Reply With Quote  
     

  9. #8  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Nice share for the ones who needs it
    Reply With Quote  
     

  10. #9  
    Respected Member


    Polar's Avatar
    Join Date
    Sep 2015
    Age
    28
    Posts
    420
    Thanks given
    0
    Thanks received
    418
    Rep Power
    3098
    Nice use of regex to parse JSON.
    Reply With Quote  
     

  11. #10  
    Special Snowflake

    DeathKid's Avatar
    Join Date
    May 2013
    Posts
    385
    Thanks given
    191
    Thanks received
    97
    Rep Power
    383
    Thanks for the share.
    "Always remember that you are unique. Just like everyone else" - My Mom
    Reply With Quote  
     

Page 1 of 2 12 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. Replies: 6
    Last Post: 04-21-2016, 05:10 AM
  2. RuneScape Bestiary Dumper
    By Archon in forum Snippets
    Replies: 10
    Last Post: 04-26-2015, 01:03 PM
  3. Runescape Model Dumper
    By Apfelsuchti in forum Requests
    Replies: 0
    Last Post: 11-19-2010, 05:27 PM
  4. Runescape deob dumper
    By `Michael in forum Downloads
    Replies: 10
    Last Post: 10-11-2009, 06:32 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
  •