Skip to content

Commit 438b878

Browse files
authored
Merge pull request chsami#1280 from See1Duck/development
2 parents 0371905 + be21d87 commit 438b878

39 files changed

Lines changed: 5413 additions & 5842 deletions

runelite-client/src/main/java/net/runelite/client/plugins/microbot/aiofighter/AIOFighterConfig.java

Lines changed: 144 additions & 263 deletions
Large diffs are not rendered by default.
Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,60 @@
11
package net.runelite.client.plugins.microbot.aiofighter;
22

3-
3+
import lombok.extern.slf4j.Slf4j;
44
import net.runelite.client.plugins.microbot.Microbot;
5+
import net.runelite.client.plugins.microbot.aiofighter.combat.SlayerScript;
6+
import net.runelite.client.plugins.microbot.util.slayer.Rs2Slayer;
7+
import net.runelite.client.plugins.microbot.util.walker.Rs2Walker;
8+
import net.runelite.client.ui.FontManager;
59
import net.runelite.client.ui.overlay.OverlayPanel;
610
import net.runelite.client.ui.overlay.OverlayPosition;
11+
import net.runelite.client.ui.overlay.components.ButtonComponent;
712
import net.runelite.client.ui.overlay.components.LineComponent;
813
import net.runelite.client.ui.overlay.components.TitleComponent;
914

1015
import javax.inject.Inject;
1116
import java.awt.*;
12-
17+
@Slf4j
1318
public class AIOFighterInfoOverlay extends OverlayPanel {
1419
private final AIOFighterConfig config;
20+
public final ButtonComponent myButton;
21+
public final ButtonComponent blacklistButton;
1522

1623
@Inject
1724
AIOFighterInfoOverlay(AIOFighterPlugin plugin, AIOFighterConfig config) {
1825
super(plugin);
1926
this.config = config;
2027
setPosition(OverlayPosition.TOP_LEFT);
2128
setNaughty();
29+
30+
// Initialize the button with a label and preferred size
31+
myButton = new ButtonComponent("Pause");
32+
myButton.setPreferredSize(new Dimension(100, 30));
33+
myButton.setParentOverlay(this);
34+
myButton.setFont(FontManager.getRunescapeBoldFont());
35+
myButton.setOnClick(() -> {
36+
// Handle button click
37+
Microbot.pauseAllScripts.set(!Microbot.pauseAllScripts.get());
38+
if (Microbot.pauseAllScripts.get()) {
39+
Rs2Walker.setTarget(null);
40+
myButton.setText("Unpause");
41+
} else {
42+
myButton.setText("Pause");
43+
}
44+
});
45+
46+
// Initialize the blacklist button with a label and preferred size
47+
blacklistButton = new ButtonComponent("Blacklist");
48+
blacklistButton.setPreferredSize(new Dimension(100, 20));
49+
blacklistButton.setParentOverlay(this);
50+
blacklistButton.setFont(FontManager.getRunescapeBoldFont());
51+
blacklistButton.setOnClick(() -> {
52+
// Handle button click
53+
AIOFighterPlugin.addBlacklistedSlayerNpcs(Rs2Slayer.slayerTaskMonsterTarget);
54+
SlayerScript.reset();
55+
});
56+
57+
2258
}
2359

2460
@Override
@@ -30,21 +66,55 @@ public Dimension render(Graphics2D graphics) {
3066
.color(Color.ORANGE)
3167
.build());
3268

33-
69+
panelComponent.getChildren().add(LineComponent.builder().build());
3470
panelComponent.getChildren().add(LineComponent.builder()
35-
.left("Play Style: " + config.playStyle() + "(" + config.playStyle().getPrimaryTickInterval() + "," + config.playStyle().getSecondaryTickInterval() + ")")
36-
.right("Attack cooldown: " + AIOFighterPlugin.getCooldown())
71+
.left("Slayer Mode: ")
72+
.right(config.slayerMode() ? "Enabled" : "Disabled")
3773
.build());
74+
75+
if (config.slayerMode()) {
76+
panelComponent.getChildren().add(LineComponent.builder()
77+
.left("Slayer Task: ")
78+
.right(config.slayerTask())
79+
.build());
80+
panelComponent.getChildren().add(LineComponent.builder()
81+
.left("Slayer Task Location: ")
82+
.right(config.slayerLocation())
83+
.build());
84+
panelComponent.getChildren().add(LineComponent.builder()
85+
.left("Remaining kills: ")
86+
.right(String.valueOf(config.remainingSlayerKills()))
87+
.build());
88+
}
89+
panelComponent.getChildren().add(LineComponent.builder().build());
90+
if (config.slayerMode()) {
91+
panelComponent.getChildren().add(LineComponent.builder()
92+
.left("Slayer Has Task Weakness: ")
93+
.right(config.slayerHasTaskWeakness() ? "Yes" : "No")
94+
.build());
95+
panelComponent.getChildren().add(LineComponent.builder()
96+
.left("Slayer Task Weakness Item: ")
97+
.right(config.slayerTaskWeaknessItem())
98+
.build());
99+
panelComponent.getChildren().add(LineComponent.builder()
100+
.left("Slayer Task Weakness Threshold: ")
101+
.right(String.valueOf(config.slayerTaskWeaknessThreshold()))
102+
.build());
103+
}
104+
panelComponent.getChildren().add(LineComponent.builder().build());
105+
panelComponent.getChildren().add(blacklistButton);
38106
panelComponent.getChildren().add(LineComponent.builder().build());
39107
panelComponent.getChildren().add(LineComponent.builder()
40108
.left(Microbot.status)
41-
.right("Version:" + AIOFighterPlugin.version)
109+
.right("Version:" + AIOFighterPlugin.version)
42110
.build());
43111

44-
112+
// Add the button to the overlay panel
113+
panelComponent.getChildren().add(myButton);
45114
} catch (Exception ex) {
46115
Microbot.logStackTrace(this.getClass().getSimpleName(), ex);
47116
}
48117
return super.render(graphics);
49118
}
119+
50120
}

