cannon plugin: cleanup
This commit is contained in:
@@ -24,9 +24,6 @@
|
||||
*/
|
||||
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.Graphics2D;
|
||||
import java.awt.Point;
|
||||
@@ -59,44 +56,43 @@ class CannonOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics, Point parent)
|
||||
{
|
||||
if (!plugin.cannonPlaced || plugin.myCannon == null)
|
||||
if (!plugin.isCannonPlaced() || plugin.getCannonPosition() == 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;
|
||||
}
|
||||
|
||||
net.runelite.api.Point cannonLoc = Perspective.getCanvasTextLocation(client,
|
||||
graphics,
|
||||
Perspective.worldToLocal(client, plugin.myCannon),
|
||||
String.valueOf(plugin.cballsLeft), 200);
|
||||
cannonPoint,
|
||||
String.valueOf(plugin.getCballsLeft()), 200);
|
||||
|
||||
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()));
|
||||
|
||||
if (plugin.cballsLeft > 15)
|
||||
{
|
||||
textComponent.setColor(GREEN);;
|
||||
}
|
||||
else if (plugin.cballsLeft > 5)
|
||||
{
|
||||
textComponent.setColor(ORANGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
textComponent.setColor(RED);
|
||||
}
|
||||
|
||||
textComponent.setColor(plugin.getStateColor());
|
||||
textComponent.render(graphics, parent);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,11 @@ package net.runelite.client.plugins.cannon;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.Color;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
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 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
|
||||
private Notifier notifier;
|
||||
@@ -90,7 +98,7 @@ public class CannonPlugin extends Plugin
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
cannonPlaced = false;
|
||||
myCannon = null;
|
||||
cannonPosition = null;
|
||||
cballsLeft = 0;
|
||||
}
|
||||
|
||||
@@ -105,7 +113,8 @@ public class CannonPlugin extends Plugin
|
||||
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2
|
||||
&& 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();
|
||||
|
||||
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()));
|
||||
|
||||
//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--;
|
||||
}
|
||||
@@ -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