cannon plugin: cleanup
This commit is contained in:
@@ -24,9 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.cannon;
|
package net.runelite.client.plugins.cannon;
|
||||||
|
|
||||||
import static java.awt.Color.GREEN;
|
|
||||||
import static java.awt.Color.ORANGE;
|
|
||||||
import static java.awt.Color.RED;
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -59,44 +56,43 @@ class CannonOverlay extends Overlay
|
|||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics, Point parent)
|
public Dimension render(Graphics2D graphics, Point parent)
|
||||||
{
|
{
|
||||||
if (!plugin.cannonPlaced || plugin.myCannon == null)
|
if (!plugin.isCannonPlaced() || plugin.getCannonPosition() == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Perspective.isWorldInScene(client, plugin.myCannon))
|
if (!Perspective.isWorldInScene(client, plugin.getCannonPosition()))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
net.runelite.api.Point cannonPoint = Perspective.worldToLocal(client, plugin.getCannonPosition());
|
||||||
|
|
||||||
|
if (cannonPoint == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
net.runelite.api.Point cannonLoc = Perspective.getCanvasTextLocation(client,
|
net.runelite.api.Point cannonLoc = Perspective.getCanvasTextLocation(client,
|
||||||
graphics,
|
graphics,
|
||||||
Perspective.worldToLocal(client, plugin.myCannon),
|
cannonPoint,
|
||||||
String.valueOf(plugin.cballsLeft), 200);
|
String.valueOf(plugin.getCballsLeft()), 200);
|
||||||
|
|
||||||
Widget viewport = client.getViewportWidget();
|
Widget viewport = client.getViewportWidget();
|
||||||
|
|
||||||
if (viewport != null && cannonLoc != null && viewport.contains(cannonLoc))
|
if (viewport == null)
|
||||||
{
|
{
|
||||||
textComponent.setText(String.valueOf(plugin.cballsLeft));
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cannonLoc != null && viewport.contains(cannonLoc))
|
||||||
|
{
|
||||||
|
textComponent.setText(String.valueOf(plugin.getCballsLeft()));
|
||||||
textComponent.setPosition(new Point(cannonLoc.getX(), cannonLoc.getY()));
|
textComponent.setPosition(new Point(cannonLoc.getX(), cannonLoc.getY()));
|
||||||
|
textComponent.setColor(plugin.getStateColor());
|
||||||
if (plugin.cballsLeft > 15)
|
|
||||||
{
|
|
||||||
textComponent.setColor(GREEN);;
|
|
||||||
}
|
|
||||||
else if (plugin.cballsLeft > 5)
|
|
||||||
{
|
|
||||||
textComponent.setColor(ORANGE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
textComponent.setColor(RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
textComponent.render(graphics, parent);
|
textComponent.render(graphics, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,9 +26,11 @@ package net.runelite.client.plugins.cannon;
|
|||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import lombok.Getter;
|
||||||
import net.runelite.api.AnimationID;
|
import net.runelite.api.AnimationID;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -56,11 +58,17 @@ public class CannonPlugin extends Plugin
|
|||||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)");
|
private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)");
|
||||||
private static final int MAX_CBALLS = 30;
|
private static final int MAX_CBALLS = 30;
|
||||||
|
|
||||||
int cballsLeft = 0;
|
@Getter
|
||||||
|
private int cballsLeft;
|
||||||
|
|
||||||
boolean cannonPlaced = false;
|
@Getter
|
||||||
|
private boolean cannonPlaced;
|
||||||
|
|
||||||
net.runelite.api.Point myCannon;
|
@Getter
|
||||||
|
private net.runelite.api.Point cannonPosition;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private GameObject cannon;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Notifier notifier;
|
private Notifier notifier;
|
||||||
@@ -90,7 +98,7 @@ public class CannonPlugin extends Plugin
|
|||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
cannonPlaced = false;
|
cannonPlaced = false;
|
||||||
myCannon = null;
|
cannonPosition = null;
|
||||||
cballsLeft = 0;
|
cballsLeft = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +113,8 @@ public class CannonPlugin extends Plugin
|
|||||||
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2
|
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2
|
||||||
&& localPlayer.getAnimation() == AnimationID.BURYING_BONES)
|
&& localPlayer.getAnimation() == AnimationID.BURYING_BONES)
|
||||||
{
|
{
|
||||||
myCannon = gameObject.getWorldLocation();
|
cannonPosition = gameObject.getWorldLocation();
|
||||||
|
cannon = gameObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,12 +124,12 @@ public class CannonPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
Projectile projectile = event.getProjectile();
|
Projectile projectile = event.getProjectile();
|
||||||
|
|
||||||
if ((projectile.getId() == CANNONBALL || projectile.getId() == GRANITE_CANNONBALL) && myCannon != null)
|
if ((projectile.getId() == CANNONBALL || projectile.getId() == GRANITE_CANNONBALL) && cannonPosition != null)
|
||||||
{
|
{
|
||||||
net.runelite.api.Point projectileLoc = Perspective.localToWorld(client, new net.runelite.api.Point(projectile.getX1(), projectile.getY1()));
|
net.runelite.api.Point projectileLoc = Perspective.localToWorld(client, new net.runelite.api.Point(projectile.getX1(), projectile.getY1()));
|
||||||
|
|
||||||
//Check to see if projectile x,y is 0 else it will continuously decrease while ball is flying.
|
//Check to see if projectile x,y is 0 else it will continuously decrease while ball is flying.
|
||||||
if (projectileLoc.equals(myCannon) && projectile.getX() == 0 && projectile.getY() == 0)
|
if (projectileLoc.equals(cannonPosition) && projectile.getX() == 0 && projectile.getY() == 0)
|
||||||
{
|
{
|
||||||
cballsLeft--;
|
cballsLeft--;
|
||||||
}
|
}
|
||||||
@@ -200,4 +209,18 @@ public class CannonPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color getStateColor()
|
||||||
|
{
|
||||||
|
if (cballsLeft > 15)
|
||||||
|
{
|
||||||
|
return Color.green;
|
||||||
|
}
|
||||||
|
else if (cballsLeft > 5)
|
||||||
|
{
|
||||||
|
return Color.orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Color.red;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user