blast furance plugin: add bar dispenser to clickbox overlay

Also added support to color the dispenser / conveyor depending on the
bar dispenser state.

These are the current expected values:

0 = No bars being processed
1 = Ores are being processed on the conveyor belt, bar dispenser cannot
be checked
2 = Bars are cooling down
3 = Bars can be collected
This commit is contained in:
ypperlig
2018-05-25 22:49:23 +02:00
committed by Adam
parent 7a1ce39633
commit a2b8ed8f7c
4 changed files with 102 additions and 17 deletions

View File

@@ -201,6 +201,17 @@ public enum Varbits
*/
IN_GAME_BA(3923),
/**
* Blast Furnace Bar Dispenser
*
* These are the expected values:
* 0 = No bars being processed
* 1 = Ores are being processed on the conveyor belt, bar dispenser cannot be checked
* 2 = Bars are cooling down
* 3 = Bars can be collected
*/
BAR_DISPENSER(936),
/**
* Motherlode mine sack
*/

View File

@@ -30,13 +30,19 @@ import java.awt.Graphics2D;
import java.awt.geom.Area;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.EquipmentInventorySlot;
import net.runelite.api.GameObject;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Point;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
class ConveyorBeltOverlay extends Overlay
class BlastFurnaceClickBoxOverlay extends Overlay
{
private static final int MAX_DISTANCE = 2350;
@@ -45,7 +51,7 @@ class ConveyorBeltOverlay extends Overlay
private final BlastFurnaceConfig config;
@Inject
ConveyorBeltOverlay(Client client, BlastFurnacePlugin plugin, BlastFurnaceConfig config)
BlastFurnaceClickBoxOverlay(Client client, BlastFurnacePlugin plugin, BlastFurnaceConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
this.client = client;
@@ -56,17 +62,52 @@ class ConveyorBeltOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showConveyorBelt() || plugin.getConveyorBelt() == null)
int dispenserState = client.getVar(Varbits.BAR_DISPENSER);
if (config.showConveyorBelt() && plugin.getConveyorBelt() != null)
{
return null;
Color color = dispenserState == 1 ? Color.RED : Color.GREEN;
renderObject(plugin.getConveyorBelt(), graphics, color);
}
if (config.showBarDispenser() && plugin.getBarDispenser() != null)
{
boolean hasIceGloves = hasIceGloves();
Color color = dispenserState == 2 && hasIceGloves ? Color.GREEN : (dispenserState == 3 ? Color.GREEN : Color.RED);
renderObject(plugin.getBarDispenser(), graphics, color);
}
return null;
}
private boolean hasIceGloves()
{
ItemContainer equipmentContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (equipmentContainer == null)
{
return false;
}
Item[] items = equipmentContainer.getItems();
int idx = EquipmentInventorySlot.GLOVES.getSlotIdx();
if (items == null || idx >= items.length)
{
return false;
}
Item glove = items[idx];
return glove != null && glove.getId() == ItemID.ICE_GLOVES;
}
private void renderObject(GameObject object, Graphics2D graphics, Color color)
{
LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
Point mousePosition = client.getMouseCanvasPosition();
GameObject object = plugin.getConveyorBelt();
LocalPoint location = object.getLocalLocation();
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
{
Area objectClickbox = object.getClickbox();
@@ -74,17 +115,16 @@ class ConveyorBeltOverlay extends Overlay
{
if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(Color.RED.darker());
graphics.setColor(color.darker());
}
else
{
graphics.setColor(Color.RED);
graphics.setColor(color);
}
graphics.draw(objectClickbox);
graphics.setColor(new Color(0xFF, 0, 0, 20));
graphics.fill(objectClickbox);
}
}
return null;
}
}

View File

@@ -37,11 +37,23 @@ public interface BlastFurnaceConfig extends Config
{
@ConfigItem(
keyName = "showConveyorBelt",
name = "Show Conveyor belt clickbox",
description = "Configures whether or not the clickbox for the conveyor belt is displayed"
name = "Show conveyor belt clickbox",
description = "Configures whether or not the clickbox for the conveyor belt is displayed",
position = 1
)
default boolean showConveyorBelt()
{
return true;
}
@ConfigItem(
keyName = "showBarDispenser",
name = "Show bar dispenser clickbox",
description = "Configures whether or not the clickbox for the bar dispenser is displayed",
position = 2
)
default boolean showBarDispenser()
{
return true;
}
}

View File

@@ -34,6 +34,7 @@ import lombok.Getter;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import static net.runelite.api.ObjectID.CONVEYOR_BELT;
import static net.runelite.api.ObjectID.NULL_9092;
import net.runelite.api.events.GameObjectDespawned;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
@@ -47,9 +48,14 @@ import net.runelite.client.ui.overlay.Overlay;
)
public class BlastFurnacePlugin extends Plugin
{
private static final int BAR_DISPENSER = NULL_9092;
@Getter(AccessLevel.PACKAGE)
private GameObject conveyorBelt;
@Getter(AccessLevel.PACKAGE)
private GameObject barDispenser;
@Inject
private BlastFurnaceOverlay overlay;
@@ -57,12 +63,13 @@ public class BlastFurnacePlugin extends Plugin
private BlastFurnaceCofferOverlay cofferOverlay;
@Inject
private ConveyorBeltOverlay conveyorBeltOverlay;
private BlastFurnaceClickBoxOverlay clickBoxOverlay;
@Override
protected void shutDown()
{
conveyorBelt = null;
barDispenser = null;
}
@Provides
@@ -74,16 +81,23 @@ public class BlastFurnacePlugin extends Plugin
@Override
public Collection<Overlay> getOverlays()
{
return Arrays.asList(overlay, cofferOverlay, conveyorBeltOverlay);
return Arrays.asList(overlay, cofferOverlay, clickBoxOverlay);
}
@Subscribe
public void onGameObjectSpawn(GameObjectSpawned event)
{
GameObject gameObject = event.getGameObject();
if (gameObject.getId() == CONVEYOR_BELT)
switch (gameObject.getId())
{
conveyorBelt = gameObject;
case CONVEYOR_BELT:
conveyorBelt = gameObject;
break;
case BAR_DISPENSER:
barDispenser = gameObject;
break;
}
}
@@ -91,9 +105,16 @@ public class BlastFurnacePlugin extends Plugin
public void onGameObjectDespawn(GameObjectDespawned event)
{
GameObject gameObject = event.getGameObject();
if (gameObject.getId() == CONVEYOR_BELT)
switch (gameObject.getId())
{
conveyorBelt = null;
case CONVEYOR_BELT:
conveyorBelt = null;
break;
case BAR_DISPENSER:
barDispenser = null;
break;
}
}
@@ -103,6 +124,7 @@ public class BlastFurnacePlugin extends Plugin
if (event.getGameState() == GameState.LOADING)
{
conveyorBelt = null;
barDispenser = null;
}
}
}