Skip to content

Commit eafbf22

Browse files
committed
add general woodcutting and improve alert system
1 parent 0ed537c commit eafbf22

17 files changed

Lines changed: 250 additions & 149 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://user-images.githubusercontent.com/115373370/195444530-a0a17efc-7d8c-4574
1010
* Fishing & Cooking - Trout & Salmon - Barbarian Village
1111

1212
# Features
13-
Configuration options:
13+
Configuration options:
1414
![Settings configuration](/img/settings.png "Copilot configuration options.")
1515

1616

old/CodeHolder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dev.jort.copilot.old;
2+
3+
public class CodeHolder {
4+
private final String[] illegalKeywords = {"STUMP", "DISEASED", "DEAD", "BIRDHOUSE",
5+
"BAG", "STRONG", "BENCH", "CAPE", "CHAIR", "DECORATION", "DRAWER", "FEEDER",
6+
"HOUSE", "OUTFIT", "NOCKS", "WARDROBE", "TROPHY", "TABLE", "CHEST", "STAND",
7+
"BRANCH", "DOOR", "PATCH", "CROSSBOW"};
8+
}
Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.jort.copilot;
22

3-
import net.runelite.api.SoundEffectID;
43
import net.runelite.api.SoundEffectVolume;
54
import net.runelite.client.config.*;
65

