Merge pull request #4320 from jkybtw/minnow-plugin

fishing plugin: add minnows overlay
This commit is contained in:
Adam
2018-07-28 20:33:26 -04:00
committed by GitHub
4 changed files with 174 additions and 22 deletions

View File

@@ -34,7 +34,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showIcons",
name = "Display Fish icons",
description = "Configures whether icons or text is displayed"
description = "Configures whether icons or text is displayed",
position = 1
)
default boolean showIcons()
{
@@ -44,7 +45,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "statTimeout",
name = "Reset stats (minutes)",
description = "Configures the time until statistic is reset"
description = "Configures the time until statistic is reset",
position = 2
)
default int statTimeout()
{
@@ -54,7 +56,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showShrimp",
name = "Show Shrimp/Anchovies",
description = "Configures whether shrimp/anchovies is displayed"
description = "Configures whether shrimp/anchovies is displayed",
position = 3
)
default boolean showShrimp()
{
@@ -64,7 +67,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showLobster",
name = "Show Lobster/Swordfish/Tuna",
description = "Configures whether lobster/swordfish/tuna is displayed"
description = "Configures whether lobster/swordfish/tuna is displayed",
position = 4
)
default boolean showLobster()
{
@@ -74,7 +78,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showShark",
name = "Show Shark",
description = "Configures whether shark is displayed"
description = "Configures whether shark is displayed",
position = 5
)
default boolean showShark()
{
@@ -84,7 +89,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showMonkfish",
name = "Show Monkfish",
description = "Configures whether monkfish displayed"
description = "Configures whether monkfish displayed",
position = 6
)
default boolean showMonkfish()
{
@@ -94,7 +100,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showSalmon",
name = "Show Salmon/Trout",
description = "Configures whether salmon/trout is displayed"
description = "Configures whether salmon/trout is displayed",
position = 7
)
default boolean showSalmon()
{
@@ -104,7 +111,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showBarb",
name = "Show Barbarian fish",
description = "Configures whether barbarian fish is displayed"
description = "Configures whether barbarian fish is displayed",
position = 8
)
default boolean showBarb()
{
@@ -114,7 +122,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showAngler",
name = "Show Anglerfish",
description = "Configures whether anglerfish is displayed"
description = "Configures whether anglerfish is displayed",
position = 9
)
default boolean showAngler()
{
@@ -124,7 +133,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showMinnow",
name = "Show Minnow fish",
description = "Configures whether minnow fish is displayed"
description = "Configures whether minnow fish is displayed",
position = 10
)
default boolean showMinnow()
{
@@ -134,7 +144,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showInfernalEel",
name = "Show Infernal Eel",
description = "Configures whether infernal eel is displayed"
description = "Configures whether infernal eel is displayed",
position = 11
)
default boolean showInfernalEel()
{
@@ -144,7 +155,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showSacredEel",
name = "Show Sacred Eel",
description = "Configures whether sacred eel is displayed"
description = "Configures whether sacred eel is displayed",
position = 12
)
default boolean showSacredEel()
{
@@ -154,7 +166,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showCaveEel",
name = "Show Cave Eel",
description = "Configures whether cave eel is displayed"
description = "Configures whether cave eel is displayed",
position = 13
)
default boolean showCaveEel()
{
@@ -164,7 +177,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showSlimyEel",
name = "Show Slimy Eel",
description = "Configures whether slimy eel is displayed"
description = "Configures whether slimy eel is displayed",
position = 14
)
default boolean showSlimyEel()
{
@@ -174,7 +188,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showKarambwanji",
name = "Show Karambwanji",
description = "Configures whether karambwanji is displayed"
description = "Configures whether karambwanji is displayed",
position = 15
)
default boolean showKarambwanji()
{
@@ -184,7 +199,8 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showKarambwan",
name = "Show Karambwan",
description = "Configures whether karambwan is displayed"
description = "Configures whether karambwan is displayed",
position = 16
)
default boolean showKarambwan()
{
@@ -194,10 +210,22 @@ public interface FishingConfig extends Config
@ConfigItem(
keyName = "showFishingStats",
name = "Show Fishing session stats",
description = "Configures whether to display the fishing session stats"
description = "Configures whether to display the fishing session stats",
position = 17
)
default boolean showFishingStats()
{
return true;
}
@ConfigItem(
keyName = "showMinnowOverlay",
name = "Show Minnow Movement overlay",
description = "Configures whether to display the minnow progress pie overlay",
position = 18
)
default boolean showMinnowOverlay()
{
return true;
}
}

View File

