11package net .runelite .client .plugins .microbot .aiofighter ;
22
33import net .runelite .api .Client ;
4+ import net .runelite .api .Constants ;
45import net .runelite .api .Perspective ;
56import net .runelite .api .Point ;
67import net .runelite .api .coords .LocalPoint ;
8+ import net .runelite .api .geometry .Geometry ;
79import net .runelite .client .plugins .microbot .Microbot ;
10+ import net .runelite .client .plugins .microbot .aiofighter .combat .AttackNpcScript ;
811import net .runelite .client .plugins .microbot .aiofighter .model .Monster ;
12+ import net .runelite .client .plugins .microbot .util .coords .Rs2WorldArea ;
913import net .runelite .client .plugins .microbot .util .npc .Rs2NpcModel ;
1014import net .runelite .client .ui .overlay .OverlayLayer ;
1115import net .runelite .client .ui .overlay .OverlayPanel ;
1519
1620import javax .inject .Inject ;
1721import java .awt .*;
22+ import java .awt .geom .Area ;
23+ import java .awt .geom .GeneralPath ;
1824
1925import 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 ;
2127import static net .runelite .client .ui .overlay .OverlayUtil .renderPolygon ;
2228
2329public 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