Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.Utilities;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.function.BooleanSupplier;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.NPCChat;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.types.RSInterface;
- import org.tribot.api2007.types.RSVarBit;
- public class NPCContact {
- private static final int INTERFACE_MASTER = 75;
- private static Map<String,Integer> cache = new HashMap<String,Integer>();
- public enum NPC {
- HONEST_JIMMY("Honest Jimmy"),
- BERT_THE_SANDMAN("Bert the Sandman"),
- ADVISOR_GHRIM("Advisor Ghrim"),
- DARK_MAGE("Dark Mage"),
- LANTHUS("Lanthus"),
- TURAEL("Turael"),
- MAZCHNA("Mazchna"),
- VANNAKA("Vannaka"),
- CHAELDAR("Chaeldar"),
- STIEVE("Nieve","Steve"),
- DURADEL("Duradel"),
- KRYSTILIA("Krystilia"),
- MURPHY("Murphy"),
- CYRISUS("Cyrisus"),
- SMOGGY("Smoggy"),
- CAPTAIN_GINEA("Captain Ginea"),
- WATSON("Watson"),
- BARBARIAN_GUARD("Barbarian guard"),
- RANDOM("Random");
- private String[] name;
- NPC(String... name){
- this.name = name;
- }
- public String[] getName(){
- return name;
- }
- public boolean contact(boolean waitForChat){
- if(getLastNPC() == this){
- return castSpell("NPC Contact",name) && (waitForChat ? Timing.waitCondition(chattingCondition(), 8000) : true);
- }
- if(!isOpen()){
- if(!(castSpell("NPC Contact","Cast") && Timing.waitCondition(new BooleanSupplier(){
- @Override
- public boolean getAsBoolean() {
- General.sleep(50,200);
- return isOpen();
- }
- }, 8000))){
- return false;
- }
- }
- RSInterface chat = getInterface();
- return chat != null && chat.click() && (waitForChat ? Timing.waitCondition(chattingCondition(), 8000) : true);
- }
- public RSInterface getInterface(){
- return NPCContact.getInterface(this.getName());
- }
- }
- public static boolean contactNPC(NPC npc, boolean shouldWait){
- return npc.contact(shouldWait);
- }
- public static NPC getLastNPC(){
- RSVarBit var = RSVarBit.get(5006);
- return var != null ? NPC.values()[var.getValue() - 1] : null;
- }
- public static boolean isOpen(){
- return Interfaces.isInterfaceSubstantiated(INTERFACE_MASTER);
- }
- private static RSInterface getInterface(String... names){
- for(String name:names){
- if(cache.containsKey(name)){
- return Interfaces.get(INTERFACE_MASTER, cache.get(name));
- }
- }
- RSInterface master = Interfaces.get(INTERFACE_MASTER);
- if(master == null)
- return null;
- RSInterface[] children = master.getChildren();
- if(children == null || children.length == 0)
- return null;
- for(RSInterface child:children){
- String[] actions = child.getActions();
- if(actions == null || actions.length == 0)
- continue;
- for(String name:names){
- if(Arrays.asList(actions).contains(name)){
- cache.put(name, child.getIndex());
- return child;
- }
- }
- }
- return null;
- }
- public static boolean castSpell(String spellName, String... action) {
- if(GameTab.open(TABS.MAGIC)){
- if(cache.containsKey("Spell " + spellName)){
- RSInterface spell = Interfaces.get(218, cache.get("Spell " + spellName));
- return spell != null && spell.click(action);
- }
- RSInterface spellbook = Interfaces.get(218);
- if(spellbook == null)
- return false;
- RSInterface[] spells = spellbook.getChildren();
- if(spells == null || spells.length == 0)
- return false;
- for(RSInterface spell:spells){
- if(spell.isHidden())
- continue;
- String name = spell.getComponentName();
- if(name != null && name.contains(spellName)){
- cache.put("Spell " + spellName, spell.getIndex());
- return spell.click(action);
- }
- }
- }
- return false;
- }
- private static BooleanSupplier chattingCondition(){
- return new BooleanSupplier(){
- @Override
- public boolean getAsBoolean() {
- General.sleep(50,200);
- return NPCChat.getClickContinueInterface() != null;
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement