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

Commit 81e974a

Browse files
ExplvExplv
authored andcommitted
Version 2.0.0
Major refactoring to Grand Exchange code, and some bug fixes. - Refactored monolithic GrandExchangeHelper into separate classes. - Made CachedWidget thread safe, to allow for static instances for better caching. - Added widget filters to util/widget/filters package. - Fixed price retrieval from OSRS API. - Removed ScriptManifest from CustomBreakManager, this was causing SDN script to not start.
1 parent 9745749 commit 81e974a

35 files changed

+709
-457
lines changed

AIO/src/org/aio/activities/grand_exchange/GEActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import org.aio.activities.activity.Activity;
44
import org.osbot.rs07.api.GrandExchange;
5+
import org.osbot.rs07.api.map.Area;
56

67
public abstract class GEActivity extends Activity {
78

8-
protected GrandExchange.Box box;
9+
protected static final Area GRAND_EXCHANGE = new Area(3154, 3479, 3174, 3500);
910

10-
public GEActivity() {
11+
GrandExchange.Box box;
12+
13+
GEActivity() {
1114
super(null);
1215
}
1316

AIO/src/org/aio/activities/grand_exchange/GEBuyActivity.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
11
package org.aio.activities.grand_exchange;
22

3-
import org.aio.util.Sleep;
3+
import org.aio.activities.banking.ItemReqBanking;
4+
import org.aio.activities.grand_exchange.event.GrandExchangeBuyEvent;
5+
import org.aio.util.item_requirement.ItemReq;
46

57
public class GEBuyActivity extends GEActivity {
68

7-
private GrandExchangeHelper exchangeHelper;
89
private final GEItem geItem;
10+
private final ItemReq coinReq;
11+
12+
private ItemReqBanking itemReqBanking;
913

1014
public GEBuyActivity(final GEItem geItem) {
1115
this.geItem = geItem;
16+
17+
int coinsRequired = geItem.getPrice() * geItem.getQuantity();
18+
19+
coinReq = new ItemReq(
20+
"Coins",
21+
coinsRequired,
22+
coinsRequired
23+
).setStackable();
24+
25+
itemReqBanking = new ItemReqBanking(coinReq);
1226
}
1327

1428
@Override
1529
public void onStart() {
16-
this.exchangeHelper = new GrandExchangeHelper();
17-
this.exchangeHelper.exchangeContext(getBot());
30+
itemReqBanking.exchangeContext(getBot());
1831
}
1932

2033
@Override
2134
public void runActivity() throws InterruptedException {
2235
if (box != null) {
2336
return;
24-
} else if(!exchangeHelper.playerIsAtGE()){
25-
exchangeHelper.walkToGE();
26-
} else if(getInventory().getAmount("Coins") < (geItem.getPrice() * geItem.getQuantity())) {
27-
getCoins();
28-
} else {
29-
box = exchangeHelper.createBuyOffer(geItem.getName(), geItem.getPrice(), geItem.getQuantity());
3037
}
31-
}
3238

33-
private void getCoins() throws InterruptedException {
34-
if (!getBank().isOpen()) {
35-
if (getBank().open()) {
36-
Sleep.sleepUntil(() -> getBank().isOpen(), 5000);
39+
if(!GRAND_EXCHANGE.contains(myPosition())){
40+
getWalking().webWalk(GRAND_EXCHANGE);
41+
} else if(!coinReq.hasRequirement(getInventory())) {
42+
itemReqBanking.run();
43+
if (itemReqBanking.hasFailed()) {
44+
setFailed();
45+
}
46+
} else {
47+
GrandExchangeBuyEvent buyEvent = new GrandExchangeBuyEvent(
48+
geItem.getName(),
49+
geItem.getPrice(),
50+
geItem.getQuantity()
51+
);
52+
execute(buyEvent);
53+
if (buyEvent.hasFailed()) {
54+
setFailed();
55+
} else {
56+
box = buyEvent.getBoxUsed();
3757
}
38-
} else if (!getInventory().isEmpty()) {
39-
getBank().depositAll();
40-
} else if (getBank().getAmount("Coins") + getInventory().getAmount("Coins") >= (geItem.getPrice() * geItem.getQuantity())) {
41-
withdrawRemaining("Coins", (geItem.getPrice() * geItem.getQuantity()));
42-
} else{
43-
setFailed();
4458
}
4559
}
4660

47-
private boolean withdrawRemaining(String itemName, int quantity) {
48-
long invAmount = getInventory().getAmount(itemName);
49-
return invAmount < quantity && getBank().withdraw(itemName, quantity - (int) invAmount);
50-
}
51-
5261
@Override
5362
public String toString() {
5463
return "Buying";

AIO/src/org/aio/activities/grand_exchange/GESellActivity.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import org.aio.activities.banking.DepositAllBanking;
44
import org.aio.activities.banking.ItemReqBanking;
5+
import org.aio.activities.grand_exchange.event.GrandExchangeSellEvent;
56
import org.aio.util.item_requirement.ItemReq;
67

78
public class GESellActivity extends GEActivity {
89

9-
private GrandExchangeHelper exchangeHelper;
1010
private final GEItem geItem;
1111
private DepositAllBanking depositAllBanking;
1212
private ItemReqBanking itemReqBanking;
@@ -20,8 +20,6 @@ public GESellActivity(final GEItem geItem) {
2020

2121
@Override
2222
public void onStart() {
23-
this.exchangeHelper = new GrandExchangeHelper();
24-
this.exchangeHelper.exchangeContext(getBot());
2523
itemReqBanking.exchangeContext(getBot());
2624
depositAllBanking.exchangeContext(getBot());
2725
}
@@ -30,8 +28,10 @@ public void onStart() {
3028
public void runActivity() throws InterruptedException {
3129
if (box != null) {
3230
return;
33-
} else if (!exchangeHelper.playerIsAtGE()) {
34-
exchangeHelper.walkToGE();
31+
}
32+
33+
if (!GRAND_EXCHANGE.contains(myPosition())) {
34+
getWalking().webWalk(GRAND_EXCHANGE);
3535
} else if (!checkedBank && getInventory().getAmount(geItem.getName()) < geItem.getQuantity()) {
3636
if (!getInventory().isEmpty()) {
3737
depositAllBanking.run();
@@ -44,7 +44,11 @@ public void runActivity() throws InterruptedException {
4444
}
4545
}
4646
} else {
47-
box = exchangeHelper.createSellOffer(geItem.getName(), geItem.getPrice(), geItem.getQuantity());
47+
GrandExchangeSellEvent sellEvent = new GrandExchangeSellEvent(
48+
geItem.getName(), geItem.getPrice(), geItem.getQuantity()
49+
);
50+
execute(sellEvent);
51+
box = sellEvent.getBoxUsed();
4852
}
4953
}
5054

0 commit comments

Comments
 (0)