Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit e4cccc8

Browse files
author
Explv
committed
Remove Musa Point fishing workaround.
Introduce deposit box functionality to banking. v3.2.0
1 parent 00d489e commit e4cccc8

File tree

17 files changed

+190
-116
lines changed

17 files changed

+190
-116
lines changed

src/main/java/activities/banking/Bank.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public enum Bank {
7777

7878
public Location location;
7979

80+
public static Area[] AREAS = Arrays.stream(Bank.values()).map(bank -> bank.location.getArea()).toArray(Area[]::new);
81+
8082
Bank(final Location location) {
8183
this.location = location;
8284
}
@@ -88,10 +90,6 @@ public static boolean inAnyBank(final Position position) {
8890
return false;
8991
}
9092

91-
public static Area[] getAreas() {
92-
return Arrays.stream(Bank.values()).map(bank -> bank.location.getArea()).toArray(Area[]::new);
93-
}
94-
9593
@Override
9694
public String toString() {
9795
return location.toString();

src/main/java/activities/banking/Banking.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,97 @@
44
import util.Executable;
55
import util.Sleep;
66

7+
import java.util.stream.Stream;
8+
79
public abstract class Banking extends Executable {
810

9-
protected static final Area[] bankAreas = Bank.getAreas();
11+
private static final Area[] ALL_BANK_AND_DEPOSIT_BOX_AREAS = Stream.concat(Stream.of(Bank.AREAS), Stream.of(DepositBox.AREAS)).toArray(Area[]::new);
12+
13+
private final boolean useDepositBoxes;
14+
15+
protected enum BankType {
16+
BANK,
17+
DEPOSIT_BOX
18+
}
19+
20+
private BankType currentBankType;
1021
public boolean succeeded;
1122

23+
public Banking() {
24+
this.useDepositBoxes = false;
25+
}
26+
27+
public Banking(final boolean useDepositBoxes) {
28+
this.useDepositBoxes = useDepositBoxes;
29+
}
30+
1231
@Override
1332
public void run() throws InterruptedException {
14-
if (!Bank.inAnyBank(myPosition())) {
15-
getWalking().webWalk(bankAreas);
16-
} else if (!getBank().isOpen()) {
17-
openBank();
33+
if (!playerInBank()) {
34+
walkToBank();
35+
} else if (!isBankOpen()) {
36+
currentBankType = openBank();
1837
} else {
19-
succeeded = bank();
38+
succeeded = bank(currentBankType);
39+
}
40+
}
41+
42+
private boolean playerInBank() {
43+
if (useDepositBoxes) {
44+
return Stream.of(ALL_BANK_AND_DEPOSIT_BOX_AREAS).anyMatch(area -> area.contains(myPosition()));
2045
}
46+
return Stream.of(Bank.AREAS).anyMatch(area -> area.contains(myPosition()));
2147
}
2248

23-
void openBank() throws InterruptedException {
49+
private boolean walkToBank() {
50+
if (useDepositBoxes) {
51+
return getWalking().webWalk(ALL_BANK_AND_DEPOSIT_BOX_AREAS);
52+
}
53+
return getWalking().webWalk(Bank.AREAS);
54+
}
55+
56+
boolean isBankOpen() {
57+
if (useDepositBoxes) {
58+
return getDepositBox().isOpen();
59+
}
60+
return getBank().isOpen();
61+
}
62+
63+
BankType openBank() throws InterruptedException {
64+
if (useDepositBoxes && getDepositBox() != null) {
65+
if (getDepositBox().open()) {
66+
Sleep.sleepUntil(() -> getDepositBox().isOpen(), 5000);
67+
}
68+
return BankType.DEPOSIT_BOX;
69+
}
70+
2471
if (getBank().open()) {
2572
Sleep.sleepUntil(() -> getBank().isOpen(), 5000);
2673
}
74+
return BankType.BANK;
2775
}
2876

2977
/**
3078
* Execute banking operation
3179
*
3280
* @return whether the operation was a success or not
3381
*/
34-
protected abstract boolean bank();
82+
protected abstract boolean bank(final BankType currentBankType);
3583

3684
@Override
3785
public void onEnd() {
38-
if (getBank().isOpen()) {
39-
closeBank();
40-
}
86+
closeBank();
4187
}
4288

4389
private void closeBank() {
44-
if (getBank().close()) {
90+
if (currentBankType == BankType.DEPOSIT_BOX) {
91+
if (getDepositBox().isOpen() && getDepositBox().close()) {
92+
Sleep.sleepUntil(() -> !getDepositBox().isOpen(), 2500);
93+
}
94+
return;
95+
}
96+
97+
if (getBank().isOpen() && getBank().close()) {
4598
Sleep.sleepUntil(() -> !getBank().isOpen(), 2500);
4699
}
47100
}
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
package activities.banking;
22

3+
import util.item_requirement.ItemReq;
4+
5+
import java.util.stream.Stream;
6+
37
public class DepositAllBanking extends Banking {
48

59
private String[] exceptItems;
610

711
public DepositAllBanking(final String... exceptItems) {
12+
super(true);
813
this.exceptItems = exceptItems;
914
}
1015

16+
public DepositAllBanking() {
17+
this(new String[]{});
18+
}
19+
20+
public DepositAllBanking(final ItemReq... exceptItems) {
21+
this(Stream.of(exceptItems).map(ItemReq::getName).toArray(String[]::new));
22+
}
23+
1124
public void setExceptItems(final String... exceptItems) {
1225
this.exceptItems = exceptItems;
1326
}
1427

1528
@Override
16-
protected boolean bank() {
29+
protected boolean bank(final BankType currentBankType) {
1730
if (exceptItems == null) {
18-
return getBank().depositAll();
31+
if (currentBankType == BankType.DEPOSIT_BOX) {
32+
return getDepositBox().depositAll();
33+
} else {
34+
return getBank().depositAll();
35+
}
36+
}
37+
38+
if (currentBankType == BankType.DEPOSIT_BOX) {
39+
return getDepositBox().depositAllExcept(exceptItems);
40+
} else {
41+
return getBank().depositAllExcept(exceptItems);
1942
}
20-
return getBank().depositAllExcept(exceptItems);
2143
}
2244
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package activities.banking;
2+
3+
import org.osbot.rs07.api.map.Area;
4+
import org.osbot.rs07.api.map.Position;
5+
import util.Location;
6+
7+
import java.util.Arrays;
8+
9+
public enum DepositBox {
10+
PORT_SARIM(new Location("Port Sarim", new Area(3044, 3237, 3052, 3234)));
11+
12+
public Location location;
13+
14+
public static Area[] AREAS = Arrays.stream(DepositBox.values()).map(depositBox -> depositBox.location.getArea()).toArray(Area[]::new);
15+
16+
DepositBox(final Location location) {
17+
this.location = location;
18+
}
19+
20+
public static boolean atAnyDepositBox(final Position position) {
21+
for (DepositBox depositBox : DepositBox.values()) {
22+
if (depositBox.location.getArea().contains(position)) return true;
23+
}
24+
return false;
25+
}
26+
27+
28+
@Override
29+
public String toString() {
30+
return location.toString();
31+
}
32+
33+
34+
}

src/main/java/activities/banking/ItemReqBanking.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public ItemReqBanking(final ItemReq... itemReqs) {
2525
@Override
2626
public void run() throws InterruptedException {
2727
if (!Bank.inAnyBank(myPosition())) {
28-
getWalking().webWalk(bankAreas);
28+
getWalking().webWalk(Bank.AREAS);
2929
} else {
30-
bank();
30+
// We can never withdraw item requirements from a deposit box
31+
// so we hardcode to BankType.BANK
32+
bank(BankType.BANK);
3133
}
3234
}
3335

@@ -82,7 +84,7 @@ private void loadItemReqTargetAmounts() {
8284
}
8385

8486
@Override
85-
protected boolean bank() {
87+
protected boolean bank(final BankType currentBankType) {
8688
reqTargetAmountMap.forEach((itemRequirement, integer) -> {
8789
if (itemRequirement != null && integer != null) {
8890
log(itemRequirement.getName() + ": " + integer);

src/main/java/activities/banking/ToolUpgradeBanking.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public boolean toolUpgradeAvailable() {
4343
}
4444

4545
@Override
46-
protected boolean bank() {
46+
protected boolean bank(final BankType currentBankType) {
4747
if (toolsInBank.isEmpty()) {
4848
for (T tool : toolClass.getEnumConstants()) {
4949
if (getBank().contains(tool.getName())) {

src/main/java/activities/money_making/flax_picking/FlaxPickingActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Activity copy() {
7979
private class FlaxBank extends Banking {
8080

8181
@Override
82-
public boolean bank() {
82+
public boolean bank(final BankType currentBankType) {
8383
if (!getInventory().isEmpty()) {
8484
getBank().depositAll();
8585
} else if (!getEquipment().isEmpty()) {

src/main/java/activities/quests/RuneMysteries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void runActivity() throws InterruptedException {
4747
}
4848
} else getBank().depositAllExcept("Air talisman", "Research package");
4949
} else {
50-
getWalking().webWalk(Bank.getAreas());
50+
getWalking().webWalk(Bank.AREAS);
5151
}
5252
} else {
5353

src/main/java/activities/skills/agility/AgilityActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public AgilityActivity copy() {
179179

180180
private class AgilityBank extends Banking {
181181
@Override
182-
public boolean bank() {
182+
public boolean bank(final BankType currentBankType) {
183183
getBank().depositAll();
184184

185185
return true;

src/main/java/activities/skills/crafting/CraftingActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void runActivity() throws InterruptedException {
5252
} else if (getBank() != null && getBank().isOpen()) {
5353
getBank().close();
5454
} else if (location.getArea() == null && !Bank.inAnyBank(myPosition())) {
55-
getWalking().webWalk(Bank.getAreas());
55+
getWalking().webWalk(Bank.AREAS);
5656
} else if (location.getArea() != null && !location.getArea().contains(myPosition())) {
5757
getWalking().webWalk(location.getArea());
5858
} else if (makeAllInterface.isMakeAllScreenOpen()) {

0 commit comments

Comments
 (0)