-
Notifications
You must be signed in to change notification settings - Fork 0
/
water-jug-filler.js
170 lines (157 loc) · 5.53 KB
/
water-jug-filler.js
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
// BEFORE RUNNING THIS CODE, ENSURE CHARACTER CAN SEE BANK BOX. EMPTY JUGS SHOULD BE IN THE FIRST INVENTORY SPOT.
//BOT DOES NOT HAVE FUNCTIONALITY TO ENTER BANK PIN.
var robot = require("robotjs");
var basic = require('./basic-functions.js');
var game = require('./game.js');
function main() {
console.log("Starting water jug filler...");
basic.sleep(6000); // 4000 ms = 4 seconds
game.openBackpack();
numJugsFilled = 0;
while(numJugsFilled < 3610) {
//open bank chest
var chest = findBankChest();
if (chest) {
robot.moveMouse(chest.x, chest.y);
robot.mouseClick();
basic.sleep(800);
//deposit and withdraw jugs
emptyBackpack();
basic.sleep(1200);
withdraw1400Items();
basic.sleep(900);
closeBank();
basic.sleep(1500);
}
//select a jug to use on sink
game.selectInventory_1_1();
//use jug on sink and wait for jugs to fill up
var sink = findSink();
if (sink) {
robot.moveMouse(sink.x, sink.y);
robot.mouseClick();
basic.sleep(18000);
numJugsFilled += 28;
console.log('num jugs filled: ' + numJugsFilled);
}
}
console.log("done!");
}
function findBankChest() {
var start_x = 50, start_y = 100, width = 1300, height = 550;
var chestColors = ['543d14', '412e09', '3d2c0f', '49340a', '4e360c'];
var numRotations = 0;
while (numRotations < 5) {
var img = robot.screen.capture(start_x, start_y, width, height);
var numUnconfirmedChests = 0;
for (var i = 0; i < 1000; i++) {
var random_x = basic.getRandomInt(0,width - 1);
var random_y = basic.getRandomInt(0, height - 1);
var sampleColor = img.colorAt(random_x, random_y);
if (chestColors.includes(sampleColor)) {
var screen_x = random_x + start_x;
var screen_y = random_y + start_y;
numUnconfirmedChests ++;
basic.sleep(4000);
console.log("chest color: " + sampleColor);
if (confirmBankChest(screen_x, screen_y)) {
console.log("found chest at: " + screen_x + " and " + screen_y);
numUnconfirmedChests = 0;
return {x: screen_x, y: screen_y};
}
if (numUnconfirmedChests > 5) {
i = 1000;
}
}
}
basic.rotateCamera();
numRotations++;
}
return false;
}
function confirmBankChest(screen_x, screen_y) {
robot.moveMouse(screen_x, screen_y);
basic.sleep(500);
lenToCheck = 90
startValue = 30
totalCyan = 0
lineToCheck = robot.screen.capture(startValue, 37, lenToCheck, 1);
for (i = 0; i < lenToCheck; i++) {
[r,g,b] = basic.hexToRGB(lineToCheck.colorAt(i,0));
if (r < 30 && g > 180 && b > 180) {
totalCyan++
}
}
return (totalCyan > 32);
}
function emptyBackpack() {
var backpackButton_x = 875;
var backpackButton_y = 672;
robot.moveMouse(backpackButton_x, backpackButton_y);
basic.sleep(500);
robot.mouseClick();
}
function withdraw1400Items() {
var bank_item_x1 = 515;
var bank_item_y1 = 120;
game.selectNthOption(bank_item_x1, bank_item_y1, 4);
basic.sleep(500);
}
function closeBank() {
closeButton_x = 915;
closeButton_y = 42;
robot.moveMouse(closeButton_x, closeButton_y);
basic.sleep(500);
robot.mouseClick();
basic.sleep(500);
}
function findSink() {
var start_x = 50, start_y = 100, width = 1300, height = 550;
var sinkColors = ['514949', '4f4747', '4c4545', '5e5655'];
var numRotations = 0;
while (numRotations < 5) {
var img = robot.screen.capture(start_x, start_y, width, height);
var numUnconfirmedSinks = 0;
for (var i = 0; i < 1000; i++) {
var random_x = basic.getRandomInt(0,width - 1);
var random_y = basic.getRandomInt(0, height - 1);
var pixelColor = img.colorAt(random_x, random_y);
if (sinkColors.includes(pixelColor)) {
var screen_x = random_x + start_x;
var screen_y = random_y + start_y;
numUnconfirmedSinks ++;
console.log("sink color: " + pixelColor);
console.log(numUnconfirmedSinks);
if (confirmSink(screen_x, screen_y)) {
console.log("found sink at: " + screen_x + " and " + screen_y);
console.log(pixelColor);
num_unconfirmed_sinks = 0;
return {x: screen_x, y: screen_y};
}
}
if (numUnconfirmedSinks > 5) {
i = 1000;
}
}
basic.rotateCamera();
numRotations++;
}
game.selectInventory_1_1();
return false;
}
function confirmSink(screen_x, screen_y) {
robot.moveMouse(screen_x, screen_y);
basic.sleep(500);
lenToCheck = 115
startValue = 75
totalCyan = 0
lineToCheck = robot.screen.capture(startValue, 37, lenToCheck, 1);
for (i = 0; i < lenToCheck; i++) {
[r,g,b] = basic.hexToRGB(lineToCheck.colorAt(i,0));
if (r < 30 && g > 180 && b > 180) {
totalCyan++
}
}
return (totalCyan > 43);
}
main();