Skip to content

Commit ca49a4e

Browse files
JortJort
authored andcommitted
work
1 parent 6c5a699 commit ca49a4e

10 files changed

Lines changed: 163 additions & 41 deletions

File tree

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

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class GiantsFoundryHelper {
6565
private static final int SPRITE_ID_GRINDSTONE = 4443;
6666
private static final int SPRITE_ID_POLISHING_WHEEL = 4444;
6767

68+
public static final int LAVA_POOL = 44631;
69+
public static final int WATERFALL = 44632;
70+
6871
public Heat getCurrentHeat() {
6972
int heat = getHeatAmount();
7073

@@ -110,38 +113,59 @@ public enum Activity {
110113
NONE
111114
}
112115

113-
public boolean isOperatingMachine(){
114-
return getOperatingMachine() != Activity.NONE;
116+
public boolean isOperatingMachine() {
117+
Activity activity = getActivity();
118+
if (activity == Activity.HAMMERING) {
119+
return true;
120+
}
121+
if (activity == Activity.POLISHING) {
122+
return true;
123+
}
124+
if (activity == Activity.GRINDING) {
125+
return true;
126+
}
127+
return false;
115128
}
116129

117-
public Activity getOperatingMachine() {
130+
public boolean isModifyingTemperature() {
131+
Activity activity = getActivity();
132+
if (activity == Activity.COOLING) {
133+
return true;
134+
}
135+
if (activity == Activity.HEATING) {
136+
return true;
137+
}
138+
return false;
139+
}
140+
141+
public Activity getActivity() {
118142
if (!tracker.isAnimating()) {
119143
return Activity.NONE;
120144
}
121145
int anim = tracker.getLastAnimationId();
122-
if (anim == 827){
146+
if (anim == 827) {
123147
return Activity.HEATING;
124148
}
125-
if(anim == 832){
149+
if (anim == 832) {
126150
return Activity.COOLING;
127151
}
128-
if(anim == 9455 || anim ==9453){
152+
if (anim == 9455 || anim == 9453) {
129153
return Activity.HAMMERING;
130154
}
131-
if(anim != 9454 && anim != 9452){
155+
if (anim != 9454 && anim != 9452) {
132156
return Activity.NONE;
133157
}
134158
GameObject polishWheel = gameObjects.closest(POLISHING_WHEEL);
135159
GameObject grindingWheel = gameObjects.closest(GRINDSTONE);
136-
if(polishWheel == null || grindingWheel== null){
160+
if (polishWheel == null || grindingWheel == null) {
137161
log.info("Cannot find objects.");
138162
return Activity.NONE;
139163
}
140164

141165
WorldPoint myLocation = client.getLocalPlayer().getWorldLocation();
142166
double polishWheelDistance = myLocation.distanceTo(polishWheel.getWorldLocation());
143167
double grindingWheelDistance = myLocation.distanceTo(grindingWheel.getWorldLocation());
144-
if (polishWheelDistance < grindingWheelDistance){
168+
if (polishWheelDistance < grindingWheelDistance) {
145169
return Activity.POLISHING;
146170
}
147171
return Activity.GRINDING;
@@ -243,6 +267,9 @@ public int getActionsLeftInStage() {
243267
double progressTillNext = progressPerStage - progress % progressPerStage;
244268

245269
Stage current = getCurrentStage();
270+
if (current == null) {
271+
return -1;
272+
}
246273
return (int) Math.ceil(progressTillNext / current.getProgressPerAction());
247274
}
248275

@@ -263,6 +290,20 @@ public Stage getCurrentStage() {
263290
return getStages().get(index);
264291
}
265292

293+
public Stage getNextStage() {
294+
List<Stage> stages = getStages();
295+
int index = (int) (getProgressAmount() / 1000d * getStages().size());
296+
if (index < 0 || index > stages.size() - 1) {
297+
return Stage.NONE;
298+
}
299+
300+
if (index > stages.size() - 2) {
301+
return Stage.NONE;
302+
}
303+
304+
return getStages().get(index + 1);
305+
}
306+
266307
public List<Stage> getStages() {
267308
if (stages.isEmpty()) {
268309
Widget progressParent = client.getWidget(WIDGET_PROGRESS_PARENT);
@@ -342,14 +383,14 @@ public enum Stage {
342383

343384
TRIP_HAMMER("Hammer", Heat.HIGH, 20, -25, GiantsFoundryHelper.TRIP_HAMMER),
344385
GRINDSTONE("Grind", Heat.MED, 10, 15, GiantsFoundryHelper.GRINDSTONE),
345-
POLISHING_WHEEL("Polish", Heat.LOW, 10, -17, GiantsFoundryHelper.POLISHING_WHEEL);
346-
// NONE("None", Heat.NONE, -1, -1, -1);
386+
POLISHING_WHEEL("Polish", Heat.LOW, 10, -17, GiantsFoundryHelper.POLISHING_WHEEL),
387+
NONE("None", Heat.NONE, -1, -1, -1);
347388

348389

349390
private final String name;
350391
private final Heat heat;
351392
private final int progressPerAction;
352393
private final int heatChange;
353394
private final int objectId;
354-
}
395+
}
355396
}

src/main/java/dev/jort/copilot/other/IdHolder.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ public class IdHolder {
2323

2424
private String name = "NoName";
2525
private int[] npcIds = new int[0];
26-
private int[] objectIds = new int[0];
26+
private int[] gameObjectIds = new int[0];
27+
private int[] secondaryGameObjectIds = new int[0];
2728
private int[] itemIds = new int[0];
2829
private Widget[] widgets = new Widget[0];
2930
private String[] actions = new String[0];
3031

3132
public IdHolder(String... contains) {
32-
setObjectIds(Ids.determineIds(ObjectID.class, contains));
33+
setGameObjectIds(Ids.determineIds(ObjectID.class, contains));
3334
setName(Util.capitalize(contains[0].toLowerCase()));
3435
}
3536

3637
public boolean matchId(int id) {
37-
return matchId(id, npcIds) || matchId(id, objectIds) || matchId(id, itemIds) || matchId(id, widgets);
38+
return matchId(id, npcIds) || matchId(id, gameObjectIds) || matchId(id, secondaryGameObjectIds) || matchId(id, itemIds) || matchId(id, widgets);
3839
}
3940

4041
public boolean matchAction(String action) {
@@ -51,14 +52,14 @@ private boolean matchId(int idToMatch, int... ids) {
5152
}
5253

5354
private boolean matchId(int idToMatch, Widget... widgets) {
54-
if(widgets == null){
55+
if (widgets == null) {
5556
return false;
5657
}
57-
for(Widget widget : widgets){
58-
if(widget == null){
58+
for (Widget widget : widgets) {
59+
if (widget == null) {
5960
continue;
6061
}
61-
if(widget.getId() != idToMatch){
62+
if (widget.getId() != idToMatch) {
6263
continue;
6364
}
6465
return true;
@@ -78,8 +79,13 @@ public IdHolder setNpcIds(int... npcIds) {
7879
return this;
7980
}
8081

81-
public IdHolder setObjectIds(int... objectIds) {
82-
this.objectIds = objectIds;
82+
public IdHolder setGameObjectIds(int... gameObjectIds) {
83+
this.gameObjectIds = gameObjectIds;
84+
return this;
85+
}
86+
87+
public IdHolder setSecondaryGameObjectIds(int... gameObjectIds) {
88+
this.secondaryGameObjectIds = gameObjectIds;
8389
return this;
8490
}
8591

src/main/java/dev/jort/copilot/overlays/CopilotOverlayUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import javax.inject.Inject;
1111
import javax.inject.Singleton;
1212
import java.awt.*;
13-
import java.util.Arrays;
1413

1514
@Slf4j
1615
@Singleton
@@ -71,7 +70,7 @@ public void handleOverlays(IdHolder action) {
7170
widgetOverlay.setItemIdsToHighlight(action.getItemIds());
7271
entityOverlay.clear();
7372
entityOverlay.setNpcIdsToHighlight(action.getNpcIds());
74-
entityOverlay.setGameObjectIdsToHighlight(action.getObjectIds());
73+
entityOverlay.setGameObjectIdsToHighlight(action.getGameObjectIds());
7574

7675
if (config.hideWidgets()) {
7776
boolean areWidgetsRendered = action.getItemIds().length > 0 || action.getWidgets().length > 0;

src/main/java/dev/jort/copilot/overlays/EntityOverlay.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class EntityOverlay extends Overlay implements CopilotOverlay {
4040

4141
private int[] gameObjectIdsToHighlight = new int[0];
4242

43+
private int[] secondaryGameObjectIdsToHighlight = new int[0];
44+
4345

4446
private int[] npcIdsToHighlight = new int[0];
4547

@@ -88,6 +90,7 @@ public Dimension render(Graphics2D graphics) {
8890
}
8991
if (onlyHighlightClosest) {
9092
highlightTileObject(graphics, gameObjects.closest(gameObjectIdsToHighlight));
93+
highlightTileObject(graphics, gameObjects.closest(secondaryGameObjectIdsToHighlight));
9194
highlightActor(graphics, npcs.closest(npcIdsToHighlight));
9295
return null;
9396

@@ -98,6 +101,11 @@ public Dimension render(Graphics2D graphics) {
98101
highlightTileObject(graphics, gameObject);
99102
}
100103

104+
gameObjectList = gameObjects.filter(gameObject -> Util.arrayContains(gameObject.getId(), secondaryGameObjectIdsToHighlight));
105+
for (GameObject gameObject : gameObjectList) {
106+
highlightTileObject(graphics, gameObject);
107+
}
108+
101109
List<NPC> npcList = npcs.filter(npc -> Util.arrayContains(npc.getId(), npcIdsToHighlight));
102110
for (NPC npc : npcList) {
103111
highlightActor(graphics, npc);

src/main/java/dev/jort/copilot/overlays/InfoOverlay.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public Dimension render(Graphics2D graphics) {
6161
}
6262
renderScriptText();
6363
renderGiantsFoundryText();
64-
panelComponent.setPreferredSize(new Dimension(200, 100));
65-
return null;
64+
panelComponent.setPreferredSize(new Dimension(300, 100));
65+
return super.render(graphics);
6666
}
6767

6868
public void renderScriptText() {
@@ -85,6 +85,7 @@ public void renderScriptText() {
8585

8686
}
8787

88+
8889
public void renderGiantsFoundryText() {
8990
if (!config.giantsFoundry()) {
9091
return;
@@ -117,13 +118,32 @@ public void renderGiantsFoundryText() {
117118

118119
panelComponent.getChildren().add(LineComponent.builder()
119120
.left("Busy with:")
120-
.right(giantsFoundryHelper.getOperatingMachine().name() + "")
121+
.right(giantsFoundryHelper.getActivity().name() + "")
121122
.build());
122123

123124
panelComponent.getChildren().add(LineComponent.builder()
124125
.left("Animation:")
125126
.right(tracker.getAnimation() + "")
126127
.build());
128+
129+
panelComponent.getChildren().add(LineComponent.builder()
130+
.left("Current stage:")
131+
.right(giantsFoundryHelper.getCurrentStage().name() + "")
132+
.build());
133+
134+
panelComponent.getChildren().add(LineComponent.builder()
135+
.left("Next stage:")
136+
.right(giantsFoundryHelper.getNextStage().name() + "")
137+
.build());
138+
panelComponent.getChildren().add(LineComponent.builder()
139+
.left("Using machine:")
140+
.right(giantsFoundryHelper.isOperatingMachine() + "")
141+
.build());
142+
143+
panelComponent.getChildren().add(LineComponent.builder()
144+
.left("Modifying temperature:")
145+
.right(giantsFoundryHelper.isModifyingTemperature() + "")
146+
.build());
127147
}
128148

129149
@Override

src/main/java/dev/jort/copilot/scripts/FishingBarbarian.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public void handleAction() {
4343
//else click the fire to summon it
4444
action = new IdHolder()
4545
.setName("Click fire")
46-
.setObjectIds(ids.BARBARIAN_FIRE);
46+
.setGameObjectIds(ids.BARBARIAN_FIRE);
4747
return;
4848
}
4949

5050
//click fishing spot
5151
action = new IdHolder()
5252
.setName("Click fishing spot")
53-
.setObjectIds(ids.ROD_FISHING_SPOT_IDS)
53+
.setGameObjectIds(ids.ROD_FISHING_SPOT_IDS)
5454
.setActions("Lure");
5555

5656
entityOverlay.setOnlyHighlightClosest(true);

src/main/java/dev/jort/copilot/scripts/GiantsFoundry.java

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,72 @@
33
import dev.jort.copilot.helpers.GiantsFoundryHelper;
44
import dev.jort.copilot.other.IdHolder;
55
import dev.jort.copilot.other.Script;
6+
import lombok.extern.slf4j.Slf4j;
67

78
import javax.inject.Inject;
89

10+
@Slf4j
911
public class GiantsFoundry extends Script {
1012
@Inject
1113
GiantsFoundryHelper gf;
1214

1315
@Override
14-
public void onStart() {
15-
action = new IdHolder()
16-
.setName("Click tool")
17-
.setObjectIds(gf.getCurrentStage().getObjectId());
16+
public void onLoop() {
17+
if (gf.isOperatingMachine()) {
18+
//hover next machine if enough actions left
19+
if(gf.getHeatLeft() > gf.getActionsLeftInStage() + config.giantsFoundryToolBuffer()){
20+
action = new IdHolder()
21+
.setName("Hover next machine")
22+
.setGameObjectIds(gf.getNextStage().getObjectId());
23+
return;
24+
}
1825

19-
}
26+
//otherwise hover lava/water
27+
if(gf.determineAction() == GiantsFoundryHelper.Action.USE_MACHINE_TO_LOWER){
28+
action = new IdHolder()
29+
.setName("Hover lava")
30+
.setGameObjectIds(GiantsFoundryHelper.LAVA_POOL);
31+
return;
32+
}
33+
if(gf.determineAction() == GiantsFoundryHelper.Action.USE_MACHINE_TO_UPPER){
34+
action = new IdHolder()
35+
.setName("Hover water")
36+
.setGameObjectIds(GiantsFoundryHelper.WATERFALL);
37+
return;
38+
}
2039

21-
@Override
22-
public void onLoop() {
23-
if(gf.isOperatingMachine()){
40+
log.warn("Unknown state, probably wrong machine!");
41+
alert.playAlternativeAlertSound();
42+
return;
43+
}
2444

25-
gf.getHeatLeft();
45+
if(gf.isModifyingTemperature()){
46+
action = new IdHolder()
47+
.setName("Hover machine")
48+
.setGameObjectIds(gf.getCurrentStage().getObjectId());
49+
return;
50+
}
51+
52+
53+
GiantsFoundryHelper.Action actionNeeded = gf.determineAction();
54+
String actionString = actionNeeded.name().toLowerCase();
55+
if(actionString.contains("machine")){
56+
action = new IdHolder()
57+
.setName("Click machine")
58+
.setGameObjectIds(gf.getCurrentStage().getObjectId());
59+
return;
60+
}
61+
if(actionString.contains("warm")){
62+
action = new IdHolder()
63+
.setName("Click lava")
64+
.setGameObjectIds(GiantsFoundryHelper.LAVA_POOL);
65+
return;
66+
}
67+
if(actionString.contains("cool")){
68+
action = new IdHolder()
69+
.setName("Click water")
70+
.setGameObjectIds(GiantsFoundryHelper.WATERFALL);
71+
return;
2672
}
2773
}
2874
}

src/main/java/dev/jort/copilot/scripts/InventoryMakeScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void determineAction() {
7878
if (!inventory.containsAll(toolAndResourceIds)) {
7979
action = new IdHolder()
8080
.setName("Open bank")
81-
.setObjectIds(ids.BANK_OBJECT_IDS);
81+
.setGameObjectIds(ids.BANK_OBJECT_IDS);
8282
return;
8383
}
8484

0 commit comments

Comments
 (0)