Botre Posted June 8, 2014 Share Posted June 8, 2014 (edited) Experience distance: package xp.Botrepreneur; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; public class XpDistance { /** * @author Botrepreneur * @Version: 00.11 */ private static final int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 }; public static int getLevelExperience(int level) { return XP[level - 1]; } public static int getDistanceBetweenLevels(int levelA, int levelB) { int d = 0; if (levelA > levelB) { d = XP[levelA - 1] - XP[levelB - 1]; } else if (levelB > levelA) { d = XP[levelB - 1] - XP[levelA - 1]; } return d; } public static int getXpUntilLevel(Script script, Skill skill, int level) { int d = XP[level - 1] - script.skills.getExperience(skill); return d > 0 ? d : 0; } public static int getXpUntilNextLevel(Script script, Skill skill) { int d = XpDistance.XP[script.skills.getStatic(skill)] - script.skills.getExperience(skill); return d > 0 ? d : 0; } public static int getXpPastCurrentLevel(Script script, Skill skill) { int d = script.skills.getExperience(skill) - XpDistance.XP[script.skills.getStatic(skill) - 1]; return d > 0 ? d : 0; } public static int getPercentageUntilNextLevelFromZero(Script script, Skill skill) { int p = script.skills.getExperience(skill) * 100 / XpDistance.XP[script.skills.getStatic(skill)]; return p > 0 ? p : 0; } public static int getPercentageUntilNextLevelFromCurrentLevel(Script script, Skill skill) { int p = XpDistance.getXpUntilNextLevel(script, skill) * 100 / (XpDistance.XP[script.skills.getStatic(skill)] - XpDistance.XP[script.skills.getStatic(skill) - 1]); return p > 0 ? p : 0; } } Edited July 5, 2014 by Botrepreneur 2 Link to comment Share on other sites More sharing options...
Dog_ Posted June 8, 2014 Share Posted June 8, 2014 i don't even 1 Link to comment Share on other sites More sharing options...
Precise Posted June 8, 2014 Share Posted June 8, 2014 This is helpful! ^_^ Link to comment Share on other sites More sharing options...
Botre Posted June 8, 2014 Author Share Posted June 8, 2014 i don't even If you have any criticisms / ideas to improve the snippet I'll gladly listen If you are here only to bash on someone trying help and learn then you should probably just leave. 2 Link to comment Share on other sites More sharing options...
Joseph Posted June 8, 2014 Share Posted June 8, 2014 Thanks for this i could of made one my self but im to lazy too lol Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 8, 2014 Share Posted June 8, 2014 private final static int[] XP Switch final and static. 3 Link to comment Share on other sites More sharing options...
Ericthecmh Posted June 8, 2014 Share Posted June 8, 2014 private final static int[] XP Switch final and static. Convention nazi. 3 Link to comment Share on other sites More sharing options...
NotoriousPP Posted June 14, 2014 Share Posted June 14, 2014 Oh god I feel bad to who ever used this.... If your hard coding something, your probably doing it wrong. //XP for level public int getXPForLevel(int level) { int points = 0; int output = 0; for (int lvl = 1; lvl <= level; lvl++) { points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0)); if (lvl >= level) return output; output = (int) Math.floor(points / 4); } return 0; } Link to comment Share on other sites More sharing options...
Botre Posted June 14, 2014 Author Share Posted June 14, 2014 Oh god I feel bad to who ever used this.... If your hard coding something, your probably doing it wrong. //XP for level public int getXPForLevel(int level) { int points = 0; int output = 0; for (int lvl = 1; lvl <= level; lvl++) { points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0)); if (lvl >= level) return output; output = (int) Math.floor(points / 4); } return 0; } It's all about CPU management. That math is quite heavy, especially if you call it every time the onPaint refreshes :p 2 Link to comment Share on other sites More sharing options...
NotoriousPP Posted June 14, 2014 Share Posted June 14, 2014 It's all about CPU management. That math is quite heavy, especially if you call it every time the onPaint refreshes int nextLevelXP = getXPForLevel(level); if(currentXP >= nextLevelXP ) nextLevelXP = getXPForLevel(level); Then do that. 1 Link to comment Share on other sites More sharing options...
Botre Posted June 14, 2014 Author Share Posted June 14, 2014 int nextLevelXP = getXPForLevel(level); if(currentXP >= nextLevelXP ) nextLevelXP = getXPForLevel(level); Then do that. Isn't that what my ternaries do ? x > 0 ? x : 0; I'm confused, which method are you talking about ? Link to comment Share on other sites More sharing options...
NotoriousPP Posted June 14, 2014 Share Posted June 14, 2014 Isn't that what my ternaries do ? x > 0 ? x : 0; I'm confused, which method are you talking about ? That was pseudo-code, so I really don't think I need to add a ternary to that. Honestly Im just saying this: private final static int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 }; Is fugly as fuck, and no wants to see that. If you know how to decently program you can figure the rest out using my method, I don't see a need to argue. Link to comment Share on other sites More sharing options...
Botre Posted June 14, 2014 Author Share Posted June 14, 2014 (edited) That was pseudo-code, so I really don't think I need to add a ternary to that. Honestly Im just saying this: private final static int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 }; Is fugly as fuck, and no wants to see that. If you know how to decently program you can figure the rest out using my method, I don't see a need to argue. Aesthetics < performance. Mine requires less CPU than yours, go ahead an prove me wrong. Ugly as fuck, who gives a shit? Also, I never told you to add a ternary to your code :p Edited June 14, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
NotoriousPP Posted June 14, 2014 Share Posted June 14, 2014 Aesthetics < performance. Mine requires less CPU than yours, go ahead an prove me wrong. Ugly as fuck, who gives a shit? Well using it correctly, and I mean by not calling every time onLoop or onPaint, it will literally amount to a minuscule difference in usage. So I don't see the point in looking like a idiot who recorded all the level XP, and stored them in a int[], when you can use less code, and achieve the same job, but dynamically, and not by hard coding which is a common bad practice. But don't listen to me, I don't know anything. Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 14, 2014 Share Posted June 14, 2014 Aesthetics < performance. Mine requires less CPU than yours, go ahead an prove me wrong. Ugly as fuck, who gives a shit? Also, I never told you to add a ternary to your code Well, the whole idea behind OOP is that your code should be designed to be reusable and extended upon, hence the whole concept of polymorphism. If Jagex suddenly updated the skill cap to be 120 then your code would be broken and need the correct level indexes added to that array. In the case of a massive business application, a minor change like that could mean weeks of bug fixing and updating. 1 Link to comment Share on other sites More sharing options...