@@ -28,14 +28,18 @@ package net.runelite.client.plugins.fishing;
import com.google.common.eventbus.Subscribe;
import com.google.common.primitives.Ints;
import com.google.inject.Provides;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.NPC;
@@ -43,6 +47,7 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
@@ -59,10 +64,14 @@ import net.runelite.client.util.QueryRunner;
)
@PluginDependency(XpTrackerPlugin.class)
@Singleton
@Slf4j
public class FishingPlugin extends Plugin
{
private final List<Integer> spotIds = new ArrayList<>();
@Getter(AccessLevel.PACKAGE)
private Map<Integer, MinnowSpot> minnowSpots = new HashMap<>();
@Getter(AccessLevel.PACKAGE)
private NPC[] fishingSpots;
@@ -110,6 +119,7 @@ public class FishingPlugin extends Plugin
overlayManager.remove(overlay);
overlayManager.remove(spotOverlay);
overlayManager.remove(fishingSpotMinimapOverlay);
minnowSpots.clear();
}
public FishingSession getSession()
@@ -199,7 +209,7 @@ public class FishingPlugin extends Plugin
}
@Subscribe
public void checkSpots(GameTick event)
public void onGameTick(GameTick event)
{
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
@@ -209,5 +219,43 @@ public class FishingPlugin extends Plugin
// -1 to make closer things draw last (on top of farther things)
Arrays.sort(spots, Comparator.comparing(npc -> -1 * npc.getLocalLocation().distanceTo(cameraPoint)));
fishingSpots = spots;
// process minnows
for (NPC npc : spots)
{
FishingSpot spot = FishingSpot.getSpot(npc.getId());
if (spot == null)
{
continue;
}
if (spot == FishingSpot.MINNOW && config.showMinnowOverlay())
{
int id = npc.getIndex();
MinnowSpot minnowSpot = minnowSpots.get(id);
// create the minnow spot if it doesn't already exist
if (minnowSpot == null)
{
minnowSpots.put(id, new MinnowSpot(npc.getWorldLocation(), Instant.now()));
}
// if moved, reset
else if (!minnowSpot.getLoc().equals(npc.getWorldLocation()))
{
minnowSpots.put(id, new MinnowSpot(npc.getWorldLocation(), Instant.now()));
}
}
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned npcDespawned)
{
NPC npc = npcDespawned.getNpc();
MinnowSpot minnowSpot = minnowSpots.remove(npc.getIndex());
if (minnowSpot != null)
{
log.debug("Minnow spot {} despawned", npc);
}
}
}

View File

@@ -28,30 +28,41 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GraphicID;
import net.runelite.api.NPC;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.game.ItemManager;
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 net.runelite.client.ui.overlay.components.ProgressPieComponent;
class FishingSpotOverlay extends Overlay
{
private static final Duration MINNOW_MOVE = Duration.ofSeconds(15);
private static final Duration MINNOW_WARN = Duration.ofSeconds(3);
private final FishingPlugin plugin;
private final FishingConfig config;
private final Client client;
private final ItemManager itemManager;
@Inject
ItemManager itemManager;
@Inject
public FishingSpotOverlay(FishingPlugin plugin, FishingConfig config)
private FishingSpotOverlay(FishingPlugin plugin, FishingConfig config, Client client, ItemManager itemManager)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.plugin = plugin;
this.config = config;
this.client = client;
this.itemManager = itemManager;
}
@Override
@@ -73,6 +84,33 @@ class FishingSpotOverlay extends Overlay
}
Color color = npc.getGraphic() == GraphicID.FLYING_FISH ? Color.RED : Color.CYAN;
if (spot == FishingSpot.MINNOW && config.showMinnowOverlay())
{
MinnowSpot minnowSpot = plugin.getMinnowSpots().get(npc.getIndex());
if (minnowSpot != null)
{
long millisLeft = MINNOW_MOVE.toMillis() - Duration.between(minnowSpot.getTime(), Instant.now()).toMillis();
if (millisLeft < MINNOW_WARN.toMillis())
{
color = Color.ORANGE;
}
LocalPoint localPoint = npc.getLocalLocation();
Point location = Perspective.worldToCanvas(client, localPoint.getX(), localPoint.getY(), client.getPlane());
if (location != null)
{
ProgressPieComponent pie = new ProgressPieComponent();
pie.setFill(color);
pie.setBorderColor(color);
pie.setPosition(location);
pie.setProgress((float) millisLeft / MINNOW_MOVE.toMillis());
pie.render(graphics);
}
}
}
if (config.showIcons())
{
BufferedImage fishImage = getFishImage(spot);

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018, 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.fishing;
import java.time.Instant;
import lombok.AllArgsConstructor;
import lombok.Value;
import net.runelite.api.coords.WorldPoint;
@AllArgsConstructor
@Value
class MinnowSpot
{
private final WorldPoint loc;
private final Instant time;
}