runelite-client/src/main/java/net/runelite/client/plugins/microbot/aiofighter/AIOFighterOverlay.java

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package net.runelite.client.plugins.microbot.aiofighter;
22

33
import net.runelite.api.Client;
4+
import net.runelite.api.Constants;
45
import net.runelite.api.Perspective;
56
import net.runelite.api.Point;
67
import net.runelite.api.coords.LocalPoint;
8+
import net.runelite.api.geometry.Geometry;
79
import net.runelite.client.plugins.microbot.Microbot;
10+
import net.runelite.client.plugins.microbot.aiofighter.combat.AttackNpcScript;
811
import net.runelite.client.plugins.microbot.aiofighter.model.Monster;
12+
import net.runelite.client.plugins.microbot.util.coords.Rs2WorldArea;
913
import net.runelite.client.plugins.microbot.util.npc.Rs2NpcModel;
1014
import net.runelite.client.ui.overlay.OverlayLayer;
1115
import net.runelite.client.ui.overlay.OverlayPanel;
@@ -15,19 +19,23 @@
1519

1620
import javax.inject.Inject;
1721
import java.awt.*;
22+
import java.awt.geom.Area;
23+
import java.awt.geom.GeneralPath;
1824

1925
import static net.runelite.client.plugins.microbot.aiofighter.combat.AttackNpcScript.filteredAttackableNpcs;
20-
import static net.runelite.client.plugins.microbot.aiofighter.combat.FlickerScript.currentMonstersAttackingUs;
26+
import static net.runelite.client.plugins.microbot.aiofighter.combat.FlickerScript.currentMonstersAttackingUsRef;
2127
import static net.runelite.client.ui.overlay.OverlayUtil.renderPolygon;
2228