@@ -11,12 +10,11 @@ public interface CopilotConfig extends Config {
1110

1211
@ConfigSection(
1312
name = "Settings",
14-
description = "Set which activity you want assistance with. Only one selected item works.",
13+
description = "Configure settings which apply to all helpers.",
1514
position = 0
1615
)
1716
String settingsSection = "Settings";
1817

19-
2018
@Range(
2119
max = SoundEffectVolume.HIGH
2220
)
@@ -32,13 +30,24 @@ default int alertVolume() {
3230
}
3331

3432
@ConfigItem(
35-
keyName = "soundId",
33+
keyName = "mainSoundId",
3634
name = "Alert sound ID",
3735
description = "Configures the sound to play for alerts. For inspiration: search 'sound id osrs'.",
3836
section = settingsSection,
3937
position = 2
4038
)
41-
default int soundId() {
39+
default int mainSoundId() {
40+
return 3929;
41+
}
42+
43+
@ConfigItem(
44+
keyName = "alternativeSoundId",
45+
name = "Alt alert sound ID",
46+
description = "Configures the sound to play when the inventory is full. Set to 0 to disable.",
47+
section = settingsSection,
48+
position = 3
49+
)
50+
default int alternativeSoundId() {
4251
return 1959;
4352
}
4453

@@ -47,7 +56,7 @@ default int soundId() {
4756
name = "Alert delay",
4857
description = "Configure after how many milliseconds of inactivity the alert go off.",
4958
section = settingsSection,
50-
position = 3
59+
position = 4
5160
)
5261
default int alertDelayMs() {
5362
return 1000;
@@ -61,7 +70,7 @@ default int alertDelayMs() {
6170
position = 4
6271
)
6372
default int amountOfSoundAlerts() {
64-
return 3;
73+
return 5;
6574
}
6675

6776

@@ -71,7 +80,7 @@ default int amountOfSoundAlerts() {
7180
name = "Notification color",
7281
description = "Set the notification overlay color",
7382
section = settingsSection,
74-
position = 5
83+
position = 6
7584
)
7685
default Color overlayColor() {
7786
return new Color(1.0f, 0.0f, 0.0f, 0.1f);
@@ -83,7 +92,7 @@ default Color overlayColor() {
8392
name = "Highlight color",
8493
description = "Set the color of the highlight for items to click.",
8594
section = settingsSection,
86-
position = 6
95+
position = 7
8796
)
8897
default Color highlightColor() {
8998
return new Color(0.0f, 1.0f, 1.0f, 0.2f);
@@ -92,41 +101,30 @@ default Color highlightColor() {
92101
@ConfigSection(
93102
name = "Activities",
94103
description = "Set which activity you want assistance with. Only one selected item works.",
95-
position = 7
104+
position = 8
96105
)
97106
String activitiesSection = "Activities";
98107

99108
@ConfigItem(
100-
keyName = "willowsDraynor",
101-
name = "Willows @ Draynor bank",
102-
description = "Chop down and bank willows next to the bank in Draynor Village.",
109+
keyName = "woodcuttingGeneral",
110+
name = "Woodcutting",
111+
description = "Highlights trees, logs and banks.",
103112
section = activitiesSection,
104-
position = 8
113+
position = 9
105114

106115
)
107-
default boolean willowsDraynor() {
116+
default boolean woodcutting() {
108117
return false;
109118
}
110119

111120
@ConfigItem(
112121
keyName = "fishingBarbarianVillage",
113-
name = "Fishing & Cooking @ Barbarians",
122+
name = "Fishing and Cooking at Barbarians",
114123
description = "Fish trout and salmon at Barbarian Village, cook it and then drop it.",
115124
section = activitiesSection,
116-
position = 9
117-
)
118-
default boolean fishingBarbarian() {
119-
return false;
120-
}
121-
122-
@ConfigItem(
123-
keyName = "yewsWoodcuttingGuild",
124-
name = "Yews @ Woodcutting Guild",
125-
description = "Chop down and bank yew trees at the Woodcutting Guild",
126-
section = activitiesSection,
127125
position = 10
128126
)
129-
default boolean yewsGuild() {
127+
default boolean fishingBarbarian() {
130128
return false;
131129
}
132130
}

src/main/java/dev/jort/copilot/CopilotPlugin.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import dev.jort.copilot.scripts.FishingBarbarian;
77
import dev.jort.copilot.other.Script;
88
import dev.jort.copilot.scripts.WillowsDraynor;
9+
import dev.jort.copilot.scripts.Woodcutting;
910
import dev.jort.copilot.scripts.YewsWoodcuttingGuild;
1011
import lombok.extern.slf4j.Slf4j;
1112
import net.runelite.api.ChatMessageType;
1213
import net.runelite.api.Client;
14+
import net.runelite.api.GameState;
1315
import net.runelite.api.InventoryID;
1416
import net.runelite.api.events.*;
1517
import net.runelite.client.callback.ClientThread;
@@ -25,6 +27,7 @@
2527
import javax.inject.Inject;
2628
import java.time.temporal.ChronoUnit;
2729
import java.util.ArrayList;
30+
import java.util.Arrays;
2831
import java.util.List;
2932

3033
@Slf4j
@@ -82,6 +85,8 @@ public class CopilotPlugin extends Plugin {
8285
FishingBarbarian fishingBarbarian;
8386
@Inject
8487
YewsWoodcuttingGuild yewsWoodcuttingGuild;
88+
@Inject
89+
Woodcutting woodcutting;
8590

8691
Script runningScript = null;
8792

@@ -106,8 +111,9 @@ protected void startUp() throws Exception {
106111
}
107112

108113
//initialize scripts which require arguments
109-
yewsWoodcuttingGuild.initialize(ids.BANK_CHEST_IDS, new int[]{ids.YEW_LOGS}, ids.YEW_TREE_IDS);
110-
willowsDraynor.initialize(new int[]{ids.BANK_BOOTH}, new int[]{ids.WILLOW_LOGS}, ids.WILLOW_TREE_IDS);
114+
// yewsWoodcuttingGuild.initialize(ids.BANK_CHEST_IDS, new int[]{ids.YEW_LOGS}, ids.YEW_TREE_IDS);
115+
// willowsDraynor.initialize(new int[]{ids.BANK_BOOTH}, new int[]{ids.WILLOW_LOGS}, ids.WILLOW_TREE_IDS);
116+
woodcutting.initialize();
111117
}
112118

113119
@Override
@@ -185,15 +191,15 @@ public void setOverlaysEnabled(boolean enable) {
185191
@Subscribe
186192
public void onGameTick(GameTick event) {
187193
tracker.onGameTick(event);
188-
if (config.willowsDraynor()) {
189-
willowsDraynor.loop();
190-
runningScript = willowsDraynor;
194+
if (!client.getGameState().equals(GameState.LOGGED_IN)) {
195+
return;
196+
}
197+
if (config.woodcutting()) {
198+
woodcutting.loop();
199+
runningScript = woodcutting;
191200
} else if (config.fishingBarbarian()) {
192201
fishingBarbarian.loop();
193202
runningScript = fishingBarbarian;
194-
} else if (config.yewsGuild()) {
195-
yewsWoodcuttingGuild.loop();
196-
runningScript = yewsWoodcuttingGuild;
197203
} else {
198204
setOverlaysEnabled(false);
199205
}
@@ -202,6 +208,7 @@ public void onGameTick(GameTick event) {
202208
@Subscribe
203209
public void onMenuOptionClicked(MenuOptionClicked event) {
204210
tracker.onMenuOptionClicked(event);
211+
woodcutting.onMenuOptionClicked(event);
205212
}
206213

207214
@Subscribe

src/main/java/dev/jort/copilot/helpers/Alert.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class Alert {
1717
@Inject
1818
Client client;
1919

20+
@Inject
21+
Inventory inventory;
22+
2023
@Inject
2124
CopilotConfig config;
2225

@@ -30,27 +33,28 @@ public class Alert {
3033
EntityOverlay entityOverlay;
3134

3235
int soundAlertsPlayed = 0;
33-
boolean previousAlertNeeded = false;
36+
boolean previousInteractionNeeded = false;
3437
long alertStartTime = -1;
3538

3639

37-
public void handleAlert(boolean alertNeeded) {
40+
public void handleAlert(boolean interactionNeeded) {
3841
//if this is the first time alerting, needed for the alert delay
39-
if (!previousAlertNeeded) {
42+
if (!previousInteractionNeeded) {
4043
alertStartTime = System.currentTimeMillis();
4144
}
42-
previousAlertNeeded = alertNeeded;
45+
previousInteractionNeeded = interactionNeeded;
46+
4347

4448
//always disable visual overlay when no alert is needed
45-
if (!alertNeeded) {
49+
if (!interactionNeeded) {
4650
notificationOverlay.disable();
4751
soundAlertsPlayed = 0;
4852
alertStartTime = -2;
4953
return;
5054
}
5155

52-
//ignore if we are awaiting the alert delay
53-
if (System.currentTimeMillis() - alertStartTime < config.alertDelayMs()) {
56+
//ignore if interacted recently
57+
if (Math.max(client.getMouseLastPressedMillis(), alertStartTime) + config.alertDelayMs() > System.currentTimeMillis()) {
5458
return;
5559
}
5660

@@ -63,15 +67,27 @@ public void handleAlert(boolean alertNeeded) {
6367
}
6468

6569
//play sound alert
66-
playAlertSound();
70+
if (inventory.isFull()) {
71+
playAlternativeAlertSound();
72+
} else {
73+
playAlertSound();
74+
}
6775
soundAlertsPlayed++;
6876
}
6977

7078
public void playAlertSound() {
71-
playSound(config.soundId());
79+
playSound(config.mainSoundId());
80+
}
81+
82+
public void playAlternativeAlertSound() {
83+
if (config.alternativeSoundId() == 0) { //set to 0 disables it
84+
playAlertSound();
85+
return;
86+
}
87+
playSound(config.alternativeSoundId());
7288
}
7389

74-
public void playSound(int id){
90+
public void playSound(int id) {
7591
Preferences preferences = client.getPreferences();
7692
int previousVolume = preferences.getSoundEffectVolume();
7793
int volume = config.alertVolume();

src/main/java/dev/jort/copilot/helpers/GameObjects.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.runelite.api.Client;
55
import net.runelite.api.GameObject;
66
import net.runelite.api.GameState;
7+
import net.runelite.api.Perspective;
78
import net.runelite.api.coords.WorldPoint;
89
import net.runelite.api.events.GameObjectDespawned;
910
import net.runelite.api.events.GameObjectSpawned;
@@ -12,6 +13,7 @@
1213
import javax.inject.Inject;
1314
import javax.inject.Singleton;
1415
import java.util.ArrayList;
16+
import java.util.Arrays;
1517
import java.util.List;
1618
import java.util.function.Predicate;
1719

@@ -28,7 +30,17 @@ public void add(GameObject gameObject) {
2830
if (gameObjects.contains(gameObject)) {
2931
return;
3032
}
31-
gameObjects.add(gameObject);
33+
34+
String[] actions = client.getObjectDefinition(gameObject.getId()).getActions();
35+
36+
37+
for (String action : actions) {
38+
if (action != null) {
39+
//dont add gameobject which are not interactable, to prevent fake bank booths for example
40+
gameObjects.add(gameObject);
41+
return;
42+
}
43+
}
3244
}
3345

3446
public void remove(GameObject gameObject) {
@@ -39,6 +51,9 @@ public GameObject closest(int... ids) {
3951
if (gameObjects.isEmpty()) {
4052
return null;
4153
}
54+
if (ids == null) { // seems to happen at startup in render
55+
return null;
56+
}
4257
GameObject closest = null;
4358
WorldPoint myLocation = client.getLocalPlayer().getWorldLocation();
4459
for (GameObject gameObject : gameObjects) {
@@ -69,7 +84,7 @@ public void onGameObjectDespawned(GameObjectDespawned event) {
6984
}
7085

7186
public void onGameStateChanged(GameStateChanged gameStateChanged) {
72-
if(gameStateChanged.getGameState().equals(GameState.LOADING)){
87+
if (gameStateChanged.getGameState().equals(GameState.LOADING)) {
7388
gameObjects.clear();
7489
}
7590
}

0 commit comments

Comments
 (0)