client: add mining plugin

Shows progress indicators for respawn times on all rocks that can be mined.

Co-authored-by: Barragek0 <barragek0lol@gmail.com>
This commit is contained in:
Adam
2019-05-31 18:02:52 -04:00
committed by Adam
parent 417e48fc7e
commit aeaa2850ee
4 changed files with 433 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* 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 java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.time.Instant;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
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.components.ProgressPieComponent;
class MiningOverlay extends Overlay
{
private final Client client;
private final MiningPlugin plugin;
@Inject
private MiningOverlay(Client client, MiningPlugin plugin)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.plugin = plugin;
this.client = client;
}
@Override
public Dimension render(Graphics2D graphics)
{
List<RockRespawn> respawns = plugin.getRespawns();
if (respawns.isEmpty())
{
return null;
}
Instant now = Instant.now();
for (Iterator<RockRespawn> it = respawns.iterator(); it.hasNext();)
{
RockRespawn rockRespawn = it.next();
float percent = (now.toEpochMilli() - rockRespawn.getStartTime().toEpochMilli()) / (float) rockRespawn.getRespawnTime();
WorldPoint worldPoint = rockRespawn.getWorldPoint();
LocalPoint loc = LocalPoint.fromWorld(client, worldPoint);
if (loc == null || percent > 1.0f)
{
it.remove();
continue;
}
Point point = Perspective.localToCanvas(client, loc, client.getPlane());
if (point == null)
{
it.remove();
continue;
}
ProgressPieComponent ppc = new ProgressPieComponent();
ppc.setBorderColor(Color.ORANGE);
ppc.setFill(Color.YELLOW);
ppc.setPosition(point);
ppc.setProgress(percent);
ppc.render(graphics);
}
return null;
}
}