2329
public class AIOFighterOverlay extends OverlayPanel {
2430

2531
private static final Color WHITE_TRANSLUCENT = new Color(0, 255, 255, 127);
2632
private static final Color RED_TRANSLUCENT = new Color(255, 0, 0, 127);
33+
private static final int MAX_LOCAL_DRAW_LENGTH = 20 * Perspective.LOCAL_TILE_SIZE;
2734
private final ModelOutlineRenderer modelOutlineRenderer;
2835
private final int diameter = 100;
2936
private final Color borderColor = Color.WHITE;
3037
private final Stroke stroke = new BasicStroke(1);
38+
private final GeneralPath[] linesToDisplay = new GeneralPath[Constants.MAX_Z];
3139
AIOFighterConfig config;
3240

3341
@Inject
@@ -51,15 +59,19 @@ public static void renderMinimapRect(Client client, Graphics2D graphics, Point c
5159

5260
@Override
5361
public Dimension render(Graphics2D graphics) {
54-
if (filteredAttackableNpcs == null) return null;
62+
if(AttackNpcScript.attackableArea == null) return null;
63+
if (filteredAttackableNpcs.get() == null) return null;
5564

65+
calculateLinesToDisplay();
66+
GeneralPath lines = linesToDisplay[Microbot.getClient().getPlane()];
5667
LocalPoint lp = LocalPoint.fromWorld(Microbot.getClient(), config.centerLocation());
5768
if (lp != null) {
5869
Polygon poly = Perspective.getCanvasTileAreaPoly(Microbot.getClient(), lp, config.attackRadius() * 2);
5970

6071
if (poly != null)
6172
{
62-
renderPolygon(graphics, poly, WHITE_TRANSLUCENT);
73+
//renderPolygon(graphics, poly, WHITE_TRANSLUCENT);
74+
renderPath(graphics,lines,WHITE_TRANSLUCENT);
6375
}
6476
}
6577
// render safe spot
@@ -68,6 +80,7 @@ public Dimension render(Graphics2D graphics) {
6880
Polygon safeSpotPoly = Perspective.getCanvasTileAreaPoly(Microbot.getClient(), sslp, 1);
6981
if (safeSpotPoly != null && config.toggleSafeSpot()) {
7082
renderPolygon(graphics, safeSpotPoly, RED_TRANSLUCENT);
83+
7184
}
7285
}
7386

@@ -83,7 +96,7 @@ public Dimension render(Graphics2D graphics) {
8396
}
8497
}
8598

86-
for (Monster currentMonster : currentMonstersAttackingUs.get()) {
99+
for (Monster currentMonster : currentMonstersAttackingUsRef.get()) {
87100
if (currentMonster != null && currentMonster.npc != null && currentMonster.npc.getCanvasTilePoly() != null) {
88101
try {
89102
graphics.setColor(Color.CYAN);
@@ -92,6 +105,12 @@ public Dimension render(Graphics2D graphics) {
92105
graphics.drawString("" + currentMonster.lastAttack,
93106
(int) currentMonster.npc.getCanvasTilePoly().getBounds().getCenterX(),
94107
(int) currentMonster.npc.getCanvasTilePoly().getBounds().getCenterY());
108+
// draw the attack style
109+
if (currentMonster.attackStyle != null) {
110+
graphics.drawString(currentMonster.attackStyle.name(),
111+
(int) currentMonster.npc.getCanvasTilePoly().getBounds().getCenterX(),
112+
(int) currentMonster.npc.getCanvasTilePoly().getBounds().getCenterY() + 15);
113+
}
95114
} catch(Exception ex) {
96115
System.out.println(ex.getMessage());
97116
}
@@ -100,4 +119,69 @@ public Dimension render(Graphics2D graphics) {
100119

101120
return super.render(graphics);
102121
}
122+
123+
private void renderPath(Graphics2D graphics, GeneralPath path, Color color)
124+
{
125+
LocalPoint playerLp = Microbot.getClient().getLocalPlayer().getLocalLocation();
126+
Rectangle viewArea = new Rectangle(
127+
playerLp.getX() - MAX_LOCAL_DRAW_LENGTH,
128+
playerLp.getY() - MAX_LOCAL_DRAW_LENGTH,
129+
MAX_LOCAL_DRAW_LENGTH * 2,
130+
MAX_LOCAL_DRAW_LENGTH * 2);
131+
132+
graphics.setColor(color);
133+
graphics.setStroke(new BasicStroke(3));
134+
135+
path = Geometry.clipPath(path, viewArea);
136+
path = Geometry.filterPath(path, (p1, p2) ->
137+
Perspective.localToCanvas(Microbot.getClient(), new LocalPoint((int)p1[0], (int)p1[1]), Microbot.getClient().getPlane()) != null &&
138+
Perspective.localToCanvas(Microbot.getClient(), new LocalPoint((int)p2[0], (int)p2[1]), Microbot.getClient().getPlane()) != null);
139+
path = Geometry.transformPath(path, coords ->
140+
{
141+
Point point = Perspective.localToCanvas(Microbot.getClient(), new LocalPoint((int)coords[0], (int)coords[1]), Microbot.getClient().getPlane());
142+
coords[0] = point.getX();
143+
coords[1] = point.getY();
144+
});
145+
146+
graphics.draw(path);
147+
}
148+
149+
private Area generateAttackableArea(Rs2WorldArea area) {
150+
Area attackableArea = new Area();
151+
Polygon poly = new Polygon();
152+
153+
// add 4 points to the polygon for the corners of the area
154+
poly.addPoint(area.getX(), area.getY() );
155+
poly.addPoint(area.getX() + area.getWidth(), area.getY());
156+
poly.addPoint(area.getX() + area.getWidth(), area.getY() + area.getHeight());
157+
poly.addPoint(area.getX(), area.getY() + area.getHeight());
158+
// create a new area from the polygon
159+
attackableArea.add(new Area(poly));
160+
161+
return attackableArea;
162+
}
163+
164+
private void calculateLinesToDisplay()
165+
{
166+
167+
Rectangle sceneRect = new Rectangle(
168+
Microbot.getClient().getTopLevelWorldView().getBaseX() + 1, Microbot.getClient().getTopLevelWorldView().getBaseY() + 1,
169+
Constants.SCENE_SIZE - 2, Constants.SCENE_SIZE - 2);
170+
171+
for (int i = 0; i < linesToDisplay.length; i++)
172+
{
173+
GeneralPath lines = new GeneralPath(generateAttackableArea(AttackNpcScript.attackableArea));
174+
lines = Geometry.clipPath(lines, sceneRect);
175+
lines = Geometry.splitIntoSegments(lines, 1);
176+
lines = Geometry.transformPath(lines, this::transformWorldToLocal);
177+
linesToDisplay[i] = lines;
178+
}
179+
}
180+
181+
private void transformWorldToLocal(float[] coords)
182+
{
183+
final LocalPoint lp = LocalPoint.fromWorld(Microbot.getClient(), (int) coords[0], (int) coords[1]);
184+
coords[0] = lp.getX() - Perspective.LOCAL_TILE_SIZE / 2f;
185+
coords[1] = lp.getY() - Perspective.LOCAL_TILE_SIZE / 2f;
186+
}
103187
}

0 commit comments

Comments
 (0)