Guest User

Untitled

a guest
Nov 17th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. /*
  2. * Gets realtime percent (when not in combat).
  3. */
  4. public final static int getHpPercent(){
  5. final double maxHp = Skills.getLevel(3) * 10.0,
  6. currHp = (double)Integer.parseInt(Widgets.get(748, 8).getText());
  7. final int hpPercent = (int)((currHp/maxHp)*100.0);
  8.  
  9. return hpPercent;
  10. }
  11.  
  12. /*
  13. * Assumes menu is open.
  14. */
  15. public final static int getMenuIndex(final String action) {
  16. String[] actions = Menu.getActions();
  17. for(int i = 0; i < actions.length; i++){
  18. if(actions[i].equals(action)){
  19. return i + 1;
  20. }
  21. }
  22. return -1;
  23. }
  24.  
  25. /*
  26. * Name.
  27. */
  28. public boolean clickWidgetOption(final Widget widget, String option) {
  29. if (widget.validate()) {
  30. option = option.toLowerCase();
  31. for (final WidgetChild c : widget.getChildren()) {
  32. if (c.getText().toLowerCase().contains(option)) {
  33. return c.click(true);
  34. }
  35. }
  36. }
  37. return false;
  38. }
  39.  
  40. /*
  41. * Gets an inventory item based on a specified ID.
  42. */
  43. public Item getItem(final int... ids){
  44. for(final Item item : Inventory.getItems()){
  45. for(int id : ids){
  46. if(item.getId() == id){
  47. return item;
  48. }
  49. }
  50. }
  51. return null;
  52. }
  53.  
  54. /*
  55. * Interacts with an item in the inventory.
  56. */
  57. public boolean interactItem(final String action, final Item item){
  58. for(final Item invItem : Inventory.getItems()){
  59. if(invItem.equals(item)){
  60. return invItem.getWidgetChild().interact(action);
  61. }
  62. }
  63. return false;
  64. }
  65.  
  66. /*
  67. * Checks if a widget contains certain text.
  68. */
  69. public boolean containsText(final Widget widget, String text) {
  70. if (widget.validate()) {
  71. text = text.toLowerCase();
  72. if(widget.getText().toLowerCase().contains(text)){
  73. return true;
  74. }
  75. for (final WidgetChild c : widget.getChildren()) {
  76. if (c.getText().toLowerCase().contains(text)) {
  77. return true;
  78. }
  79. }
  80. }
  81. return false;
  82. }
Add Comment
Please, Sign In to add comment