-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCannonBallSmither.java
More file actions
184 lines (170 loc) · 7.5 KB
/
Copy pathCannonBallSmither.java
File metadata and controls
184 lines (170 loc) · 7.5 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
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
package main;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.bank.BankLocation;
import org.dreambot.api.methods.map.Area;
import org.dreambot.api.methods.map.Tile;
import org.dreambot.api.methods.skills.Skill;
import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.script.listener.PaintListener;
import org.dreambot.api.wrappers.widgets.WidgetChild;
import java.awt.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
@ScriptManifest(author = "skengrat", category = Category.SMITHING, name = "CannonBallSmither", version = 1.0)
public class CannonBallSmither extends AbstractScript implements PaintListener {
private final Area Edgeville_BankArea = new Area(3091,3488,3098,3499,0);
private final Tile Edgeville_BankTile = new Tile(3096,3494,0);
private final Area Furnace_Area = new Area(3105,3497,3110,3501,0);
private final Tile Furnace_Tile = new Tile(3109,3499,0);
private int beginning;
private int smithing_level;
private long timeBegan;
private BufferedWriter writer;
@Override
public void onStart(){
try {
writer = new BufferedWriter(new FileWriter("error_report.txt"));
}catch(Exception e){
e.printStackTrace();
}
print("Started CannonBallSmither 1.00!");
beginning = getSkills().getExperience(Skill.SMITHING);
timeBegan = System.currentTimeMillis();
smithing_level = getSkills().getRealLevel(Skill.SMITHING);
}
@Override
public int onLoop(){
print("Loop");
if ((getInventory().contains(i -> i.getName().contains("Steel bar")))&&(getInventory().contains(i -> i.getName().contains("Ammo mould")))){
smelt();
}else{
bank();
}
return 100;
}
@Override
public void onExit(){
try {
writer.close();
}catch(Exception e) {
e.printStackTrace();
}
}
private void bank(){
print("Trying to bank");
if (Edgeville_BankArea.contains(getLocalPlayer())) { //if at bank
print("At the bank");
if (getBank().isOpen()) {
if ((!getInventory().onlyContains("Ammo mould"))&&(!getInventory().isEmpty())) {
sleepUntil(() -> getBank().depositAllExcept("Ammo mould"), 1000);
} else if (!getInventory().contains("Ammo mould")){
if (getBank().contains("Ammo mould")) {
getBank().withdraw("Ammo mould", 1);
sleepUntil(() -> !getInventory().contains(i -> i.getName().contains("Ammo mould")),1000);
}else{
print("No ammo mould. Exiting script.");
stop();
}
} else if (!getInventory().contains("Steel bar")){
System.out.println("don't have steel bars in inventory");
if (getBank().contains("Steel bar")) {
getBank().withdrawAll("Steel bar");
sleepUntil(() -> !getInventory().contains(i -> i.getName().contains("Steel bar")),1000);
}else{
print("Out of steel bars. Exiting script.");
stop();
}
}
if (sleepUntil(() -> ((getInventory().contains(i -> i.getName().contains("Steel bar")))&&(getInventory().contains(i -> i.getName().contains("Ammo mould")))), 1000)){
if (getBank().close()){
sleepUntil(() -> !getBank().isOpen(),3000);
}
}
} else{
open_bank(Edgeville_BankTile);
}
}else if (Furnace_Area.contains(getLocalPlayer())){
print("At the furnace");
walk(Edgeville_BankTile);
}else {
print("Somewhere else");
walk(Edgeville_BankTile);
}
}
private void smelt(){
print("Trying to smelt");
smithing_level = getSkills().getRealLevel(Skill.SMITHING);
if (Edgeville_BankArea.contains(getLocalPlayer())) { //if at bank
print("At the bank");
walk(Furnace_Tile);
}else if (Furnace_Area.contains(getLocalPlayer())) { //if near stairs when upstairs
print("At the furnace");
if (getInventory().isItemSelected()){
print(getInventory().getSelectedItemName());
}
if ((getInventory().isItemSelected()) && (getInventory().getSelectedItemName().contains("Steel bar"))){
print("selected steel bar");
getGameObjects().closest("Furnace").interact();
sleepUntil(()-> (getWidgets().getWidgetChild(270,14) != null && getWidgets().getWidgetChild(270,14).isVisible()), 1000);
WidgetChild makeAllWidg = getWidgets().getWidgetChild(270,14);
if (makeAllWidg != null && makeAllWidg.isVisible()){
print("Widget visible");
if (makeAllWidg.interact()){
sleepUntil(()->(!getInventory().contains("Steel bar") || (getSkills().getRealLevel(Skill.SMITHING) != smithing_level)),161000);
}
}else {
random_camera();
getWalking().walk(Furnace_Tile);
}
} else if (getInventory().isItemSelected()){
print("Selected something else.");
getInventory().deselect();
sleepUntil(() ->!getInventory().isItemSelected(),1000);
}else{
print("Selecting the steel bar");
getInventory().interact("Steel bar","Use");
sleepUntil(() -> (getInventory().isItemSelected() && getInventory().getSelectedItemName().contains("Steel bar")),1000);
}
}else {
print("Somewhere else");
walk(Furnace_Tile);
}
}
private void random_camera(){
getCamera().rotateTo(Calculations.random(0,2048), Calculations.random(getClient().getLowestPitch(), 383));
}
//open the bank if you are near it at the specified tile
private void open_bank(Tile tile){
getBank().open(BankLocation.EDGEVILLE);
if (!sleepUntil(() -> getBank().isOpen(), 2000)) {
getWalking().walk(tile);
sleep(Calculations.random(900,1500));
}
}
//walk to tile
private void walk(Tile tile){
if (getWalking().walk(tile)) {
sleep(Calculations.random(800, 1000));
sleepUntil( () -> !getLocalPlayer().isMoving() || getLocalPlayer().distance(
getClient().getDestination()) < Calculations.random(
1, 5) , Calculations.random(3000, 5000));
}
}
private void print(String message){
log(message);
try {
writer.write(message +"\n");
}catch(Exception e){
e.printStackTrace();
}
}
@Override
public void onPaint(Graphics g) {
//g.drawString("isHealthBarVisible: " + String.valueOf(getLocalPlayer().isHealthBarVisible()), 20, 110);
//g.drawString("State: " + String.valueOf(state), 20, 130);
// g.drawString("Health timer: " + String.valueOf(System.currentTimeMillis() - health_timer), 20, 150);
g.drawString("Smithing XP gained: " + String.valueOf(getSkills().getExperience(Skill.SMITHING) - beginning), 20, 40);
}
}