-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectTraps.java
142 lines (128 loc) · 6.4 KB
/
CollectTraps.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
package com.remco1337.bots.ImpHunter;
import com.runemate.game.api.hybrid.cache.sprites.Sprite;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.entities.GroundItem;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.Traversal;
import com.runemate.game.api.hybrid.location.navigation.basic.BresenhamPath;
import com.runemate.game.api.hybrid.location.navigation.cognizant.RegionPath;
import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.hybrid.region.GroundItems;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.tree.LeafTask;
/**
* NOTES:
*
*/
public class CollectTraps extends LeafTask {
Settings setting = new Settings();
@Override
public void execute() {
if (setting.gettingDebugBot()) {
System.out.println("CollectTraps.java: started");
}
setting.setBotStatus("Bot status: Collecting traps");
int oldInventoryCountNonactive = Inventory.getQuantity("Magic box");
int oldInventoryCountActive = Inventory.getQuantity("Imp-in-a-box(2)");
GameObject magicBox = GameObjects.newQuery().names("Magic box").actions("Retrieve").results().first();
GroundItem magicBoxDeactivated = GroundItems.newQuery().names("Magic box").actions("Take", "Activate").results().first();
GameObject magicBoxFailed = GameObjects.newQuery().names("Magic box failed").actions("Deactivate").results().first();
if (magicBox != null && magicBox.hover()) {
if (magicBox.interact("Retrieve")) {
Execution.delayUntil(()-> oldInventoryCountActive < Inventory.getQuantity("Imp-in-a-box(2)"), 2500, 3500);
if (oldInventoryCountActive < Inventory.getQuantity("Imp-in-a-box(2)")) {
Coordinate destination = magicBox.getPosition();
setting.deleteTrap();
setting.removeTrapLocation(destination);
setting.increaseImpCount();
if(Players.getLocal().getPosition() == destination) {
placeTrap();
}
else {
walkToBoxCoordinate(destination);
Execution.delay(1000, 2000);
if(Players.getLocal().getPosition() == destination) {
placeTrap();
}
}
return;
}
}
}
if (magicBoxDeactivated != null && magicBoxDeactivated.hover()) {
if (magicBoxDeactivated.interact("Activate")) {
Coordinate destinationDeactivated = magicBoxDeactivated.getPosition();
Execution.delay(2500, 3500);
return;
}
}
if (magicBoxFailed != null && magicBoxFailed.hover()) {
if (magicBoxFailed.interact("Deactivate")) {
Execution.delay(2500, 3500);
if (oldInventoryCountNonactive < Inventory.getQuantity("Magic box")) {
Coordinate destinationDeactivated = magicBoxFailed.getPosition();
setting.deleteTrap();
setting.removeTrapLocation(destinationDeactivated);
if(Players.getLocal().getPosition() == destinationDeactivated) {
placeTrap();
}
else {
walkToBoxCoordinate(destinationDeactivated);
Execution.delay(1000, 2000);
if(Players.getLocal().getPosition() == destinationDeactivated) {
placeTrap();
}
}
}
}
}
}
public void placeTrap() {
SpriteItem magicBoxInventory = Inventory.getItems("Magic box").first();
if(setting.getTrapCount() < setting.getMaxTraps()) {
if (!checkIfStandingOnTrap()) {
if (magicBoxInventory != null && magicBoxInventory.hover()) {
if (magicBoxInventory.interact("Activate")) {
setting.addTrap();
Execution.delay(3500, 4500);
}
}
}
}
}
public boolean checkIfStandingOnTrap() {
GameObject magicBox = GameObjects.newQuery().names("Magic box").on(Players.getLocal().getPosition()).actions("Retrieve").results().first();
GroundItem magicBoxDeactivated = GroundItems.newQuery().names("Magic box").on(Players.getLocal().getPosition()).actions("Take", "Activate").results().first();
GameObject magicBoxFailed = GameObjects.newQuery().names("Magic box failed").on(Players.getLocal().getPosition()).actions("Deactivate").results().first();
GameObject magicBoxPending = GameObjects.newQuery().names("Magic box").on(Players.getLocal().getPosition()).actions("Deactivate", "Investigate").results().first();
if (magicBox != null || magicBoxDeactivated != null || magicBoxFailed != null || magicBoxPending != null) {
System.out.println("Standing on magic box :)");
final Coordinate stepToCoord = Players.getLocal().getPosition().derive(0, 1);
BresenhamPath bresPath = BresenhamPath.buildTo(stepToCoord);
if (bresPath != null) {
bresPath.step();
return true;
} else {
getLogger().warn("bresPath was null in checkifStandingOnTrap");
return true;
}
}
return false;
}
public boolean walkToBoxCoordinate(Coordinate trapCoordinate) {
RegionPath regionPath = RegionPath.buildTo(trapCoordinate);
if(regionPath != null){
regionPath.step();
Execution.delay(3000, 4000);
return true;
} else {
getLogger().warn("regionPath was null in Walk");
}
Execution.delay(200, 500);
return false;
}
}