Guest User

Untitled

a guest
Jul 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.44 KB | None | 0 0
  1. package methods;
  2.  
  3. import org.powerbot.game.api.methods.Tabs;
  4. import org.powerbot.game.api.methods.Widgets;
  5. import org.powerbot.game.api.methods.tab.Skills;
  6. import org.powerbot.game.api.util.Random;
  7. import org.powerbot.game.api.util.Time;
  8.  
  9.  
  10. /**
  11. * This class is for all the skill calculations.
  12. * <p/>
  13. * Example usage: skills.getRealLevel(Skills.ATTACK);
  14. */
  15. public class Skill {
  16. public static final String[] SKILL_NAMES = {"attack", "defence",
  17. "strength", "constitution", "range", "prayer", "magic", "cooking",
  18. "woodcutting", "fletching", "fishing", "firemaking", "crafting",
  19. "smithing", "mining", "herblore", "agility", "thieving", "slayer",
  20. "farming", "runecrafting", "hunter", "construction", "summoning",
  21. "dungeoneering", "-unused-"};
  22.  
  23. /**
  24. * A table containing the experiences that begin each level.
  25. */
  26. public static final int[] XP_TABLE = {0, 0, 83, 174, 276, 388, 512, 650,
  27. 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523,
  28. 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031,
  29. 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408,
  30. 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127,
  31. 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
  32. 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599,
  33. 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445,
  34. 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200,
  35. 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594,
  36. 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253,
  37. 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431,
  38. 14391160, 15889109, 17542976, 19368992, 21385073, 23611006,
  39. 26068632, 28782069, 31777943, 35085654, 38737661, 42769801,
  40. 47221641, 52136869, 57563718, 63555443, 70170840, 77474828,
  41. 85539082, 94442737, 104273167};
  42.  
  43. public static final int ATTACK = 0;
  44. public static final int DEFENSE = 1;
  45. public static final int STRENGTH = 2;
  46. public static final int CONSTITUTION = 3;
  47. public static final int RANGE = 4;
  48. public static final int PRAYER = 5;
  49. public static final int MAGIC = 6;
  50. public static final int COOKING = 7;
  51. public static final int WOODCUTTING = 8;
  52. public static final int FLETCHING = 9;
  53. public static final int FISHING = 10;
  54. public static final int FIREMAKING = 11;
  55. public static final int CRAFTING = 12;
  56. public static final int SMITHING = 13;
  57. public static final int MINING = 14;
  58. public static final int HERBLORE = 15;
  59. public static final int AGILITY = 16;
  60. public static final int THIEVING = 17;
  61. public static final int SLAYER = 18;
  62. public static final int FARMING = 19;
  63. public static final int RUNECRAFTING = 20;
  64. public static final int HUNTER = 21;
  65. public static final int CONSTRUCTION = 22;
  66. public static final int SUMMONING = 23;
  67. public static final int DUNGEONEERING = 24;
  68.  
  69. public static final int INTERFACE_TAB_STATS = 320;
  70. public static final int INTERFACE_ATTACK = 1;
  71. public static final int INTERFACE_DEFENSE = 22;
  72. public static final int INTERFACE_STRENGTH = 4;
  73. public static final int INTERFACE_CONSTITUTION = 2;
  74. public static final int INTERFACE_RANGE = 46;
  75. public static final int INTERFACE_PRAYER = 70;
  76. public static final int INTERFACE_MAGIC = 87;
  77. public static final int INTERFACE_COOKING = 62;
  78. public static final int INTERFACE_WOODCUTTING = 102;
  79. public static final int INTERFACE_FLETCHING = 95;
  80. public static final int INTERFACE_FISHING = 38;
  81. public static final int INTERFACE_FIREMAKING = 85;
  82. public static final int INTERFACE_CRAFTING = 78;
  83. public static final int INTERFACE_SMITHING = 20;
  84. public static final int INTERFACE_MINING = 3;
  85. public static final int INTERFACE_HERBLORE = 30;
  86. public static final int INTERFACE_AGILITY = 12;
  87. public static final int INTERFACE_THIEVING = 54;
  88. public static final int INTERFACE_SLAYER = 112;
  89. public static final int INTERFACE_FARMING = 120;
  90. public static final int INTERFACE_RUNECRAFTING = 104;
  91. public static final int INTERFACE_HUNTER = 136;
  92. public static final int INTERFACE_CONSTRUCTION = 128;
  93. public static final int INTERFACE_SUMMONING = 144;
  94. public static final int INTERFACE_DUNGEONEERING = 152;
  95.  
  96. /**
  97. * Gets the index of the skill with a given name. This is not case
  98. * sensitive.
  99. *
  100. * @param statName The skill's name.
  101. * @return The index of the specified skill; otherwise -1.
  102. * @see #Skills.SKILL_NAMES
  103. */
  104. public static int getIndex(final String statName) {
  105. for (int i = 0; i < Skill.SKILL_NAMES.length; i++) {
  106. if (Skill.SKILL_NAMES[i].equalsIgnoreCase(statName)) {
  107. return i;
  108. }
  109. }
  110. return -1;
  111. }
  112.  
  113. /**
  114. * Gets the level at the given experience.
  115. *
  116. * @param exp The experience.
  117. * @return The level based on the experience given.
  118. * @see #XP_TABLE
  119. */
  120. public static int getLevelAt(final int exp) {
  121. for (int i = Skill.XP_TABLE.length - 1; i > 0; i--) {
  122. if (exp > Skill.XP_TABLE[i]) {
  123. return i;
  124. }
  125. }
  126. return 1;
  127. }
  128.  
  129. /**
  130. * Gets the experience at the given level.
  131. *
  132. * @param lvl The level.
  133. * @return The level based on the experience given.
  134. */
  135. public static int getExpAt(final int lvl) {
  136. if (lvl > 120) {
  137. return 1;
  138. }
  139. return Skill.XP_TABLE[lvl - 1];
  140. }
  141.  
  142. /**
  143. * Gets the experience required for the given level.
  144. *
  145. * @param lvl The level.
  146. * @return The level based on the experience given.
  147. */
  148. public static int getExpRequired(final int lvl) {
  149. if (lvl > 120) {
  150. return 1;
  151. }
  152. return Skill.XP_TABLE[lvl];
  153. }
  154.  
  155. /**
  156. * Gets the skill name of an index.
  157. *
  158. * @param index The index.
  159. * @return The name of the skill for that index.
  160. */
  161. public static String getSkillName(final int index) {
  162. if (index > Skill.SKILL_NAMES.length - 1) {
  163. return null;
  164. }
  165. return Skill.SKILL_NAMES[index];
  166. }
  167.  
  168. /**
  169. * Gets the current experience for the given skill.
  170. *
  171. * @param index The index of the skill.
  172. * @return -1 if the skill is unavailable
  173. */
  174. public static int getCurrentExp(final int index) {
  175. if (index > Skill.SKILL_NAMES.length - 1) {
  176. return -1;
  177. }
  178. final int[] skills = Skills.getExperiences();
  179.  
  180. if (index > skills.length - 1) {
  181. return -1;
  182. }
  183.  
  184. return Skills.getExperiences()[index];
  185. }
  186.  
  187. /**
  188. * Gets the effective level of the given skill (accounting for temporary
  189. * boosts and reductions).
  190. *
  191. * @param index The index of the skill.
  192. * @return The current level of the given Skill.
  193. */
  194. public static int getCurrentLevel(final int index) {
  195. if (index > Skill.SKILL_NAMES.length - 1) {
  196. return -1;
  197. }
  198. return Skills.getLevels()[index];
  199. }
  200.  
  201. /**
  202. * Gets the player's current level in a skill based on their experience in
  203. * that skill.
  204. *
  205. * @param index The index of the skill.
  206. * @return The real level of the skill.
  207. * @see #getRealLevel(int)
  208. */
  209. public static int getRealLevel(final int index) {
  210. if (index > Skill.SKILL_NAMES.length - 1) {
  211. return -1;
  212. }
  213. return Skill.getLevelAt(getCurrentExp(index));
  214. }
  215.  
  216. /**
  217. * Gets the percentage to the next level in a given skill.
  218. *
  219. * @param index The index of the skill.
  220. * @return The percent to the next level of the provided skill or 0 if level
  221. * of skill is 99.
  222. */
  223. public static int getPercentToNextLevel(final int index) {
  224. if (index > Skill.SKILL_NAMES.length - 1) {
  225. return -1;
  226. }
  227. final int lvl = getRealLevel(index);
  228. return getPercentToLevel(index, lvl + 1);
  229. }
  230.  
  231. /**
  232. * Gets the percentage to the a level in a given skill.
  233. *
  234. * @param index The index of the skill.
  235. * @param endLvl The level for the percent.
  236. * @return The percent to the level provided of the provided skill or 0 if level
  237. * of skill is 99.
  238. */
  239. public static int getPercentToLevel(final int index, final int endLvl) {
  240. if (index > Skill.SKILL_NAMES.length - 1) {
  241. return -1;
  242. }
  243. final int lvl = getRealLevel(index);
  244. if (index == Skill.DUNGEONEERING && (lvl == 120 || endLvl > 120)) {
  245. return 0;
  246. } else if (lvl == 99 || endLvl > 99) {
  247. return 0;
  248. }
  249. final int xpTotal = Skill.XP_TABLE[endLvl] - Skill.XP_TABLE[lvl];
  250. if (xpTotal == 0) {
  251. return 0;
  252. }
  253. final int xpDone = getCurrentExp(index) - Skill.XP_TABLE[lvl];
  254. return 100 * xpDone / xpTotal;
  255. }
  256.  
  257. /**
  258. * Gets the maximum level of a given skill.
  259. *
  260. * @param index The index of the skill.
  261. * @return The max level of the skill.
  262. */
  263. public int getMaxLevel(final int index) {
  264. if (index > Skill.SKILL_NAMES.length - 1) {
  265. return -1;
  266. }
  267. return Skills.getMaxLevels()[index];
  268. }
  269.  
  270. /**
  271. * Gets the maximum experience of a given skill.
  272. *
  273. * @param index The index of the skill.
  274. * @return The max experience of the skill.
  275. */
  276. public int getMaxExp(final int index) {
  277. if (index > Skill.SKILL_NAMES.length - 1) {
  278. return -1;
  279. }
  280. return Skills.getMaxExperiences()[index];
  281. }
  282.  
  283. /**
  284. * Gets the experience remaining until reaching the next level in a given
  285. * skill.
  286. *
  287. * @param index The index of the skill.
  288. * @return The experience to the next level of the skill.
  289. */
  290. public static int getExpToNextLevel(final int index) {
  291. if (index > Skill.SKILL_NAMES.length - 1) {
  292. return -1;
  293. }
  294. final int lvl = getRealLevel(index);
  295. return getExpToLevel(index, lvl + 1);
  296. }
  297.  
  298. /**
  299. * Gets the experience remaining until reaching the a level in a given
  300. * skill.
  301. *
  302. * @param index The index of the skill.
  303. * @param endLvl The level for the experience remaining.
  304. * @return The experience to the level provided of the skill.
  305. */
  306. public static int getExpToLevel(final int index, final int endLvl) {
  307. if (index > Skill.SKILL_NAMES.length - 1) {
  308. return -1;
  309. }
  310. final int lvl = getRealLevel(index);
  311. if (index == Skill.DUNGEONEERING && (lvl == 120 || endLvl > 120)) {
  312. return 0;
  313. } else if (lvl == 99 || endLvl > 99) {
  314. return 0;
  315. }
  316. return Skill.XP_TABLE[endLvl] - getCurrentExp(index);
  317. }
  318.  
  319. /**
  320. * Gets the time remaining until the next level.
  321. *
  322. * @param index The index of the skill.
  323. * @param exp The start Exp.
  324. * @param time The time the script has been running.
  325. * @return The time till the next level of the skill.
  326. */
  327. public long getTimeTillNextLevel(int index, int exp, long time) {
  328. if (index > Skill.SKILL_NAMES.length - 1) {
  329. return -1;
  330. }
  331. int level = getRealLevel(index);
  332. return getTimeTillLevel(index, exp, level + 1, time);
  333. }
  334.  
  335. /**
  336. * Gets the time remaining until the level provided.
  337. *
  338. * @param index The index of the skill.
  339. * @param exp The start Exp.
  340. * @param endLvl The level to get the time till for.
  341. * @param time The time the script has been running.
  342. * @return The time till the level provided of the skill.
  343. */
  344. public long getTimeTillLevel(int index, int exp, int endLvl, long time) {
  345. if (index > Skill.SKILL_NAMES.length - 1) {
  346. return -1;
  347. }
  348. int level = getRealLevel(index);
  349. int currentExp = getCurrentExp(index);
  350. if (index == Skill.DUNGEONEERING && level == 120) {
  351. return 0;
  352. } else if (level == 99) {
  353. return 0;
  354. }
  355. try {
  356. return ((time * getExpToLevel(index, endLvl)) / (currentExp - exp));
  357. } catch (Exception e) {
  358. return -1;
  359. }
  360. }
  361.  
  362. /**
  363. * Gets the number of actions needed until the next level.
  364. *
  365. * @param index The index.
  366. * @param exp The exp each action gives.
  367. * @return How many you need to do until the next level.
  368. */
  369. public int ammountTillNextLevel(final int index, final double exp) {
  370. if (index > Skill.SKILL_NAMES.length - 1) {
  371. return -1;
  372. }
  373. int level = getRealLevel(index);
  374. return ammountTillLevel(index, exp, level + 1);
  375. }
  376.  
  377. /**
  378. * Gets the number of actions needed until the level provided.
  379. *
  380. * @param index The index.
  381. * @param exp The exp each action gives.
  382. * @param lvl The level to get the ammount till for.
  383. * @return How many you need to do until leveling to the level provided.
  384. */
  385. public int ammountTillLevel(final int index, final double exp, final int lvl) {
  386. if (index > Skill.SKILL_NAMES.length - 1) {
  387. return -1;
  388. }
  389. return getExpToLevel(index, lvl) != -1 ? (int) (getExpToLevel(index, lvl) / exp) : 0;
  390. }
  391.  
  392. /**
  393. * Gets the total/overall level.
  394. *
  395. * @return The total/overall level.
  396. */
  397. public int getTotalLevel() {
  398. int total = 0;
  399. for (int i = 0; i < Skill.SKILL_NAMES.length - 1; i++) {
  400. total += getRealLevel(i);
  401. }
  402. return total;
  403. }
  404.  
  405. /**
  406. * Gets the percent to max level in the specified skill index
  407. *
  408. * @param index Skill index.
  409. * @return Percent to level max level.
  410. */
  411. public int getPercentToMaxLevel(final int index) {
  412. if (index > Skill.SKILL_NAMES.length - 1) {
  413. return -1;
  414. }
  415. int lvl = 99;
  416. if (index == Skill.DUNGEONEERING) {
  417. lvl = 120;
  418. }
  419. return getPercentToLevel(index, lvl);
  420. }
  421.  
  422. /**
  423. * Gets the experience needed to the max level in the specified skill index
  424. *
  425. * @param index Skill index.
  426. * @return Experience to level max level.
  427. */
  428. public int getExpToMaxLevel(final int index) {
  429. if (index > Skill.SKILL_NAMES.length - 1) {
  430. return -1;
  431. }
  432. int lvl = 99;
  433. if (index == Skill.DUNGEONEERING) {
  434. lvl = 120;
  435. }
  436. return getExpToLevel(index, lvl);
  437. }
  438.  
  439. /**
  440. * Gets the time remaining until the max level.
  441. *
  442. * @param index The index of the skill.
  443. * @param exp The start Exp.
  444. * @param time The time the script has been running.
  445. * @return The time till the max level of the skill.
  446. */
  447. public long getTimeTillMaxLevel(int index, int exp, long time) {
  448. if (index > Skill.SKILL_NAMES.length - 1) {
  449. return -1;
  450. }
  451. int lvl = 99;
  452. if (index == Skill.DUNGEONEERING) {
  453. lvl = 120;
  454. }
  455. return getTimeTillLevel(index, exp, lvl, time);
  456. }
  457.  
  458. /**
  459. * Gets the number of actions needed until the max level.
  460. *
  461. * @param index The index.
  462. * @param exp The exp each action gives.
  463. * @return How many you need to do until the max level.
  464. */
  465. public int ammountTillMaxLevel(final int index, final double exp) {
  466. if (index > Skill.SKILL_NAMES.length - 1) {
  467. return -1;
  468. }
  469. int lvl = 99;
  470. if (index == Skill.DUNGEONEERING) {
  471. lvl = 120;
  472. }
  473. return ammountTillLevel(index, exp, lvl);
  474. }
  475.  
  476. /**
  477. * Moves the mouse over a given component in the stats tab.
  478. *
  479. * @param component The component index.
  480. * @return <tt>true</tt> if the mouse was moved over the given component
  481. * index.
  482. */
  483. public boolean doHover(int component) {
  484. Tabs.STATS.open();
  485. Time.sleep(Random.nextInt(10, 100));
  486. return Widgets.get(INTERFACE_TAB_STATS, component).hover();
  487. }
  488.  
  489. }
Add Comment
Please, Sign In to add comment