From 8e18bb6208ebc5f22e9d07e679d12445f9ae6718 Mon Sep 17 00:00:00 2001 From: lordzuku <47382776+lordzuku@users.noreply.github.com> Date: Thu, 29 Aug 2019 16:10:30 -0400 Subject: [PATCH] dropparty: add (#1433) --- .../plugins/dropparty/DropPartyConfig.java | 95 ++++++++ .../plugins/dropparty/DropPartyOverlay.java | 119 ++++++++++ .../plugins/dropparty/DropPartyPlugin.java | 212 ++++++++++++++++++ .../src/main/resources/npc_stats.json | 2 +- 4 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyPlugin.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyConfig.java new file mode 100644 index 0000000000..9a106d0bdf --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyConfig.java @@ -0,0 +1,95 @@ +package net.runelite.client.plugins.dropparty; + +import java.awt.Color; +import java.awt.Font; +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Range; + +@ConfigGroup("drop") +public interface DropPartyConfig extends Config +{ + @Getter + @AllArgsConstructor + enum FontStyle + { + BOLD("Bold", Font.BOLD), + ITALIC("Italic", Font.ITALIC), + PLAIN("Plain", Font.PLAIN); + + private String name; + private int font; + + @Override + public String toString() + { + return getName(); + } + } + + @ConfigItem( + keyName = "playerName", + name = "Dropping player:", + description = "selects what players name to mark tiles", + position = 0 + ) + default String playerName() + { + return ""; + } + + @Range( + min = 1, + max = 40 + ) + @ConfigItem( + keyName = "showAmmount", + name = "Trail length", + description = "Shows the legnth of the droppers trail", + position = 1 + ) + default int showAmmount() + { + return 10; + } + + @ConfigItem( + position = 2, + keyName = "overlayColor", + name = "Overlay Color", + description = "Configures the color of the overlay" + ) + default Color overlayColor() + { + return new Color(0, 150, 200); + } + + @ConfigItem( + position = 3, + keyName = "fontStyle", + name = "Font Style", + description = "Bold/Italics/Plain" + ) + default FontStyle fontStyle() + { + return FontStyle.BOLD; + } + + @Range( + min = 10, + max = 40 + ) + @ConfigItem( + position = 4, + keyName = "textSize", + name = "Text Size", + description = "Text Size for Timers." + ) + default int textSize() + { + return 18; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyOverlay.java new file mode 100644 index 0000000000..a00bb4c4e8 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyOverlay.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * + * Modified by farhan1666 + * + * 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.dropparty; + +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.OverlayUtil; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import static net.runelite.client.util.ColorUtil.setAlphaComponent; + +@Singleton +public class DropPartyOverlay extends Overlay +{ + private static final int FILL_START_ALPHA = 25; + private static final int OUTLINE_START_ALPHA = 255; + + private final Client client; + private final DropPartyPlugin plugin; + + @Inject + public DropPartyOverlay(final Client client, final DropPartyPlugin plugin) + { + setPosition(OverlayPosition.DYNAMIC); + setLayer(OverlayLayer.UNDER_WIDGETS); + this.client = client; + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics) + { + int tiles = plugin.getShowAmmount(); + if (tiles == 0) + { + return null; + } + final List path = plugin.getPlayerPath(); + + final List markedTiles = new ArrayList<>(); + + for (int i = 0; i < path.size(); i++) + { + if (i > plugin.getMAXPATHSIZE() || i > (plugin.getShowAmmount() - 1)) + { + break; + } + if (path.get(i) != null) + { + final LocalPoint local = LocalPoint.fromWorld(client, path.get(i)); + Polygon tilePoly = null; + if (local != null) + { + continue; + } + tilePoly = Perspective.getCanvasTileAreaPoly(client, local, 1); + + if (tilePoly != null) + { + if (!markedTiles.contains(path.get(i))) + { + graphics.setColor(new Color(setAlphaComponent(plugin.getOverlayColor().getRGB(), OUTLINE_START_ALPHA), true)); + graphics.drawPolygon(tilePoly); + OverlayUtil.renderTextLocation(graphics, Integer.toString(i + 1), plugin.getTextSize(), + plugin.getFontStyle(), Color.WHITE, centerPoint(tilePoly.getBounds()), true, 0); + } + markedTiles.add(path.get(i)); + } + + } + } + + + return null; + } + + private Point centerPoint(Rectangle rect) + { + int x = (int) (rect.getX() + rect.getWidth() / 2); + int y = (int) (rect.getY() + rect.getHeight() / 2); + return new Point(x, y); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyPlugin.java new file mode 100644 index 0000000000..7ef79cb850 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/dropparty/DropPartyPlugin.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * + * Modified by farhan1666 + * + * 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.dropparty; + +import com.google.inject.Provides; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.Player; +import net.runelite.api.coords.WorldPoint; +import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.GameTick; +import net.runelite.client.Notifier; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.eventbus.EventBus; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.PluginType; +import net.runelite.client.ui.overlay.OverlayManager; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + + +@PluginDescriptor( + name = "Drop Party", + description = "Marks where a user ran, for drop partys", + tags = {"Drop", "Party", "marker", "player"}, + type = PluginType.UTILITY, + enabledByDefault = false +) +@Singleton +@Slf4j +public class DropPartyPlugin extends Plugin +{ + @Inject + private DropPartyConfig config; + @Getter(AccessLevel.PACKAGE) + private List playerPath = new ArrayList<>(); + @Getter(AccessLevel.PACKAGE) + private String playerName = ""; + @Getter(AccessLevel.PACKAGE) + private int showAmmount = 0; + @Getter(AccessLevel.PACKAGE) + private int MAXPATHSIZE = 100; + private Player runningPlayer; + @Getter(AccessLevel.PACKAGE) + private Color overlayColor; + + @Inject + private Notifier notifier; + @Inject + private OverlayManager overlayManager; + @Inject + private DropPartyOverlay coreOverlay; + @Inject + private EventBus eventbus; + @Inject + private Client client; + @Getter(AccessLevel.PACKAGE) + private int fontStyle; + @Getter(AccessLevel.PACKAGE) + private int textSize; + + @Provides + DropPartyConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(DropPartyConfig.class); + } + + @Override + protected void startUp() + { + updateConfig(); + addSubscriptions(); + overlayManager.add(coreOverlay); + reset(); + } + + @Override + protected void shutDown() + { + overlayManager.remove(coreOverlay); + reset(); + eventbus.unregister(this); + } + + private void addSubscriptions() + { + eventbus.subscribe(ConfigChanged.class, this, this::onConfigChanged); + eventbus.subscribe(GameTick.class, this, this::onGameTick); + } + + + private void onGameTick(GameTick event) + { + shuffleList(); + if (playerName.equalsIgnoreCase("")) + { + return; + } + + runningPlayer = null; + + for (Player player : client.getPlayers()) + { + if (player.getName() == null) + { + continue; + } + if (player.getName().equalsIgnoreCase(playerName)) + { + runningPlayer = player; + break; + } + + } + + if (runningPlayer == null) + { + cordsError(); + return; + } + addCords(); + } + + private void cordsError() + { + playerPath.add(null); + + } + + private void shuffleList() + { + if (playerPath.size() > MAXPATHSIZE - 1) + { + playerPath.remove(0); + } + } + + private void addCords() + { + while (true) + { + if (playerPath.size() >= MAXPATHSIZE) + { + playerPath.add(runningPlayer.getWorldLocation()); + break; + } + playerPath.add(null); + + } + + + } + + private void onConfigChanged(ConfigChanged event) + { + if (!event.getGroup().equals("drop")) + { + return; + } + + updateConfig(); + } + + + private void reset() + { + playerPath.clear(); + + } + + + private void updateConfig() + { + this.playerName = config.playerName(); + this.showAmmount = config.showAmmount(); + this.overlayColor = config.overlayColor(); + this.fontStyle = config.fontStyle().getFont(); + this.textSize = config.textSize(); + } +} diff --git a/runelite-client/src/main/resources/npc_stats.json b/runelite-client/src/main/resources/npc_stats.json index 58e7b58126..dfd9ffe5e6 100644 --- a/runelite-client/src/main/resources/npc_stats.json +++ b/runelite-client/src/main/resources/npc_stats.json @@ -38178,4 +38178,4 @@ "bonusStrength": 28, "bonusRangeStrength": 28 } -} \ No newline at end of file +}