-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathFlaxer.java
executable file
·230 lines (195 loc) · 6.17 KB
/
Flaxer.java
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.wrappers.*;
import java.awt.*;
import java.text.NumberFormat;
import java.util.Locale;
@ScriptManifest(authors = "Vastico", name = "Flaxer", version = 0.12)
public class Flaxer extends Script implements PaintListener {
/*
* Constants
*/
private static enum Action {
WALK_TO_FIELD, WALK_TO_BANK, PICK, BANK
}
private static final RSTile[] PATH = {new RSTile(2726, 3491),
new RSTile(2725, 3481), new RSTile(2728, 3472),
new RSTile(2726, 3464), new RSTile(2730, 3453),
new RSTile(2735, 3447), new RSTile(2739, 3443)};
private static final int FLAX_OBJECT = 2646;
private static final int FLAX_ITEM = 1779;
private static final RSArea FLAX_FIELD = new RSArea(2737, 3436, 2751, 3451);
private static final RSArea BANK_AREA = new RSArea(2722, 3490, 2730, 3493);
private static final Color MOUSE_COLOR = new Color(0, 0, 0, 50);
private static final Color MOUSE_BORDER_COLOR = new Color(255, 252, 0, 50);
private static final RenderingHints RENDERING_HINTS = new RenderingHints(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
private RSTilePath pathToFlax;
private RSTilePath pathToBank;
/* Script State */
private int nextMinRunEnergy;
private int flaxPrice;
private int flaxCollected;
private long startTime;
/*
* Overridden Methods
*/
@Override
public boolean onStart() {
flaxPrice = grandExchange.lookup(FLAX_ITEM).getGuidePrice();
return true;
}
/*
* Implemented Methods
*/
@Override
public int loop() {
if (startTime == 0) {
if (skills.getCurrentLevel(Skills.CONSTITUTION) > 1) {
initializeState();
} else {
return 500;
}
}
if (!walking.isRunEnabled() && walking.getEnergy() > nextMinRunEnergy) {
nextMinRunEnergy = random(30, 40);
walking.setRun(true);
}
switch (getAction()) {
case WALK_TO_BANK:
if (pathToBank.traverse()) {
sleep(500);
}
break;
case WALK_TO_FIELD:
if (pathToFlax.traverse()) {
sleep(500);
}
break;
case PICK:
RSObject flax = objects.getNearest(FLAX_OBJECT);
if (flax != null && flax.isOnScreen()) {
int startCount = inventory.getCount();
if (pickFlax(flax)) {
long picked = System.currentTimeMillis();
while (startCount == inventory.getCount()
&& System.currentTimeMillis() - picked < 10000) {
sleep(100);
}
if (startCount < inventory.getCount()) {
flaxCollected++;
}
}
}
break;
case BANK:
if (!bank.isOpen()) {
bank.open();
} else {
bank.depositAll();
long deposit = System.currentTimeMillis();
while (inventory.getCount() > 0
&& System.currentTimeMillis() - deposit < 10000) {
sleep(100);
}
}
}
return random(100, 200);
}
public void onRepaint(Graphics render) {
if (startTime == 0) {
return;
}
Graphics2D g = (Graphics2D) render;
g.setRenderingHints(RENDERING_HINTS);
NumberFormat comma = NumberFormat.getNumberInstance(new Locale("en",
"IN"));
RSInterface chatBox = interfaces.get(Game.INTERFACE_CHAT_BOX);
int y = 344;
if (chatBox != null && game.isLoggedIn()) {
y = chatBox.getComponent(0).getLocation().y;
}
long millis = System.currentTimeMillis() - startTime;
long hours = millis / (1000 * 60 * 60);
millis -= hours * 1000 * 60 * 60;
long minutes = millis / (1000 * 60);
millis -= minutes * 1000 * 60;
long seconds = millis / 1000;
g.setColor(new Color(168, 9, 9, 255));
g.setFont(new Font("Arial", Font.BOLD, 12));
g.drawString("Time Running:", 12, y + 41);
g.drawString("Flax Picked:", 12, y + 57);
g.drawString("Flax Value:", 12, y + 73);
g.setColor(new Color(0, 0, 0, 255));
g.setFont(new Font("Arial", Font.PLAIN, 12));
g.drawString(hours + " Hours " + minutes + " Minutes " + seconds
+ " Seconds", 120, y + 41);
g.drawString(comma.format(flaxCollected), 120, y + 57);
g.drawString(comma.format((flaxPrice * flaxCollected)), 120, y + 73);
g.setFont(new Font("Arial", Font.PLAIN, 9));
g.drawString("V. "
+ getClass().getAnnotation(ScriptManifest.class).version(),
478, y + 124);
drawMouse(g);
}
/*
* Defined Methods
*/
private void initializeState() {
nextMinRunEnergy = 20;
startTime = System.currentTimeMillis();
flaxCollected = 0;
pathToFlax = walking.newTilePath(PATH);
pathToBank = walking.newTilePath(PATH).reverse();
}
private Action getAction() {
if (inventory.isFull()) {
if (inArea(BANK_AREA)) {
return Action.BANK;
}
return Action.WALK_TO_BANK;
}
if (inArea(FLAX_FIELD)) {
return Action.PICK;
}
return Action.WALK_TO_FIELD;
}
public void drawMouse(final Graphics g) {
Point location = mouse.getLocation();
if (mouse.isPressed()) {
g.setColor(new Color(255, 252, 0, 150));
g.fillOval(location.x - 5, location.y - 5, 10, 10);
}
g.setColor(MOUSE_BORDER_COLOR);
g.drawLine(location.x, 0, location.x, game.getHeight());
g.drawLine(0, location.y, game.getWidth(), location.y);
g.setColor(MOUSE_COLOR);
g.drawLine(location.x + 1, 0, location.x + 1, game.getHeight());
g.drawLine(location.x - 1, 0, location.x - 1, game.getHeight());
g.drawLine(0, location.y + 1, game.getWidth(), location.y + 1);
g.drawLine(0, location.y - 1, game.getWidth(), location.y - 1);
}
private boolean pickFlax(RSObject obj) {
if (getMyPlayer().isMoving()) {
for (int i = 0, len = random(2, 5); i < len; ++i) {
mouse.move(obj.getModel().getPoint());
sleep(random(20, 100));
}
return menu.doAction("Pick");
} else {
return obj.doAction("Pick");
}
}
private boolean inArea(RSArea area) {
if (area != null && !area.contains(getMyPlayer().getLocation())) {
RSTile dest = walking.getDestination();
return dest != null && getMyPlayer().isMoving()
&& area.contains(dest) && calc.distanceTo(dest) < 8;
}
return true;
}
}