Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.autoMerchanter;
- import org.tribot.api.Clicking;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Keyboard;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.types.RSInterface;
- import org.tribot.api2007.types.RSInterfaceChild;
- import org.tribot.api2007.types.RSInterfaceComponent;
- public class Trader {
- private Check values;
- private Clicker clicker;
- public Trader(Check values) {
- this.values = values;
- this.clicker = new Clicker(values);
- }
- public void startTrade() {
- //*
- /* Initializes trade with
- * Person who traded
- */
- RSInterface chat = Interfaces.get(137, 4);
- if (chat != null) {
- if (chat.click()) {
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return values.inTrade();
- }
- }, General.random(1200, 1800));
- }
- }
- }
- public void handleFirstTrade(){
- //*
- /* Checks if we've offered an item, if not it offers
- * Than determines wether or not we can accept the trade
- */
- if (!offeredItem()) {
- General.println("Offering item");
- offerItem();
- }
- else if (!haveAnOffer()) {
- if (!Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return haveAnOffer();
- }
- }, General.random(8000, 12000))) {
- clicker.handleTradeScreen(false);
- }
- }
- else if (canAccept()) {
- clicker.handleTradeScreen(true);
- }
- else {
- clicker.handleTradeScreen(false);
- }
- }
- private void offerItem() {
- //*
- /* Offers item for both buying and selling,
- * Depending on which state the bot is in
- */
- switch(values.status){
- case "selling":
- if (Clicking.click("Offer", Inventory.find(values.itemName))) {
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return offeredItem();
- }
- }, General.random(3300, 4300));
- }
- break;
- case "buying":
- if (Clicking.click("Offer-X", Inventory.find("Coins"))) {
- if (Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Interfaces.isInterfaceValid(137);
- }
- }, General.random(3300, 4300))) {
- Keyboard.typeSend(Integer.toString(values.buyingPrice));
- }
- }
- break;
- }
- }
- private boolean offeredItem() {
- //*
- /* Checks through trade screen to see if
- * there is an offer
- */
- RSInterfaceChild ourSide = Interfaces.get(335, 48);
- if(ourSide != null){
- RSInterfaceComponent[] ourChildren = ourSide.getChildren();
- if(ourChildren != null) {
- for(RSInterfaceComponent i : ourChildren){
- if (i != null && !i.isHidden()) {
- if (i.getComponentItem() != -1) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public void handleSecondTrade(){
- if(tradeIsGood()){
- clicker.handleTradeScreen(true);
- }
- else {
- clicker.handleTradeScreen(false);
- }
- }
- public boolean canAccept(){
- //*
- /* Checks through the trade screen to see
- * if its the item that we want to have
- */
- RSInterface theirSide = Interfaces.get(335, 50);
- if (theirSide != null){
- RSInterfaceComponent[] offers = Interfaces.get(335, 50).getChildren();
- if (offers != null) {
- for (RSInterfaceComponent i : offers){
- if (i != null && !i.isHidden()) {
- String item = i.getComponentName();
- if (item != null && (item.contains("Coins")
- || item.contains(values.itemName))){
- return !clickedAccept();
- }
- }
- }
- }
- }
- return false;
- }
- public boolean clickedAccept() {
- RSInterface accepted = Interfaces.get(Interfaces.isInterfaceValid(335) ? 335 : 334, Interfaces.isInterfaceValid(335) ? 56 : 33);
- if (accepted != null) {
- String text = accepted.getText();
- return text != null && (text.contains(values.WAITING_MESSAGE));
- }
- return false;
- }
- public static boolean haveAnOffer(){
- RSInterfaceChild theirSide = Interfaces.get(335, 50);
- if(theirSide != null){
- RSInterfaceComponent[] theirChildren = theirSide.getChildren();
- if(theirChildren != null) {
- for(RSInterfaceComponent i : theirChildren){
- if (i != null && !i.isHidden()) {
- if (i.getComponentItem() != -1) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public boolean tradeIsGood() {
- //*
- /* Checks through the trade screen to see
- * if its the item that we want to have,
- * Or coins and the right amount
- */
- if (Interfaces.isInterfaceValid(334)) {
- for (RSInterface i : Interfaces.get(334, 40).getChildren()) {
- if (i != null && (i.getText().contains(getCoinAmount())
- && i.getText().contains("Coins"))
- || i.getText().contains(values.itemName)) {
- return true;
- }
- }
- }
- return false;
- }
- private String getCoinAmount() {
- //adds nessesary commas to match the onscreen text
- String amt = Integer.toString(values.sellingPrice);
- StringBuffer sub = new StringBuffer(amt);
- if (amt.length() == 5) {
- //thousands
- amt = sub.insert(2, ",").toString();
- General.println(amt);
- }
- else if (amt.length() == 6) {
- //hundred thousands
- amt = sub.insert(3, ",").toString();
- }
- else if (amt.length() == 7) {
- //millions
- amt = sub.insert(1, ",").toString();
- StringBuffer sub2 = new StringBuffer(amt);
- amt = sub2.insert(5, ",").toString();
- }
- return amt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement