runecraft: add pouch degrade overlay. (#1765)
This commit is contained in:
@@ -34,6 +34,7 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum VarPlayer
|
public enum VarPlayer
|
||||||
{
|
{
|
||||||
|
POUCH_STATUS(261),
|
||||||
DUEL_PENDING(286),
|
DUEL_PENDING(286),
|
||||||
ATTACK_STYLE(43),
|
ATTACK_STYLE(43),
|
||||||
QUEST_POINTS(101),
|
QUEST_POINTS(101),
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package net.runelite.client.plugins.runecraft;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.api.ItemID;
|
||||||
|
import net.runelite.api.widgets.WidgetItem;
|
||||||
|
import net.runelite.client.game.ItemManager;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
|
import net.runelite.client.ui.overlay.WidgetItemOverlay;
|
||||||
|
|
||||||
|
public class PouchOverlay extends WidgetItemOverlay
|
||||||
|
{
|
||||||
|
private final ItemManager itemManager;
|
||||||
|
private final RunecraftPlugin plugin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PouchOverlay(final ItemManager itemManager, final RunecraftPlugin plugin)
|
||||||
|
{
|
||||||
|
this.itemManager = itemManager;
|
||||||
|
this.plugin = plugin;
|
||||||
|
showOnInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget)
|
||||||
|
{
|
||||||
|
switch (itemId)
|
||||||
|
{
|
||||||
|
case ItemID.MEDIUM_POUCH_5511:
|
||||||
|
case ItemID.LARGE_POUCH_5513:
|
||||||
|
case ItemID.GIANT_POUCH_5515:
|
||||||
|
final Rectangle bounds = itemWidget.getCanvasBounds();
|
||||||
|
final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), Color.RED);
|
||||||
|
graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null);
|
||||||
|
break;
|
||||||
|
case ItemID.MEDIUM_POUCH:
|
||||||
|
OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getMediumCharges(), Color.WHITE);
|
||||||
|
break;
|
||||||
|
case ItemID.LARGE_POUCH:
|
||||||
|
OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getLargeCharges(), Color.WHITE);
|
||||||
|
break;
|
||||||
|
case ItemID.GIANT_POUCH:
|
||||||
|
OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getGiantCharges(), Color.WHITE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,6 +95,18 @@ public interface RunecraftConfig extends Config
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "degradeOverlay",
|
||||||
|
name = "Show Uses until Degrade",
|
||||||
|
description = "This will show how many uses are left on a pouch until they degrade.",
|
||||||
|
position = 6,
|
||||||
|
titleSection = "utilTitle"
|
||||||
|
)
|
||||||
|
default boolean degradeOverlay()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigTitleSection(
|
@ConfigTitleSection(
|
||||||
keyName = "riftsTitle",
|
keyName = "riftsTitle",
|
||||||
name = "Rifts",
|
name = "Rifts",
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.DecorativeObject;
|
import net.runelite.api.DecorativeObject;
|
||||||
@@ -43,11 +43,13 @@ import net.runelite.api.ItemContainer;
|
|||||||
import net.runelite.api.ItemID;
|
import net.runelite.api.ItemID;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.NpcID;
|
import net.runelite.api.NpcID;
|
||||||
|
import net.runelite.api.VarPlayer;
|
||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.DecorativeObjectDespawned;
|
import net.runelite.api.events.DecorativeObjectDespawned;
|
||||||
import net.runelite.api.events.DecorativeObjectSpawned;
|
import net.runelite.api.events.DecorativeObjectSpawned;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
|
import net.runelite.api.events.GameTick;
|
||||||
import net.runelite.api.events.ItemContainerChanged;
|
import net.runelite.api.events.ItemContainerChanged;
|
||||||
import net.runelite.api.events.NpcDespawned;
|
import net.runelite.api.events.NpcDespawned;
|
||||||
import net.runelite.api.events.NpcSpawned;
|
import net.runelite.api.events.NpcSpawned;
|
||||||
@@ -71,8 +73,14 @@ import net.runelite.client.ui.overlay.OverlayManager;
|
|||||||
tags = {"abyssal", "minimap", "overlay", "rifts", "rc", "runecrafting"}
|
tags = {"abyssal", "minimap", "overlay", "rifts", "rc", "runecrafting"}
|
||||||
)
|
)
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
@Slf4j
|
||||||
public class RunecraftPlugin extends Plugin
|
public class RunecraftPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
private static final int MEDIUM_DEGRADE = 46;
|
||||||
|
private static final int LARGE_DEGRADE = 30;
|
||||||
|
private static final int GIANT_DEGRADE = 11;
|
||||||
|
private static final Object POUCH_TICK = new Object();
|
||||||
private static final BankComparableEntry POUCH = new BankComparableEntry("fill", "pouch", false);
|
private static final BankComparableEntry POUCH = new BankComparableEntry("fill", "pouch", false);
|
||||||
private static final BaseComparableEntry EMPTY_SMALL = newBaseComparableEntry("empty", "small pouch");
|
private static final BaseComparableEntry EMPTY_SMALL = newBaseComparableEntry("empty", "small pouch");
|
||||||
private static final BaseComparableEntry EMPTY_MEDIUM = newBaseComparableEntry("empty", "medium pouch");
|
private static final BaseComparableEntry EMPTY_MEDIUM = newBaseComparableEntry("empty", "medium pouch");
|
||||||
@@ -89,53 +97,44 @@ public class RunecraftPlugin extends Plugin
|
|||||||
ItemID.GIANT_POUCH_5515
|
ItemID.GIANT_POUCH_5515
|
||||||
);
|
);
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private final Set<AbyssRifts> rifts = new HashSet<>();
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AbyssOverlay abyssOverlay;
|
private AbyssOverlay abyssOverlay;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AbyssMinimapOverlay abyssMinimapOverlay;
|
private AbyssMinimapOverlay abyssMinimapOverlay;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private RunecraftOverlay runecraftOverlay;
|
private RunecraftOverlay runecraftOverlay;
|
||||||
|
@Inject
|
||||||
|
private PouchOverlay pouchOverlay;
|
||||||
@Inject
|
@Inject
|
||||||
private RunecraftConfig config;
|
private RunecraftConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Notifier notifier;
|
private Notifier notifier;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MenuManager menuManager;
|
private MenuManager menuManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
private final Set<AbyssRifts> rifts = new HashSet<>();
|
||||||
private final Set<DecorativeObject> abyssObjects = new HashSet<>();
|
private final Set<DecorativeObject> abyssObjects = new HashSet<>();
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean degradedPouchInInventory;
|
private boolean degradedPouchInInventory;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean degradingNotification;
|
private boolean degradingNotification;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean essPouch;
|
private boolean essPouch;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean hightlightDarkMage;
|
private boolean hightlightDarkMage;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean lavas;
|
private boolean lavas;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean showClickBox;
|
private boolean showClickBox;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
|
||||||
private boolean showRifts;
|
private boolean showRifts;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
private boolean degradeOverlay;
|
||||||
|
private boolean medDegrade;
|
||||||
|
private boolean largeDegrade;
|
||||||
|
private boolean giantDegrade;
|
||||||
|
private int mediumCharges = MEDIUM_DEGRADE;
|
||||||
|
private int largeCharges = LARGE_DEGRADE;
|
||||||
|
private int giantCharges = GIANT_DEGRADE;
|
||||||
|
private int pouchVar = 0;
|
||||||
private NPC darkMage;
|
private NPC darkMage;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -180,6 +179,86 @@ public class RunecraftPlugin extends Plugin
|
|||||||
eventBus.subscribe(NpcDespawned.class, this, this::onNpcDespawned);
|
eventBus.subscribe(NpcDespawned.class, this, this::onNpcDespawned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onGameTick(GameTick event)
|
||||||
|
{
|
||||||
|
final int before = pouchVar;
|
||||||
|
pouchVar = client.getVar(VarPlayer.POUCH_STATUS);
|
||||||
|
|
||||||
|
if (pouchVar == before)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pouchVar & 0x8) > 0 && (before & 0x8) <= 0)
|
||||||
|
{
|
||||||
|
if (giantCharges > 0)
|
||||||
|
{
|
||||||
|
giantCharges--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((pouchVar & 0x4) > 0 && (before & 0x4) <= 0)
|
||||||
|
{
|
||||||
|
if (largeCharges > 0)
|
||||||
|
{
|
||||||
|
largeCharges--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((pouchVar & 0x2) > 0 && (before & 0x2) <= 0)
|
||||||
|
{
|
||||||
|
if (mediumCharges > 0)
|
||||||
|
{
|
||||||
|
mediumCharges--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onItemContainerChanged(ItemContainerChanged event)
|
||||||
|
{
|
||||||
|
final ItemContainer container = event.getItemContainer();
|
||||||
|
|
||||||
|
if (container == client.getItemContainer(InventoryID.INVENTORY))
|
||||||
|
{
|
||||||
|
degradedPouchInInventory = false;
|
||||||
|
|
||||||
|
for (Item item : container.getItems())
|
||||||
|
{
|
||||||
|
if (!medDegrade && item.getId() == ItemID.MEDIUM_POUCH_5511)
|
||||||
|
{
|
||||||
|
medDegrade = true;
|
||||||
|
mediumCharges = 0;
|
||||||
|
degradedPouchInInventory = true;
|
||||||
|
}
|
||||||
|
else if (!largeDegrade && item.getId() == ItemID.LARGE_POUCH_5513)
|
||||||
|
{
|
||||||
|
largeDegrade = true;
|
||||||
|
largeCharges = 0;
|
||||||
|
degradedPouchInInventory = true;
|
||||||
|
}
|
||||||
|
else if (!giantDegrade && item.getId() == ItemID.GIANT_POUCH_5515)
|
||||||
|
{
|
||||||
|
giantDegrade = true;
|
||||||
|
giantCharges = 0;
|
||||||
|
degradedPouchInInventory = true;
|
||||||
|
}
|
||||||
|
else if (medDegrade && item.getId() == ItemID.MEDIUM_POUCH)
|
||||||
|
{
|
||||||
|
medDegrade = false;
|
||||||
|
mediumCharges = MEDIUM_DEGRADE;
|
||||||
|
}
|
||||||
|
else if (largeDegrade && item.getId() == ItemID.LARGE_POUCH)
|
||||||
|
{
|
||||||
|
largeDegrade = false;
|
||||||
|
largeCharges = LARGE_DEGRADE;
|
||||||
|
}
|
||||||
|
else if (giantDegrade && item.getId() == ItemID.GIANT_POUCH)
|
||||||
|
{
|
||||||
|
giantDegrade = false;
|
||||||
|
giantCharges = GIANT_DEGRADE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onConfigChanged(ConfigChanged event)
|
private void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
if (!event.getGroup().equals("runecraft"))
|
if (!event.getGroup().equals("runecraft"))
|
||||||
@@ -245,17 +324,6 @@ public class RunecraftPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onItemContainerChanged(ItemContainerChanged event)
|
|
||||||
{
|
|
||||||
final ItemContainer container = event.getItemContainer();
|
|
||||||
|
|
||||||
if (container == client.getItemContainer(InventoryID.INVENTORY))
|
|
||||||
{
|
|
||||||
final Item[] items = container.getItems();
|
|
||||||
degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onNpcSpawned(NpcSpawned event)
|
private void onNpcSpawned(NpcSpawned event)
|
||||||
{
|
{
|
||||||
final NPC npc = event.getNpc();
|
final NPC npc = event.getNpc();
|
||||||
@@ -339,6 +407,18 @@ public class RunecraftPlugin extends Plugin
|
|||||||
this.degradingNotification = config.degradingNotification();
|
this.degradingNotification = config.degradingNotification();
|
||||||
this.showRifts = config.showRifts();
|
this.showRifts = config.showRifts();
|
||||||
this.showClickBox = config.showClickBox();
|
this.showClickBox = config.showClickBox();
|
||||||
|
this.degradeOverlay = config.degradeOverlay();
|
||||||
|
|
||||||
|
if (this.degradeOverlay)
|
||||||
|
{
|
||||||
|
overlayManager.add(pouchOverlay);
|
||||||
|
eventBus.subscribe(GameTick.class, POUCH_TICK, this::onGameTick);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
overlayManager.remove(pouchOverlay);
|
||||||
|
eventBus.unregister(POUCH_TICK);
|
||||||
|
}
|
||||||
|
|
||||||
updateRifts();
|
updateRifts();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user