Botre Posted February 23, 2015 Share Posted February 23, 2015 (edited) LAST UPDATE: MARCH 26, 2015 package org.bjornkrols.experience; import java.util.Arrays; /** * @author Bjorn Krols (Botre) * @version 0.1 * @since March 6, 2015 */ public final class ExperienceTable { /** * The maximum skill level in OSRS. */ private static final int MAXIMUM_LEVEL = 99; /** * A table holding the experience amounts for a specific number of levels. */ private static final int[] TABLE = create(MAXIMUM_LEVEL); private ExperienceTable() { // This class should never be instantiated. // Do not delete or make accessible. } /** * @return The total amount of experience required for the level. */ public static int getXp(int level) { return level == 0 ? 0 : TABLE[level - 1]; } /** * @return The level acquired by the amount of experience. */ public static int getLevel(int experience) { return Math.abs(Arrays.binarySearch(TABLE, experience) + 1); } /** * Creates the experience table. */ private static int[] create(int maximumLevel) { int[] table = new int[maximumLevel]; int experience = 0; for (int i = 1; i < maximumLevel; i++) { experience += Math.floor(i + 300 * Math.pow(2, i / 7.0)); table[i] = (int) Math.floor(experience / 4); } return table; } } Edited March 26, 2015 by Botre 4 Quote Link to comment Share on other sites More sharing options...
Apaec Posted February 23, 2015 Share Posted February 23, 2015 Oh sweet, Its cool that you're actually calculating the exp rather than using a static table apa Quote Link to comment Share on other sites More sharing options...
Botre Posted February 23, 2015 Author Share Posted February 23, 2015 Oh sweet, Its cool that you're actually calculating the exp rather than using a static table apa It still uses table look-up (because it's cheaper). I made it generate the table though, because otherwise certain people will cry about it not being flexible (I personally really doubt they'll ever implement levels > 126 but whatever). Quote Link to comment Share on other sites More sharing options...
Apaec Posted February 23, 2015 Share Posted February 23, 2015 It still uses table look-up (because it's cheaper). I made it generate the table though, because otherwise certain people will cry about it not being flexible (I personally really doubt they'll ever implement levels > 126 but whatever). i like your new old profile picture 1 Quote Link to comment Share on other sites More sharing options...
range inc Posted February 23, 2015 Share Posted February 23, 2015 Might be better 'cpu-wise' to use a static table. Since CPU is more precious then the few bytes the table would use. Quote Link to comment Share on other sites More sharing options...
Botre Posted February 23, 2015 Author Share Posted February 23, 2015 Might be better 'cpu-wise' to use a static table. Since CPU is more precious then the few bytes the table would use. That's why I'm using table look-up :p Quote Link to comment Share on other sites More sharing options...
Swizzbeat Posted February 23, 2015 Share Posted February 23, 2015 Why final 1 Quote Link to comment Share on other sites More sharing options...
Swizzbeat Posted February 23, 2015 Share Posted February 23, 2015 Might be better 'cpu-wise' to use a static table. Since CPU is more precious then the few bytes the table would use. Yeah but no. Ever heard of polymorphism? Enjoy updating all your scripts if Jagex decides to increase the max level from 99 - 500. Quote Link to comment Share on other sites More sharing options...
Botre Posted February 23, 2015 Author Share Posted February 23, 2015 Yeah but no. Ever heard of polymorphism? Enjoy updating all your scripts if Jagex decides to increase the max level from 99 - 500. public RSExperienceTable() { generateTable(126); } to public RSExperienceTable() { generateTable(500); } It would take 5 seconds. And it's unlikely I'll ever have to pay that time price :p If they were to update it to 500 with the current formula it would take 536870911 xp. Meaning you would have to calc a long every x seconds. But why stop at 500? Why not make the calculation return a BigDecimal, just to be safe, in case they add decimal levels? Quote Link to comment Share on other sites More sharing options...
VladBots Posted February 23, 2015 Share Posted February 23, 2015 would've been better off making this all static kek Quote Link to comment Share on other sites More sharing options...
Botre Posted February 23, 2015 Author Share Posted February 23, 2015 would've been better off making this all static kek Yup. I currently only have one script an account so I only ever create one instance of it :p But yeah will probably make it static later on ^^ Quote Link to comment Share on other sites More sharing options...
Joseph Posted February 24, 2015 Share Posted February 24, 2015 import java.util.Arrays; /** * * @author Bjorn Krols (Botre) * */ public final class RSExperienceTable { int[] table; public RSExperienceTable() { generateTable(126); } public RSExperienceTable(int maxLevel) { generateTable(maxLevel); } public int getXp(int level) { return level == 0 ? 0 : table[level - 1]; } public int getLevel(int experience) { return Math.abs(Arrays.binarySearch(table, experience) + 1); } private void generateTable(int maxLevel) { int[] table = new int[maxLevel]; int experience = 0; for (int i = 1; i < maxLevel; i++) { experience += Math.floor(i + 300 * Math.pow(2, i / 7.0)); table[i] = Math.floorDiv(experience, 4); } this.table = table; } } Why final what swiz said. How you going to use an instances when is final. Quote Link to comment Share on other sites More sharing options...
VladBots Posted February 24, 2015 Share Posted February 24, 2015 what swiz said. How you going to use an instances when is final.Lol what? Do you even know what final does? Quote Link to comment Share on other sites More sharing options...
Botre Posted February 24, 2015 Author Share Posted February 24, 2015 Why final Because I decided that's where that inheritance branch should end There's no need for it to been extendable. what swiz said. How you going to use an instances when is final. Making a class final really just makes it unextendable ^^ Quote Link to comment Share on other sites More sharing options...
Joseph Posted February 24, 2015 Share Posted February 24, 2015 (edited) Because I decided that's where that inheritance branch should end :ph34r: There's no need for it to been extendable. Making a class final really just makes it unextendable ^^ Lol what? Do you even know what final does?it was pretty late when I replied and I had it mixed up lol. Edited February 24, 2015 by josedpay 1 Quote Link to comment Share on other sites More sharing options...