Initial Mining Plugin (copy of mlm)

This commit is contained in:
Nick Kroeger
2019-01-19 17:35:32 -05:00
parent 01fbcde008
commit 72b1867382
5 changed files with 938 additions and 0 deletions

View File

@@ -0,0 +1,429 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* 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
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.mining;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.*;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.*;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.motherlode.MotherlodeConfig;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.overlay.OverlayManager;
import javax.inject.Inject;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;
import static net.runelite.api.ObjectID.*;
@PluginDescriptor(
name = "Motherlode Mine",
description = "Show helpful information inside the Motherload Mine",
tags = {"pay", "dirt", "mining", "mlm", "skilling", "overlay"},
enabledByDefault = false
)
public class MiningPlugin extends Plugin
{
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 MAX_INVENTORY_SIZE = 28;
// private static final int SACK_LARGE_SIZE = 162;
// private static final int SACK_SIZE = 81;
//
// private static final int UPPER_FLOOR_HEIGHT = -500;
@Inject
private OverlayManager overlayManager;
@Inject
private MotherlodeOverlay overlay;
@Inject
private MiningRocksOverlay rocksOverlay;
@Inject
private MotherlodeConfig config;
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@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 MiningSession session;
@Getter(AccessLevel.PACKAGE)
private final Set<WallObject> veins = new HashSet<>();
@Getter(AccessLevel.PACKAGE)
private final Set<GameObject> rocks = new HashSet<>();
@Provides
MotherlodeConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(MotherlodeConfig.class);
}
@Override
protected void startUp()
{
overlayManager.add(overlay);
overlayManager.add(rocksOverlay);
// overlayManager.add(motherlodeGemOverlay);
// overlayManager.add(motherlodeSackOverlay);
session = new MiningSession();
//inMlm = checkInMlm();
// if (inMlm)
// {
// clientThread.invokeLater(this::refreshSackValues);
// }
}
@Override
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
overlayManager.remove(rocksOverlay);
// overlayManager.remove(motherlodeGemOverlay);
// overlayManager.remove(motherlodeSackOverlay);
session = null;
// veins.clear();
rocks.clear();
// Widget sack = client.getWidget(WidgetInfo.MOTHERLODE_MINE);
// clientThread.invokeLater(() ->
// {
// if (sack != null && sack.isHidden())
// {
// sack.setHidden(false);
// }
// });
}
public MiningSession getSession()
{
return session;
}
// @Subscribe
// public void onVarbitChanged(VarbitChanged event)
// {
// if (inMlm)
// {
// refreshSackValues();
// }
// }
// @Subscribe
// public void onChatMessage(ChatMessage event)
// {
// if (!inMlm || event.getType() != ChatMessageType.FILTERED)
// {
// return;
// }
//
// String chatMessage = event.getMessage();
//
// switch (chatMessage)
// {
// case "You manage to mine some pay-dirt.":
// session.incrementPayDirtMined();
// break;
//
// case "You just found a Diamond!":
// session.incrementGemFound(ItemID.UNCUT_DIAMOND);
// break;
//
// case "You just found a Ruby!":
// session.incrementGemFound(ItemID.UNCUT_RUBY);
// break;
//
// case "You just found an Emerald!":
// session.incrementGemFound(ItemID.UNCUT_EMERALD);
// break;
//
// case "You just found a Sapphire!":
// session.incrementGemFound(ItemID.UNCUT_SAPPHIRE);
// break;
// }
// }
@Schedule(
period = 1,
unit = ChronoUnit.SECONDS
)
// public void checkMining()
// {
// if (!inMlm)
// {
// return;
// }
//
// depositsLeft = calculateDepositsLeft();
//
// Instant lastPayDirtMined = session.getLastPayDirtMined();
// if (lastPayDirtMined == null)
// {
// return;
// }
//
// // reset recentPayDirtMined if you haven't mined anything recently
// Duration statTimeout = Duration.ofMinutes(config.statTimeout());
// Duration sinceMined = Duration.between(lastPayDirtMined, Instant.now());
//
// if (sinceMined.compareTo(statTimeout) >= 0)
// {
// session.resetRecent();
// }
// }
// @Subscribe
// public void onWallObjectSpawned(WallObjectSpawned event)
// {
// if (!inMlm)
// {
// return;
// }
//
// WallObject wallObject = event.getWallObject();
// if (MINE_SPOTS.contains(wallObject.getId()))
// {
// veins.add(wallObject);
// }
// }
//
// @Subscribe
// public void onWallObjectChanged(WallObjectChanged event)
// {
// if (!inMlm)
// {
// return;
// }
//
// WallObject previous = event.getPrevious();
// WallObject wallObject = event.getWallObject();
//
// veins.remove(previous);
// if (MINE_SPOTS.contains(wallObject.getId()))
// {
// veins.add(wallObject);
// }
// }
//
// @Subscribe
// public void onWallObjectDespawned(WallObjectDespawned event)
// {
// if (!inMlm)
// {
// return;
// }
//
// WallObject wallObject = event.getWallObject();
// veins.remove(wallObject);
// }
@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event)
{
if (!inMlm)
{
return;
}
GameObject gameObject = event.getGameObject();
if (ROCK_OBSTACLES.contains(gameObject.getId()))
{
rocks.add(gameObject);
}
}
// @Subscribe
// public void onGameObjectChanged(GameObjectChanged event)
// {
// if (!inMlm)
// {
// return;
// }
//
// GameObject previous = event.getPrevious();
// GameObject gameObject = event.getGameObject();
//
// rocks.remove(previous);
// if (ROCK_OBSTACLES.contains(gameObject.getId()))
// {
// rocks.add(gameObject);
// }
//
// }
//
// @Subscribe
// public void onGameObjectDespawned(GameObjectDespawned event)
// {
// if (!inMlm)
// {
// return;
// }
//
// GameObject gameObject = event.getGameObject();
// rocks.remove(gameObject);
// }
// @Subscribe
// public void onGameStateChanged(GameStateChanged event)
// {
// if (event.getGameState() == GameState.LOADING)
// {
// // on region changes the tiles get set to null
// veins.clear();
// rocks.clear();
// }
// else if (event.getGameState() == GameState.LOGGED_IN)
// {
// inMlm = checkInMlm();
// }
// else if (event.getGameState() == GameState.LOGIN_SCREEN)
// {
// // Prevent code from running while logged out.
// inMlm = false;
// }
// }
// private Integer calculateDepositsLeft()
// {
// if (maxSackSize == 0) // check if maxSackSize has been initialized
// {
// refreshSackValues();
// }
//
// double depositsLeft = 0;
// int nonPayDirtItems = 0;
//
// ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
// if (inventory == null)
// {
// return null;
// }
//
// Item[] result = inventory.getItems();
// assert result != null;
//
// 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 = MAX_INVENTORY_SIZE - 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;
// }
//
// private void refreshSackValues()
// {
// curSackSize = client.getVar(Varbits.SACK_NUMBER);
// boolean sackUpgraded = client.getVar(Varbits.SACK_UPGRADED) == 1;
// maxSackSize = sackUpgraded ? SACK_LARGE_SIZE : SACK_SIZE;
// }
//
// /**
// * Checks if the given point is "upstairs" in the mlm.
// * The upper floor is actually on z=0.
// * @param localPoint
// * @return
// */
// boolean isUpstairs(LocalPoint localPoint)
// {
// return Perspective.getTileHeight(client, localPoint, 0) < UPPER_FLOOR_HEIGHT;
// }
}

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* 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
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.mining;
import net.runelite.api.Point;
import net.runelite.api.*;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.game.SkillIconManager;
import net.runelite.client.plugins.motherlode.MotherlodeConfig;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import javax.inject.Inject;
import java.awt.*;
import java.awt.image.BufferedImage;
class MiningRocksOverlay extends Overlay
{
private static final int MAX_DISTANCE = 2350;
private final Client client;
private final MiningPlugin plugin;
private final MotherlodeConfig config;
private final BufferedImage miningIcon;
@Inject
MiningRocksOverlay(Client client, MiningPlugin plugin, MotherlodeConfig config, SkillIconManager iconManager)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.client = client;
this.plugin = plugin;
this.config = config;
miningIcon = iconManager.getSkillImage(Skill.MINING);
}
@Override
public Dimension render(Graphics2D graphics)
{
if ((!config.showVeins() && !config.showRockFalls()) || !plugin.isInMlm())
{
return null;
}
Player local = client.getLocalPlayer();
renderTiles(graphics, local);
return null;
}
private void renderTiles(Graphics2D graphics, Player local)
{
LocalPoint localLocation = local.getLocalLocation();
// if (config.showVeins())
// {
// for (WallObject vein : plugin.getVeins())
// {
// LocalPoint location = vein.getLocalLocation();
// if (localLocation.distanceTo(location) <= MAX_DISTANCE)
// {
// // Only draw veins on the same level
// if (plugin.isUpstairs(localLocation) == plugin.isUpstairs(vein.getLocalLocation()))
// {
// renderVein(graphics, vein);
// }
// }
// }
// }
if (config.showRockFalls())
{
for (GameObject rock : plugin.getRocks())
{
LocalPoint location = rock.getLocalLocation();
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
{
renderRock(graphics, rock);
}
}
}
}
private void renderVein(Graphics2D graphics, WallObject vein)
{
Point canvasLoc = Perspective.getCanvasImageLocation(client, vein.getLocalLocation(), miningIcon, 150);
if (canvasLoc != null)
{
graphics.drawImage(miningIcon, canvasLoc.getX(), canvasLoc.getY(), null);
}
}
private void renderRock(Graphics2D graphics, GameObject rock)
{
Polygon poly = Perspective.getCanvasTilePoly(client, rock.getLocalLocation());
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.red);
}
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.mining;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ItemID;
import java.time.Duration;
import java.time.Instant;
@Slf4j
public class MiningSession
{
private static final Duration HOUR = Duration.ofHours(1);
private int perHour;
private Instant lastPayDirtMined;
private int totalMined;
private Instant recentPayDirtMined;
private int recentMined;
@Getter(AccessLevel.PACKAGE)
private Instant lastGemFound;
@Getter(AccessLevel.PACKAGE)
private int diamondsFound;
@Getter(AccessLevel.PACKAGE)
private int rubiesFound;
@Getter(AccessLevel.PACKAGE)
private int emeraldsFound;
@Getter(AccessLevel.PACKAGE)
private int sapphiresFound;
public void incrementGemFound(int gemID)
{
lastGemFound = Instant.now();
switch (gemID)
{
case ItemID.UNCUT_DIAMOND:
diamondsFound++;
break;
case ItemID.UNCUT_RUBY:
rubiesFound++;
break;
case ItemID.UNCUT_EMERALD:
emeraldsFound++;
break;
case ItemID.UNCUT_SAPPHIRE:
sapphiresFound++;
break;
default:
log.error("Invalid gem type specified. The gem count will not be incremented.");
}
}
public void incrementPayDirtMined()
{
Instant now = Instant.now();
lastPayDirtMined = now;
++totalMined;
if (recentMined == 0)
{
recentPayDirtMined = now;
}
++recentMined;
Duration timeSinceStart = Duration.between(recentPayDirtMined, now);
if (!timeSinceStart.isZero())
{
perHour = (int) ((double) recentMined * (double) HOUR.toMillis() / (double) timeSinceStart.toMillis());
}
}
public void resetRecent()
{
recentPayDirtMined = null;
recentMined = 0;
}
public int getPerHour()
{
return perHour;
}
public Instant getLastPayDirtMined()
{
return lastPayDirtMined;
}
public int getTotalMined()
{
return totalMined;
}
public Instant getRecentPayDirtMined()
{
return recentPayDirtMined;
}
public int getRecentMined()
{
return recentMined;
}
}

View File

@@ -0,0 +1,114 @@
/*
* 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
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.mining;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("motherlode")
public interface MotherlodeConfig extends Config
{
@ConfigItem(
keyName = "showVeins",
name = "Show pay-dirt mining spots",
description = "Configures whether or not the pay-dirt mining spots are displayed."
)
default boolean showVeins()
{
return true;
}
@ConfigItem(
keyName = "showRocks",
name = "Show rocks obstacles",
description = "Configures whether or not the fallen rocks obstacles are displayed."
)
default boolean showRockFalls()
{
return true;
}
@ConfigItem(
keyName = "statTimeout",
name = "Reset stats (minutes)",
description = "Configures the time until statistics are reset"
)
default int statTimeout()
{
return 5;
}
@ConfigItem(
keyName = "showSack",
name = "Show pay-dirt sack",
description = "Configures whether the pay-dirt sack is displayed or not."
)
default boolean showSack()
{
return true;
}
@ConfigItem(
keyName = "showMiningStats",
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;
}
@ConfigItem(
keyName = "showGemsFound",
name = "Show gems found",
description = "Shows gems found during current mining session"
)
default boolean showGemsFound()
{
return true;
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2018, Seth <Sethtroll3@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.mining;
import com.google.common.collect.ImmutableSet;
import net.runelite.api.Client;
import net.runelite.client.plugins.motherlode.MotherlodeConfig;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
import javax.inject.Inject;
import java.awt.*;
import java.time.Duration;
import java.time.Instant;
import java.util.Set;
import static net.runelite.api.AnimationID.*;
class MotherlodeOverlay extends Overlay
{
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,
MINING_MOTHERLODE_INFERNAL
);
private final Client client;
private final MiningPlugin plugin;
private final MotherlodeConfig config;
private final PanelComponent panelComponent = new PanelComponent();
@Inject
MotherlodeOverlay(Client client, MiningPlugin plugin, MotherlodeConfig config)
{
setPosition(OverlayPosition.TOP_LEFT);
this.client = client;
this.plugin = plugin;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!plugin.isInMlm() || !config.showMiningStats())
{
return null;
}
MiningSession session = plugin.getSession();
if (session.getLastPayDirtMined() == null)
{
return null;
}
Duration statTimeout = Duration.ofMinutes(config.statTimeout());
Duration sinceCut = Duration.between(session.getLastPayDirtMined(), Instant.now());
if (sinceCut.compareTo(statTimeout) >= 0)
{
return null;
}
panelComponent.getChildren().clear();
if (config.showMiningState())
{
if (MINING_ANIMATION_IDS.contains(client.getLocalPlayer().getAnimation()))
{
panelComponent.getChildren().add(TitleComponent.builder()
.text("Mining")
.color(Color.GREEN)
.build());
}
else
{
panelComponent.getChildren().add(TitleComponent.builder()
.text("NOT mining")
.color(Color.RED)
.build());
}
}
panelComponent.getChildren().add(LineComponent.builder()
.left("Pay-dirt mined:")
.right(Integer.toString(session.getTotalMined()))
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Pay-dirt/hr:")
.right(session.getRecentMined() > 2 ? Integer.toString(session.getPerHour()) : "")
.build());
return panelComponent.render(graphics);
}
}