Merge pull request #1286 from ypperlig/master

Motherlode Mine - Sack overlay and region check
This commit is contained in:
Adam
2018-04-13 10:01:00 -04:00
committed by GitHub
6 changed files with 239 additions and 25 deletions

View File

@@ -202,6 +202,7 @@ public enum Varbits
* Motherlode mine sack
*/
SACK_NUMBER(5558),
SACK_UPGRADED(5556),
/**
* Experience tracker

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Lars <lars.oernlo@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,14 +32,14 @@ import net.runelite.client.config.ConfigItem;
@ConfigGroup(
keyName = "motherlode",
name = "Motherlode Mine",
description = "Configuration for the motherlode plugin"
description = "Configuration for the Motherlode Mine plugin"
)
public interface MotherlodeConfig extends Config
{
@ConfigItem(
keyName = "showRocks",
name = "Show Pay-dirt mining spots",
description = "Configures whether or not the pay-dirt minings spots is displayed"
name = "Show pay-dirt mining spots",
description = "Configures whether or not the pay-dirt mining spots are displayed."
)
default boolean showRocks()
{
@@ -48,7 +49,7 @@ public interface MotherlodeConfig extends Config
@ConfigItem(
keyName = "statTimeout",
name = "Reset stats (minutes)",
description = "Configures the time until statistic is reset"
description = "Configures the time until statistics are reset"
)
default int statTimeout()
{
@@ -57,8 +58,8 @@ public interface MotherlodeConfig extends Config
@ConfigItem(
keyName = "showSack",
name = "Show Pay-dirt Sack",
description = "Configures whether to Pay-dirt sack is displayed"
name = "Show pay-dirt sack",
description = "Configures whether the pay-dirt sack is displayed or not."
)
default boolean showSack()
{
@@ -67,11 +68,31 @@ public interface MotherlodeConfig extends Config
@ConfigItem(
keyName = "showMiningStats",
name = "Show Mining session stats",
name = "Show mining session stats",
description = "Configures whether to display mining session stats"
)
default boolean showMiningStats()
{
return true;
}
@ConfigItem(
keyName = "showDepositsLeft",
name = "Show deposits left",
description = "Displays deposits left before sack is full"
)
default boolean showDepositsLeft()
{
return true;
}
@ConfigItem(
keyName = "showMiningState",
name = "Show current mining state",
description = "Shows current mining state. 'You are currently mining' / 'You are currently NOT mining'"
)
default boolean showMiningState()
{
return true;
}
}

View File

@@ -24,7 +24,7 @@
*/
package net.runelite.client.plugins.motherlode;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
@@ -49,7 +49,7 @@ import net.runelite.client.ui.overlay.components.PanelComponent;
class MotherlodeOverlay extends Overlay
{
private static final Set<Integer> MINING_ANIMATION_IDS = Sets.newHashSet(
private static final Set<Integer> MINING_ANIMATION_IDS = ImmutableSet.of(
MINING_MOTHERLODE_BRONZE, MINING_MOTHERLODE_IRON, MINING_MOTHERLODE_STEEL,
MINING_MOTHERLODE_BLACK, MINING_MOTHERLODE_MITHRIL, MINING_MOTHERLODE_ADAMANT,
MINING_MOTHERLODE_RUNE, MINING_MOTHERLODE_DRAGON, MINING_MOTHERLODE_DRAGON_ORN,
@@ -73,7 +73,7 @@ class MotherlodeOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showMiningStats())
if (!plugin.isInMlm() || !config.showMiningStats())
{
return null;
}
@@ -95,15 +95,22 @@ class MotherlodeOverlay extends Overlay
panelComponent.getLines().clear();
if (MINING_ANIMATION_IDS.contains(client.getLocalPlayer().getAnimation()))
if (config.showMiningState())
{
panelComponent.setTitle("You are mining");
panelComponent.setTitleColor(Color.GREEN);
if (MINING_ANIMATION_IDS.contains(client.getLocalPlayer().getAnimation()))
{
panelComponent.setTitle("You are mining");
panelComponent.setTitleColor(Color.GREEN);
}
else
{
panelComponent.setTitle("You are NOT mining");
panelComponent.setTitleColor(Color.RED);
}
}
else
{
panelComponent.setTitle("You are NOT mining");
panelComponent.setTitleColor(Color.RED);
panelComponent.setTitle(null);
}
panelComponent.getLines().add(new PanelComponent.Line(

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Lars <lars.oernlo@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -25,7 +26,7 @@
*/
package net.runelite.client.plugins.motherlode;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.time.Duration;
@@ -39,20 +40,28 @@ import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import static net.runelite.api.ObjectID.ORE_VEIN_26661;
import static net.runelite.api.ObjectID.ORE_VEIN_26662;
import static net.runelite.api.ObjectID.ORE_VEIN_26663;
import static net.runelite.api.ObjectID.ORE_VEIN_26664;
import static net.runelite.api.ObjectID.ROCKFALL;
import static net.runelite.api.ObjectID.ROCKFALL_26680;
import net.runelite.api.Varbits;
import net.runelite.api.WallObject;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameObjectChanged;
import net.runelite.api.events.GameObjectDespawned;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.MapRegionChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WallObjectChanged;
import net.runelite.api.events.WallObjectDespawned;
import net.runelite.api.events.WallObjectSpawned;
@@ -68,8 +77,14 @@ import net.runelite.client.ui.overlay.Overlay;
)
public class MotherlodePlugin extends Plugin
{
private static final Set<Integer> MINE_SPOTS = Sets.newHashSet(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664);
private static final Set<Integer> ROCK_OBSTACLES = Sets.newHashSet(ROCKFALL, ROCKFALL_26680);
private static final Set<Integer> MOTHERLODE_MAP_REGIONS = ImmutableSet.of(14679, 14680, 14681, 14935, 14936, 14937, 15191, 15192, 15193);
private static final Set<Integer> MINE_SPOTS = ImmutableSet.of(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664);
private static final Set<Integer> MLM_ORE_TYPES = ImmutableSet.of(ItemID.RUNITE_ORE, ItemID.ADAMANTITE_ORE,
ItemID.MITHRIL_ORE, ItemID.GOLD_ORE, ItemID.COAL, ItemID.GOLDEN_NUGGET);
private static final Set<Integer> ROCK_OBSTACLES = ImmutableSet.of(ROCKFALL, ROCKFALL_26680);
private static final int SACK_LARGE_SIZE = 162;
private static final int SACK_SIZE = 81;
@Inject
private MotherlodeOverlay overlay;
@@ -83,6 +98,19 @@ public class MotherlodePlugin extends Plugin
@Inject
private MotherlodeConfig config;
@Inject
private Client client;
@Getter(AccessLevel.PACKAGE)
private boolean inMlm;
@Getter(AccessLevel.PACKAGE)
private int curSackSize;
@Getter(AccessLevel.PACKAGE)
private int maxSackSize;
@Getter(AccessLevel.PACKAGE)
private Integer depositsLeft;
private final MotherlodeSession session = new MotherlodeSession();
@Getter(AccessLevel.PACKAGE)
@@ -114,9 +142,25 @@ public class MotherlodePlugin extends Plugin
return session;
}
@Subscribe
public void onVarbitChanged(VarbitChanged event)
{
if (inMlm)
{
curSackSize = client.getSetting(Varbits.SACK_NUMBER);
boolean sackUpgraded = client.getSetting(Varbits.SACK_UPGRADED) == 1;
maxSackSize = sackUpgraded ? SACK_LARGE_SIZE : SACK_SIZE;
}
}
@Subscribe
public void onChatMessage(ChatMessage event)
{
if (!inMlm)
{
return;
}
if (event.getType() == ChatMessageType.FILTERED)
{
if (event.getMessage().equals("You manage to mine some pay-dirt."))
@@ -132,6 +176,13 @@ public class MotherlodePlugin extends Plugin
)
public void checkMining()
{
if (!inMlm)
{
return;
}
depositsLeft = calculateDepositsLeft();
Instant lastPayDirtMined = session.getLastPayDirtMined();
if (lastPayDirtMined == null)
{
@@ -149,8 +200,13 @@ public class MotherlodePlugin extends Plugin
}
@Subscribe
public void onWallObjectSpanwed(WallObjectSpawned event)
public void onWallObjectSpawned(WallObjectSpawned event)
{
if (!inMlm)
{
return;
}
WallObject wallObject = event.getWallObject();
if (MINE_SPOTS.contains(wallObject.getId()))
{
@@ -161,6 +217,11 @@ public class MotherlodePlugin extends Plugin
@Subscribe
public void onWallObjectChanged(WallObjectChanged event)
{
if (!inMlm)
{
return;
}
WallObject previous = event.getPrevious();
WallObject wallObject = event.getWallObject();
@@ -174,6 +235,11 @@ public class MotherlodePlugin extends Plugin
@Subscribe
public void onWallObjectDespawned(WallObjectDespawned event)
{
if (!inMlm)
{
return;
}
WallObject wallObject = event.getWallObject();
veins.remove(wallObject);
}
@@ -181,6 +247,11 @@ public class MotherlodePlugin extends Plugin
@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event)
{
if (!inMlm)
{
return;
}
GameObject gameObject = event.getGameObject();
if (ROCK_OBSTACLES.contains(gameObject.getId()))
{
@@ -191,6 +262,11 @@ public class MotherlodePlugin extends Plugin
@Subscribe
public void onGameObjectChanged(GameObjectChanged event)
{
if (!inMlm)
{
return;
}
GameObject previous = event.getPrevious();
GameObject gameObject = event.getGameObject();
@@ -205,10 +281,21 @@ public class MotherlodePlugin extends Plugin
@Subscribe
public void onGameObjectDespawned(GameObjectDespawned event)
{
if (!inMlm)
{
return;
}
GameObject gameObject = event.getGameObject();
rocks.remove(gameObject);
}
@Subscribe
public void onRegionChanged(MapRegionChanged event)
{
inMlm = checkInMlm();
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
@@ -218,5 +305,78 @@ public class MotherlodePlugin extends Plugin
veins.clear();
rocks.clear();
}
else if (event.getGameState() == GameState.LOGGED_IN)
{
inMlm = checkInMlm();
}
}
private Integer calculateDepositsLeft()
{
if (maxSackSize == 0) // check if maxSackSize has been initialized
{
return null;
}
double depositsLeft = 0;
int nonPayDirtItems = 0;
ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
if (inventory == null)
{
return null;
}
Item[] result = inventory.getItems();
assert result != null;
int inventorySize = result.length;
for (Item item : result)
{
// Assume that MLM ores are being banked and exclude them from the check,
// so the user doesn't see the Overlay switch between deposits left and N/A.
//
// Count other items at nonPayDirtItems so depositsLeft is calculated accordingly.
if (item.getId() != ItemID.PAYDIRT && item.getId() != -1 && !MLM_ORE_TYPES.contains(item.getId()))
{
nonPayDirtItems += 1;
}
}
double inventorySpace = inventorySize - nonPayDirtItems;
double sackSizeRemaining = maxSackSize - curSackSize;
if (inventorySpace > 0 && sackSizeRemaining > 0)
{
depositsLeft = Math.ceil(sackSizeRemaining / inventorySpace);
}
else if (inventorySpace == 0)
{
return null;
}
return (int) depositsLeft;
}
private boolean checkInMlm()
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return false;
}
int[] currentMapRegions = client.getMapRegions();
// Verify that all regions exist in MOTHERLODE_MAP_REGIONS
for (int region : currentMapRegions)
{
if (!MOTHERLODE_MAP_REGIONS.contains(region))
{
return false;
}
}
return true;
}
}

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Lars <lars.oernlo@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -70,7 +71,7 @@ class MotherlodeRocksOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showRocks())
if (!config.showRocks() || !plugin.isInMlm())
{
return null;
}

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Lars <lars.oernlo@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,6 +28,7 @@ package net.runelite.client.plugins.motherlode;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Color;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
@@ -40,19 +42,27 @@ class MotherlodeSackOverlay extends Overlay
{
private final Client client;
private final MotherlodeConfig config;
private final MotherlodePlugin plugin;
private final PanelComponent panelComponent = new PanelComponent();
@Inject
MotherlodeSackOverlay(Client client, MotherlodeConfig config)
MotherlodeSackOverlay(Client client, MotherlodeConfig config, MotherlodePlugin plugin)
{
setPosition(OverlayPosition.TOP_LEFT);
this.client = client;
this.config = config;
this.plugin = plugin;
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!plugin.isInMlm())
{
return null;
}
Widget sack = client.getWidget(WidgetInfo.MOTHERLODE_MINE);
panelComponent.getLines().clear();
@@ -65,7 +75,21 @@ class MotherlodeSackOverlay extends Overlay
{
panelComponent.getLines().add(new PanelComponent.Line(
"Pay-dirt in sack:",
String.valueOf(client.getSetting(Varbits.SACK_NUMBER))
Color.WHITE,
String.valueOf(client.getSetting(Varbits.SACK_NUMBER)),
plugin.getCurSackSize() >= plugin.getMaxSackSize() ? Color.RED : Color.WHITE
));
}
if (config.showDepositsLeft())
{
Integer depositsLeft = plugin.getDepositsLeft();
panelComponent.getLines().add(new PanelComponent.Line(
"Deposits left:",
Color.WHITE,
depositsLeft == null ? "N/A" : String.valueOf(depositsLeft),
depositsLeft == null ? Color.WHITE : (depositsLeft == 0 ? Color.RED : Color.WHITE)
));
}
}