View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* 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 java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import static net.runelite.api.ObjectID.DEPLETED_VEIN_26665;
import static net.runelite.api.ObjectID.DEPLETED_VEIN_26666;
import static net.runelite.api.ObjectID.DEPLETED_VEIN_26667;
import static net.runelite.api.ObjectID.DEPLETED_VEIN_26668;
import static net.runelite.api.ObjectID.EMPTY_WALL;
import net.runelite.api.WallObject;
import net.runelite.api.events.GameObjectDespawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.WallObjectSpawned;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@Slf4j
@PluginDescriptor(
name = "Mining",
description = "Show ore respawn timers",
tags = {"overlay", "skilling", "timers"},
enabledByDefault = false
)
public class MiningPlugin extends Plugin
{
private static final int ROCK_DISTANCE = 14;
private static final int MINING_GUILD_REGION = 12183;
@Inject
private Client client;
@Inject
private OverlayManager overlayManager;
@Inject
private MiningOverlay overlay;
@Getter(AccessLevel.PACKAGE)
private final List<RockRespawn> respawns = new ArrayList<>();
private boolean recentlyLoggedIn;
@Override
protected void startUp()
{
overlayManager.add(overlay);
}
@Override
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
respawns.clear();
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
switch (event.getGameState())
{
case LOADING:
case HOPPING:
respawns.clear();
break;
case LOGGED_IN:
// After login rocks that are depleted will be changed,
// so wait for the next game tick before watching for
// rocks to deplete
recentlyLoggedIn = true;
break;
}
}
@Subscribe
public void onGameTick(GameTick gameTick)
{
recentlyLoggedIn = false;
}
@Subscribe
public void onGameObjectDespawned(GameObjectDespawned event)
{
if (client.getGameState() != GameState.LOGGED_IN || recentlyLoggedIn)
{
return;
}
final GameObject object = event.getGameObject();
Rock rock = Rock.getRock(object.getId());
if (rock != null)
{
RockRespawn rockRespawn = new RockRespawn(rock, object.getWorldLocation(), Instant.now(), (int) rock.getRespawnTime(inMiningGuild()).toMillis());
respawns.add(rockRespawn);
}
}
@Subscribe
public void onWallObjectSpawned(WallObjectSpawned event)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
final WallObject object = event.getWallObject();
switch (object.getId())
{
case EMPTY_WALL:
{
Rock rock = Rock.AMETHYST;
RockRespawn rockRespawn = new RockRespawn(rock, object.getWorldLocation(), Instant.now(), (int) rock.getRespawnTime(inMiningGuild()).toMillis());
respawns.add(rockRespawn);
break;
}
case DEPLETED_VEIN_26665: // Depleted motherlode vein
case DEPLETED_VEIN_26666: // Depleted motherlode vein
case DEPLETED_VEIN_26667: // Depleted motherlode vein
case DEPLETED_VEIN_26668: // Depleted motherlode vein
{
Rock rock = Rock.ORE_VEIN;
RockRespawn rockRespawn = new RockRespawn(rock, object.getWorldLocation(), Instant.now(), (int) rock.getRespawnTime(inMiningGuild()).toMillis());
respawns.add(rockRespawn);
break;
}
}
}
private boolean inMiningGuild()
{
return client.getLocalPlayer().getWorldLocation().getRegionID() == MINING_GUILD_REGION;
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* 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.ImmutableMap;
import java.time.Duration;
import java.util.Map;
import static net.runelite.api.ObjectID.ROCKS_11161;
import static net.runelite.api.ObjectID.ROCKS_11360;
import static net.runelite.api.ObjectID.ROCKS_11361;
import static net.runelite.api.ObjectID.ROCKS_11364;
import static net.runelite.api.ObjectID.ROCKS_11365;
import static net.runelite.api.ObjectID.ROCKS_11366;
import static net.runelite.api.ObjectID.ROCKS_11367;
import static net.runelite.api.ObjectID.ROCKS_11369;
import static net.runelite.api.ObjectID.ROCKS_11370;
import static net.runelite.api.ObjectID.ROCKS_11371;
import static net.runelite.api.ObjectID.ROCKS_11372;
import static net.runelite.api.ObjectID.ROCKS_11373;
import static net.runelite.api.ObjectID.ROCKS_11374;
import static net.runelite.api.ObjectID.ROCKS_11375;
import static net.runelite.api.ObjectID.ROCKS_11376;
import static net.runelite.api.ObjectID.ROCKS_11377;
enum Rock
{
TIN(Duration.ofMillis(2300), ROCKS_11360, ROCKS_11361),
COPPER(Duration.ofMillis(2200), ROCKS_11161),
IRON(Duration.ofMillis(5300), ROCKS_11364, ROCKS_11365)
{
@Override
Duration getRespawnTime(boolean inMiningGuild)
{
return inMiningGuild ? Duration.ofMillis(2200) : super.respawnTime;
}
},
COAL(Duration.ofSeconds(40), ROCKS_11366, ROCKS_11367)
{
@Override
Duration getRespawnTime(boolean inMiningGuild)
{
return inMiningGuild ? Duration.ofMillis(14_500) : super.respawnTime;
}
},
SILVER(Duration.ofMinutes(1), ROCKS_11369),
GOLD(Duration.ofMinutes(1), ROCKS_11370, ROCKS_11371),
MITHRIL(Duration.ofMinutes(2), ROCKS_11372, ROCKS_11373)
{
@Override
Duration getRespawnTime(boolean inMiningGuild)
{
return inMiningGuild ? Duration.ofMinutes(1) : super.respawnTime;
}
},
ADAMANTITE(Duration.ofMinutes(4), ROCKS_11374, ROCKS_11375)
{
@Override
Duration getRespawnTime(boolean inMiningGuild)
{
return inMiningGuild ? Duration.ofMinutes(2) : super.respawnTime;
}
},
RUNITE(Duration.ofMinutes(12), ROCKS_11376, ROCKS_11377)
{
@Override
Duration getRespawnTime(boolean inMiningGuild)
{
return inMiningGuild ? Duration.ofMinutes(6) : super.respawnTime;
}
},
ORE_VEIN(Duration.ofSeconds(108)),
AMETHYST(Duration.ofSeconds(75));
private static final Map<Integer, Rock> ROCKS;
static
{
ImmutableMap.Builder<Integer, Rock> builder = new ImmutableMap.Builder<>();
for (Rock rock : values())
{
for (int id : rock.ids)
{
builder.put(id, rock);
}
}
ROCKS = builder.build();
}
private final Duration respawnTime;
private final int[] ids;
Rock(Duration respawnTime, int... ids)
{
this.respawnTime = respawnTime;
this.ids = ids;
}
Duration getRespawnTime(boolean inMiningGuild)
{
return respawnTime;
}
static Rock getRock(int id)
{
return ROCKS.get(id);
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* 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 java.time.Instant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.api.coords.WorldPoint;
@AllArgsConstructor
@Getter
class RockRespawn
{
private final Rock rock;
private final WorldPoint worldPoint;
private final Instant startTime;
private final int respawnTime;
}