Jump to content
Ricky Dactyl

BankManager class

Recommended Posts

For whatever reason I couldn't get the OSBot's allocated API section regarding finding items in the bank to work, so I came up with my own method to do so.

Calling the BankManager object within your main script class.
unknown.png

The Class 

package com.shrykur.bots.thieving;

import java.awt.Rectangle;

import org.osbot.rs07.Bot;
import org.osbot.rs07.api.Bank;
import org.osbot.rs07.api.Mouse;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.input.mouse.RectangleDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.Condition;

public class BankManager {

	private Bot bot;
	private Mouse mouse;
	private Bank bank;
	private boolean canSee;
	private Script script;

	public BankManager(Script script) {
		this.script = script;
		this.bot = script.getBot();
		this.mouse = script.getMouse();
		this.bank = script.getBank();
		canSee = false;
	}

	public boolean containsItem(String name) {
		if (this.bank.contains(name)) {
			return true;
		}
		return false;
	}

	public boolean isVisible(String name) {
		this.canSee = this.bank.isSlotVisible(bot, getSlot(name), getSlot(name));
		return this.canSee;
	}

	@SuppressWarnings("static-access")
	public void withdrawItem(String name, int amount) {
		if (!this.isVisible(name)) {
			// Moves scroll bar to the top of the bank
			this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 1)));

			// Holds left click on downward arrow until item is visible
			RectangleDestination rd = new RectangleDestination(bot, new Rectangle(482, 280, 3, 10));
			this.mouse.continualClick(rd, new Condition() {
				@Override
				public boolean evaluate() {
					return isVisible(name);
				}
			}, false);
		}
		switch (amount) {
		case 1: {
			this.getItem(name).interact("Withdraw-1");
			break;
		}
		case 5: {
			this.getItem(name).interact("Withdraw-5");
			break;
		}
		case 10: {
			this.getItem(name).interact("Withdraw-10");
			break;
		}
		default: {
			try {
				this.getItem(name).interact("Withdraw-X");
				this.script.sleep(1000);
				this.script.getKeyboard().typeString(String.valueOf(amount));
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			break;
		}
		}
	}

	public void depositInventory() {
		if (this.bank.isOpen()) {
			this.mouse.click(new RectangleDestination(bot, new Rectangle(430, 297, 24, 30)));
		}
	}

	public Item getItem(String name) {
		return this.bank.getItem(name);
	}

	public int getSlot(String name) {
		return this.bank.getSlot(name);
	}

	public void close() {
		this.bank.close();
	}
}

Notes:
WithdrawItem(String, Integer) will automatically find the item within your bank.

This class is not completed, it's simply what I came up and use for the specific problem of finding and withdrawing a particular item from the bank.

BankManager.java

Edited by Ricky Dactyl
Link to comment
Share on other sites

Oof this is not good. The class is called Bank, you're using a lot of static widget ids which will certainly break over the course of a month. API should be the most stable part of your script and never break.

 

The getRandomInteger stuff is a bit confusing as well, what you could do is get a random point in the rectangle of the widget, since you wouldn't want to misclick? Also wouldn't withdrawing one at a time instead of Withdraw-10/Withdraw-X be less "bot like"?

I'm not quite understanding this part:
this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); 

This means you can only withdraw an item at a very specific slot on a very specific tab setup?

Hopefully you take it constructively, sorry if I came off as rude.
 

  • Like 1
Link to comment
Share on other sites

27 minutes ago, Alek said:

Oof this is not good. The class is called Bank, you're using a lot of static widget ids which will certainly break over the course of a month. API should be the most stable part of your script and never break.

 

The getRandomInteger stuff is a bit confusing as well, what you could do is get a random point in the rectangle of the widget, since you wouldn't want to misclick? Also wouldn't withdrawing one at a time instead of Withdraw-10/Withdraw-X be less "bot like"?

Also I'm not understanding this part:
this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); 

This means you can only withdraw an item at a very specific slot on a very specific tab setup?

Hopefully you take it constructively, sorry if I came off as rude.
 

Hey my dude, Hopefully I can shed some light, the built in Bank within OSBot was open/closing repeatedly without finding the slot requested, the only widget ID I've used is the one for this specific widget unknown.png  I wasn't aware widget ID's changed (I've only been developing for Runescape scripts for a few days.)

this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); was specifically to ensure that the slider in the bank is moved to the top most possible point.

The drawing out of items singularly was used because it's a personal class I've developed, I was simply putting it here encase anyone had a similar problem to mine then it would help them, either by taking the class as a whole and changing it to their needs or simply taking a specific set of code.

Hopefully this has cleared up any questions you had @Alek, I'd like to hear back about the widget ID's if you don't mind ^_^

Edited by Ricky Dactyl
  • Like 1
Link to comment
Share on other sites

32 minutes ago, Shrykur said:

Hey my dude, Hopefully I can shed some light, the built in Bank within OSBot was open/closing repeatedly without finding the slot requested, the only widget ID I've used is the one for this specific widget unknown.png  I wasn't aware widget ID's changed (I've only been developing for Runescape scripts for a few days.)

this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); was specifically to ensure that the slider in the bank is moved to the top most possible point.

The drawing out of items singularly was used because it's a personal class I've developed, I was simply putting it here encase anyone had a similar problem to mine then it would help them, either by taking the class as a whole and changing it to their needs or simply taking a specific set of code.

Hopefully this has cleared up any questions you had @Alek, I'd like to hear back about the widget ID's if you don't mind ^_^

Sounds like you were doing something not quite right. If you were using slot ids, then they were probably wrong (common mistake). Opening/closing the bank repeatedly sounds like a script problem, not OSBot. Visibility can be done by the widget of the slot which is your destination, however you can get the SlotDestination using default Bank methods. The deposit all button can be scanned for using sprite ids. 

Edit: I like that you were at least trying some solutions to your problem instead of giving up

  • Heart 1
Link to comment
Share on other sites

31 minutes ago, Alek said:

Sounds like you were doing something not quite right. If you were using slot ids, then they were probably wrong (common mistake). Opening/closing the bank repeatedly sounds like a script problem, not OSBot. Visibility can be done by the widget of the slot which is your destination, however you can get the SlotDestination using default Bank methods. The deposit all button can be scanned for using sprite ids. 

Edit: I like that you were at least trying some solutions to your problem instead of giving up

I took what you @Alek into consideration about widgets and based it purely from client mouse location (updated the class btw), the class no longer uses widgets and uses a less bot like withdraw method while catering for specific amounts of items being withdrawn. Encase someone stumbles upon this thread in the future with the same issue as mine, it should futureproof them.

Also worth mentioning, I was using a getItemSlot method within the OSBot API alongside the isSlotVisible method also from the OSBot API, I'm sure on sub-level it was something I was misusing in some shape or form. Thanks for the thoughts on Widgets :)

Edited by Ricky Dactyl
Link to comment
Share on other sites

On 7/31/2018 at 3:27 PM, liverare said:

 

Alek's simply jealous he'd never thought of:


	public boolean containsItem(String name) {
		if (this.bank.contains(name)) {
			return true;
		}
		return false;
	}

Success breeds jealousy.

I mean more or less the whole reason for this class was to do with this portion of the code, but okay.
 

public void withdrawItem(String name, int amount) {
		if (!this.isVisible(name)) {
			// Moves scroll bar to the top of the bank
			this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 1)));

			// Holds left click on downward arrow until item is visible
			RectangleDestination rd = new RectangleDestination(bot, new Rectangle(482, 280, 3, 10));
			this.mouse.continualClick(rd, new Condition() {
				@Override
				public boolean evaluate() {
					return isVisible(name);
				}
			}, false);
		}
		switch (amount) {
		case 1: {
			this.getItem(name).interact("Withdraw-1");
			break;
		}
		case 5: {
			this.getItem(name).interact("Withdraw-5");
			break;
		}
		case 10: {
			this.getItem(name).interact("Withdraw-10");
			break;
		}
		default: {
			try {
				this.getItem(name).interact("Withdraw-X");
				this.script.sleep(1000);
				this.script.getKeyboard().typeString(String.valueOf(amount));
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			break;
		}
		}
	}

 

Link to comment
Share on other sites

10 hours ago, Shrykur said:

I mean more or less the whole reason for this class was to do with this portion of the code, but okay.

I know. :) I supposed a bit of critique I have are:

  • Don't suppress warnings. If you're being told you can reference something statically, you should.
  • Don't add and then modified delegate methods unless it makes sense. The thing I was mocking you for was the fact that 'this.bank.contains' returns a bool and you could have simply returned that in your 'containsItem' method. Similar thing for your 'close' method.
  • OSBot has an InterruptedException handler, so you don't have to add your own. Instead, have your methods throw that exception up the stack.
  • You're effectively making an API, albeit an extension to the Bank API. Instead of defining mouse, keyboard, script, etc. just extend 'org.osbot.rs07.script.API' on your class, instantiate a new object of that class and call its 'exchangeContext' function and 'initialiseModule' function (in that order). That gives you access to all the internal APIs. You can see an example here.
  • Your 'withdrawItem' function is flawed in the human sense. If I have to withdraw 2 of something, I'm not going to be performing a 'withdraw-X', but I bet Jagex performs a little check of players who do. If the action requires maybe more than 5 mouse actions, then perhaps withdraw by X amount. By 5 mouse actions, that includes withdrawing 5 and 10, then left-clicking the rest. Have fun writing that AI. :)

 

  • Heart 1
Link to comment
Share on other sites

On 8/3/2018 at 12:32 PM, liverare said:

I know. :) I supposed a bit of critique I have are:

  • Don't suppress warnings. If you're being told you can reference something statically, you should.
  • Don't add and then modified delegate methods unless it makes sense. The thing I was mocking you for was the fact that 'this.bank.contains' returns a bool and you could have simply returned that in your 'containsItem' method. Similar thing for your 'close' method.
  • OSBot has an InterruptedException handler, so you don't have to add your own. Instead, have your methods throw that exception up the stack.
  • You're effectively making an API, albeit an extension to the Bank API. Instead of defining mouse, keyboard, script, etc. just extend 'org.osbot.rs07.script.API' on your class, instantiate a new object of that class and call its 'exchangeContext' function and 'initialiseModule' function (in that order). That gives you access to all the internal APIs. You can see an example here.
  • Your 'withdrawItem' function is flawed in the human sense. If I have to withdraw 2 of something, I'm not going to be performing a 'withdraw-X', but I bet Jagex performs a little check of players who do. If the action requires maybe more than 5 mouse actions, then perhaps withdraw by X amount. By 5 mouse actions, that includes withdrawing 5 and 10, then left-clicking the rest. Have fun writing that AI. :)

 

I respect your input and thank you for doing so, I'd rather you just tell me straight up rather than mock any work that anyone contributes, it's more productive that way. I completely agree with everything you said however for me this was just a quick fix for an issue I was having while suicide bottling some seeds, thank you though!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...