-
-
Save youramazingames/d5e07bc64dd99477f9aba903ad0177ec to your computer and use it in GitHub Desktop.
npcInteract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.YOURNAMEHERE.bots.BOTHERE; // Change to your package | |
import com.runemate.game.api.hybrid.entities.Actor; | |
import com.runemate.game.api.hybrid.local.Camera; | |
import com.runemate.game.api.hybrid.local.hud.interfaces.ChatDialog; | |
import com.runemate.game.api.script.Execution; | |
import com.runemate.game.api.script.framework.task.TaskBot; | |
import java.util.Objects; | |
/** | |
* An API for talking to NPCS in Runscape using runemate. | |
* | |
* Takes the input example of: | |
* | |
* @code Actor a = Npcs.newQuery().names("NPC_NAME").results().first(); | |
* @code Object[] list = {1, "Test!", 4} | |
* @code talk(a, list) | |
* | |
* This will then talk to the NPC, select the first choice option. | |
* Then on the second one it will look for the one with the exact name of "Test!" and select that. | |
* Then finally it will choose the 4th option on the 3 Choice section. | |
* | |
* This is designed for RS3 but may work in OSRS not tested. | |
* | |
* @author youramazingames | |
* @version 1.0 | |
* @since 06/07/2017 | |
* | |
*/ | |
public class npcInteract extends TaskBot { | |
// Init Variables | |
private boolean interact; | |
private int interactNum; | |
private boolean facingNPC = false; | |
/** | |
* Initial Action called to run the whole thing | |
* @param a The NPC you want to talk too | |
* @param interacts An object List of Interactions, takes ints for number to select or Strings to find. | |
*/ | |
public void talk(Actor a, Object[] interacts){ | |
interact = true; | |
interactNum = 0; | |
facingNPC = false; | |
while(interact) { | |
if (a != null) { | |
npcInteracts(a, interacts); | |
}else {interact = false;} | |
} | |
} | |
/** | |
* Starts interaction with NPC | |
* @param a Stores the NPC data | |
* @param interacts Stores Interact data | |
*/ | |
private void npcInteracts(Actor a, Object[] interacts){ | |
if(a != null) { | |
if(!facingNPC) { | |
Camera.concurrentlyTurnTo(a); | |
facingNPC = true; | |
} | |
Execution.delayUntil(this::isChatDialogOpen, 200, 400); | |
if (!isChatDialogOpen()) { | |
a.interact("Talk-to"); // For what ever reason some NPC have "Talk-to" as their option. | |
a.interact("Talk to"); // And others have "Talk to" maybe its just old code and new together. | |
if (Execution.delayUntil(this::isChatDialogOpen, 2000, 4000)) { | |
npcTalk(interacts); | |
} | |
} else { | |
npcTalk(interacts); | |
} | |
} | |
} | |
/** | |
* The talking part of the API | |
* @param interacts Stores Interact data | |
*/ | |
private void npcTalk(Object[] interacts){ | |
if(ChatDialog.getContinue()!=null){ | |
ChatDialog.getContinue().select(); | |
Execution.delayUntil(() -> ChatDialog.getContinue()==null, 1000); | |
} | |
else { | |
String chat1 = ChatDialog.getOptions().toString(); | |
if (interacts[interactNum] instanceof Integer) { | |
ChatDialog.getOption((int) interacts[interactNum]).select(); | |
Execution.delay(400, 1000); | |
} else if (interacts[interactNum] instanceof String) { | |
ChatDialog.getOption((String) interacts[interactNum]).select(); | |
Execution.delay(400, 1000); | |
} | |
String chat2 = ChatDialog.getOptions().toString(); | |
// Checking if it did click the option or not. | |
if (!Objects.equals(chat1, chat2)) { | |
interactNum += 1; | |
if(interacts.length == interactNum){ | |
continueClick(); | |
interact = false; | |
} | |
} | |
} | |
} | |
/** | |
* Closes all continue boxs after talking has finished | |
*/ | |
private void continueClick(){ | |
while(ChatDialog.getContinue() != null){ | |
ChatDialog.getContinue().select(); | |
Execution.delayUntil(() -> ChatDialog.getContinue() == null, 400,1000); | |
} | |
} | |
/** | |
* Checks if the Dialog box is open | |
* @return True if dialog box is open | |
*/ | |
private boolean isChatDialogOpen(){ | |
return ChatDialog.getText() != null || ChatDialog.getTitle() != null || ChatDialog.getContinue() != null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment