Jump to content
Existing user? Sign In

Sign In



Sign Up

[Ruse] Generate static ints for all items


Flub

Recommended Posts

I've always liked being able to reference an item in code via static ints. 

I have a file named Items.java, and I simply reference Items.RUNE_ARROW for example.

Well if you want this too, I made this to generate them.

public static void main(String[] args) {
        try {
            File dumpedDefs = new File("./DumpedDefs.txt");
            FileWriter fw = new FileWriter(dumpedDefs, false);
            //Loading ints into definitions[]
            init();

            HashMap<String, ItemDefinition> map = new HashMap<>();


            // Adding definitions into a hashmap in reverse
            // This replaces items that have duplicate names such as tinderbox
            // With the version which has the lowest ID
            // The key for the map is the name of the item
            for (int i = definitions.length - 1; i > 0; i--) {
                ItemDefinition itemDef = forId(i);
                if (!itemDef.description.contains("null")) {
                    String stack = itemDef.isStackable() ? "_STACK" : "";
                    String noted = itemDef.isNoted() ? "_NOTED" : "";
                    String name = itemDef.name.replaceAll(" ", "_")
                            .replaceAll("'", "")
                            .replaceAll("!", "")
                            .replaceAll("%", "")
                            .replaceAll("-", "_")
                            .replace("+", "PLUS")
                            .replace("(", "")
                            .replace(")", "")
                            .replace(".", "_")
                            .replace("&", "_")
                            .replace("/", "_OF_")
                            .replace(",", "_")
                            .replace("?", "")
                            .replaceAll("\"", "")
                            + (itemDef.isNoted() ? noted : stack);
                    if (Character.isDigit(name.charAt(0))) {
                        name = "_" + name;
                    }
                    map.put(name, itemDef);
                }
            }

            ArrayList<Integer> itemArray = new ArrayList<>();

            // Adding all of the items from the hashmap into an array that we can sort
            for (String key : map.keySet()) {
                ItemDefinition itemDef = map.get(key);
                itemArray.add(itemDef.id);
            }
            // printing the unsorted ArrayList
            System.out.println("Before Sorting: " + itemArray);
            // Sorting ArrayList in ascending Order
            Collections.sort(itemArray);
            // printing the sorted ArrayList
            System.out.println("After Sorting: " + itemArray);

            // Writing the file and removing junk from the name
            for (Integer integer : itemArray) {
                ItemDefinition itemDef = forId(integer);
                String stack = itemDef.isStackable() ? "_STACK" : "";
                String noted = itemDef.isNoted() ? "_NOTED" : "";
                String name = itemDef.name.replaceAll(" ", "_")
                        .replaceAll("'", "")
                        .replaceAll("!", "")
                        .replaceAll("%", "")
                        .replaceAll("-", "_")
                        .replace("+", "PLUS")
                        .replace("(", "")
                        .replace(")", "")
                        .replace(".", "_")
                        .replace("&", "_")
                        .replace("/", "_OF_")
                        .replace(",", "_")
                        .replace("?", "")
                        .replaceAll("\"", "")
                        + (itemDef.isNoted() ? noted : stack);
                if (Character.isDigit(name.charAt(0))) {
                    name = "_" + name;
                }
                fw.write("public static int " + name.toUpperCase() + " = " + itemDef.id + "; \n");
            }

            fw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

Example of the ints generated:

public static int TOOLKIT = 1;
    public static int CANNONBALL_STACK = 2;
    public static int NULODIONS_NOTES = 3;
    public static int AMMO_MOULD = 4;
    public static int INSTRUCTION_MANUAL = 5;
    public static int CANNON_BASE = 6;
    public static int CANNON_BASE_NOTED = 7;
    public static int CANNON_STAND = 8;
    public static int CANNON_STAND_NOTED = 9;
    public static int CANNON_BARRELS = 10;
    public static int CANNON_BARRELS_NOTED = 11;
    public static int CANNON_FURNACE = 12;
    public static int CANNON_FURNACE_NOTED = 13;
    public static int RAILING_STACK = 14;
    public static int HOLY_TABLE_NAPKIN = 15;
    public static int MAGIC_WHISTLE = 16;
    public static int GRAIL_BELL = 17;
    public static int MAGIC_GOLD_FEATHER = 18;
    public static int HOLY_LONGBOW = 20;
    public static int COPSE_LONGBOW = 21;
    public static int ELEGANT_LONGBOW = 22;
    public static int MALEVOLENT_LONGBOW = 23;
    public static int RAT_POISON = 24;
    public static int RED_VINE_WORM_STACK = 25;
    public static int FISHING_TROPHY = 26;
    public static int FISHING_PASS = 27;
    public static int INSECT_REPELLENT = 28;
    public static int TINDERBOX = 29;
    public static int BUCKET_OF_WAX = 30;
    public static int LIT_BLACK_CANDLE = 32;
    public static int LIT_CANDLE = 33;
    public static int LIT_CANDLE_STACK = 34;
    public static int EXCALIBUR = 35;
    public static int CANDLE = 36;
    public static int CANDLE_NOTED = 37;


Thanks boiz

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Contact

[email protected]

astra.security

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

Runewild Ikov RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex in any way & exists solely for educational purposes.

×
×
  • Create New...