Advertisement
FALSkills

Untitled

Nov 15th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. package scripts.Utilities;
  2.  
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.function.BooleanSupplier;
  7.  
  8. import org.tribot.api.General;
  9. import org.tribot.api.Timing;
  10. import org.tribot.api2007.GameTab;
  11. import org.tribot.api2007.Interfaces;
  12. import org.tribot.api2007.NPCChat;
  13. import org.tribot.api2007.GameTab.TABS;
  14. import org.tribot.api2007.types.RSInterface;
  15. import org.tribot.api2007.types.RSVarBit;
  16.  
  17. public class NPCContact {
  18.  
  19. private static final int INTERFACE_MASTER = 75;
  20.  
  21.  
  22. private static Map<String,Integer> cache = new HashMap<String,Integer>();
  23. public enum NPC {
  24. HONEST_JIMMY("Honest Jimmy"),
  25. BERT_THE_SANDMAN("Bert the Sandman"),
  26. ADVISOR_GHRIM("Advisor Ghrim"),
  27. DARK_MAGE("Dark Mage"),
  28. LANTHUS("Lanthus"),
  29. TURAEL("Turael"),
  30. MAZCHNA("Mazchna"),
  31. VANNAKA("Vannaka"),
  32. CHAELDAR("Chaeldar"),
  33. STIEVE("Nieve","Steve"),
  34. DURADEL("Duradel"),
  35. KRYSTILIA("Krystilia"),
  36. MURPHY("Murphy"),
  37. CYRISUS("Cyrisus"),
  38. SMOGGY("Smoggy"),
  39. CAPTAIN_GINEA("Captain Ginea"),
  40. WATSON("Watson"),
  41. BARBARIAN_GUARD("Barbarian guard"),
  42. RANDOM("Random");
  43.  
  44. private String[] name;
  45. NPC(String... name){
  46. this.name = name;
  47. }
  48.  
  49. public String[] getName(){
  50. return name;
  51. }
  52.  
  53. public boolean contact(boolean waitForChat){
  54. if(getLastNPC() == this){
  55. return castSpell("NPC Contact",name) && (waitForChat ? Timing.waitCondition(chattingCondition(), 8000) : true);
  56. }
  57. if(!isOpen()){
  58. if(!(castSpell("NPC Contact","Cast") && Timing.waitCondition(new BooleanSupplier(){
  59.  
  60. @Override
  61. public boolean getAsBoolean() {
  62. General.sleep(50,200);
  63. return isOpen();
  64. }
  65.  
  66. }, 8000))){
  67. return false;
  68. }
  69. }
  70. RSInterface chat = getInterface();
  71. return chat != null && chat.click() && (waitForChat ? Timing.waitCondition(chattingCondition(), 8000) : true);
  72. }
  73.  
  74. public RSInterface getInterface(){
  75. return NPCContact.getInterface(this.getName());
  76. }
  77.  
  78. }
  79.  
  80. public static boolean contactNPC(NPC npc, boolean shouldWait){
  81. return npc.contact(shouldWait);
  82. }
  83.  
  84. public static NPC getLastNPC(){
  85. RSVarBit var = RSVarBit.get(5006);
  86. return var != null ? NPC.values()[var.getValue() - 1] : null;
  87. }
  88.  
  89. public static boolean isOpen(){
  90. return Interfaces.isInterfaceSubstantiated(INTERFACE_MASTER);
  91. }
  92.  
  93. private static RSInterface getInterface(String... names){
  94. for(String name:names){
  95. if(cache.containsKey(name)){
  96. return Interfaces.get(INTERFACE_MASTER, cache.get(name));
  97. }
  98. }
  99. RSInterface master = Interfaces.get(INTERFACE_MASTER);
  100. if(master == null)
  101. return null;
  102. RSInterface[] children = master.getChildren();
  103. if(children == null || children.length == 0)
  104. return null;
  105. for(RSInterface child:children){
  106. String[] actions = child.getActions();
  107. if(actions == null || actions.length == 0)
  108. continue;
  109. for(String name:names){
  110. if(Arrays.asList(actions).contains(name)){
  111. cache.put(name, child.getIndex());
  112. return child;
  113. }
  114. }
  115. }
  116. return null;
  117. }
  118.  
  119. public static boolean castSpell(String spellName, String... action) {
  120. if(GameTab.open(TABS.MAGIC)){
  121. if(cache.containsKey("Spell " + spellName)){
  122. RSInterface spell = Interfaces.get(218, cache.get("Spell " + spellName));
  123. return spell != null && spell.click(action);
  124. }
  125. RSInterface spellbook = Interfaces.get(218);
  126. if(spellbook == null)
  127. return false;
  128. RSInterface[] spells = spellbook.getChildren();
  129. if(spells == null || spells.length == 0)
  130. return false;
  131. for(RSInterface spell:spells){
  132. if(spell.isHidden())
  133. continue;
  134. String name = spell.getComponentName();
  135. if(name != null && name.contains(spellName)){
  136. cache.put("Spell " + spellName, spell.getIndex());
  137. return spell.click(action);
  138. }
  139. }
  140. }
  141. return false;
  142. }
  143.  
  144. private static BooleanSupplier chattingCondition(){
  145. return new BooleanSupplier(){
  146.  
  147. @Override
  148. public boolean getAsBoolean() {
  149. General.sleep(50,200);
  150. return NPCChat.getClickContinueInterface() != null;
  151. }
  152.  
  153. };
  154. }
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement