This repository was archived by the owner on Aug 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankItem.java
More file actions
94 lines (77 loc) · 2.48 KB
/
BankItem.java
File metadata and controls
94 lines (77 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package mAPI;
import java.awt.Point;
import java.awt.Rectangle;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import mAPI.Constants;
public class BankItem extends WidgetChild {
public BankItem(int index) {
super(Widgets.get(Constants.INDEX_BANK), Widgets.get(Constants.INDEX_BANK, Constants.BANK_ITEM_ARRAY), index);
}
public String getName() {
return this.getChildName();
}
public int getID() {
return this.getChildId();
}
public Rectangle getBankBox() {
return Widgets.get(Constants.INDEX_BANK, Constants.BANK_ITEM_ARRAY).getBoundingRectangle();
}
public int getGlobalX() {
return this.getParent().getAbsoluteX() + this.getRelativeX();
}
public int getGlobalY() {
return this.getParent().getAbsoluteY() + this.getRelativeY();
}
public int getAbsoluteX() {
if (this.getBankBox().contains(new Point(this.getGlobalX(), this.getGlobalY())))
return (int) this.getGlobalX();
return -1;
}
public int getAbsoluteY() {
if (this.getBankBox().contains(new Point(this.getGlobalX(), this.getGlobalY())))
return (int) this.getGlobalY();
return -1;
}
public Point getAbsoluteLocation() {
return new Point(this.getAbsoluteX(), this.getAbsoluteY());
}
public boolean isOnScreen() {
return this.getBankBox().contains(this.getAbsoluteLocation());
}
public boolean scrollTo() {
if (this.isOnScreen())
return true;
return Widgets.scroll(Widgets.get(Constants.INDEX_BANK, Constants.BANK_SCROLLBAR), this);
}
public boolean withdraw(int amount) {
if (this.scrollTo())
switch(amount) {
case -1:
return this.interact("Withdraw-All but one");
case 0:
return this.interact("Withdraw-All");
case 1:
return this.click(true);
default:
String[] actions = this.getActions();
for(String str:actions)
if (str.equals("Withdraw-" + amount))
return this.interact("Withdraw-" + amount);
Timer timeout = new Timer(3500);
//TO-DO: Solid method for detection of box!!!
while (!Widgets.get(Constants.BANK_AMOUNT_INDEX, Constants.BANK_AMOUNT_VISIBLE).isVisible()) {
if (timeout.getRemaining() == 0) return false;
this.interact("Withdraw-X");
Time.sleep(Random.nextInt(1200, 1600));
}
Keyboard.sendText("" + amount, true);
return true;
}
return false;
}
}