From 1261947a25c09c9f5c68577b427766c0772e9528 Mon Sep 17 00:00:00 2001 From: xKylee <48519776+xKylee@users.noreply.github.com> Date: Sat, 11 Jan 2020 05:59:36 +0000 Subject: [PATCH] templetrekking: add plugin templetrekking: add plugin --- .../TempleTrekkingBogOverlay.java | 67 +++++++++ .../templetrekking/TempleTrekkingConfig.java | 55 ++++++++ .../templetrekking/TempleTrekkingOverlay.java | 78 +++++++++++ .../templetrekking/TempleTrekkingPlugin.java | 132 ++++++++++++++++++ 4 files changed, 332 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingBogOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingPlugin.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingBogOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingBogOverlay.java new file mode 100644 index 0000000000..37d947df77 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingBogOverlay.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, Frosty Fridge + * 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.templetrekking; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Polygon; +import javax.inject.Inject; +import net.runelite.api.GroundObject; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.OverlayUtil; + +public class TempleTrekkingBogOverlay extends Overlay +{ + private static final Color GREEN = new Color(0, 200, 83); + private final TempleTrekkingConfig config; + private final TempleTrekkingPlugin plugin; + + @Inject + private TempleTrekkingBogOverlay(TempleTrekkingConfig config, TempleTrekkingPlugin plugin) + { + super(plugin); + this.config = config; + this.plugin = plugin; + setPosition(OverlayPosition.DYNAMIC); + setPriority(OverlayPriority.LOW); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (config.bogMapActive()) + { + for (GroundObject bog : plugin.getBogList()) + { + Polygon bogPoly = bog.getCanvasTilePoly(); + OverlayUtil.renderPolygon(graphics, bogPoly, GREEN); + } + } + return null; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingConfig.java new file mode 100644 index 0000000000..d0acd72aa5 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, Frosty Fridge + * 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.templetrekking; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("templetrekking") +public interface TempleTrekkingConfig extends Config +{ + @ConfigItem( + keyName = "bogMapActive", + name = "Bog Map", + description = "Marks out a safe route through the bog event", + position = 0 + ) + default boolean bogMapActive() + { + return true; + } + + @ConfigItem( + keyName = "pointTrackerActive", + name = "Point Tracker", + description = "Track your Temple Trek reward points, which determine the size of your reward.", + position = 1 + ) + default boolean pointTrackerActive() + { + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingOverlay.java new file mode 100644 index 0000000000..af6b2f7e54 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingOverlay.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Frosty Fridge + * 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.templetrekking; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.components.LineComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class TempleTrekkingOverlay extends Overlay +{ + private final TempleTrekkingConfig config; + private final TempleTrekkingPlugin plugin; + + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + private TempleTrekkingOverlay(TempleTrekkingConfig config, TempleTrekkingPlugin plugin) + { + super(plugin); + this.config = config; + this.plugin = plugin; + setPosition(OverlayPosition.TOP_LEFT); + setPriority(OverlayPriority.LOW); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (config.pointTrackerActive() && plugin.isInTrek()) + { + int points = plugin.getRewardPoints(); + double percentage = plugin.getRewardPercentage() * 100; + panelComponent.getChildren().clear(); + panelComponent.getChildren().add(LineComponent.builder() + .left("Trek Points: ") + .right(Integer.toString(points)) + .rightColor(percentage < 25 ? Color.RED : percentage >= 25 && percentage < 50 ? Color.YELLOW : + percentage >= 50 && percentage < 75 ? Color.BLUE : Color.GREEN) + .build()); + panelComponent.getChildren().add(LineComponent.builder() + .left("Reward %: ") + .right(String.format("%.2f", percentage) + "%") + .rightColor(percentage < 25 ? Color.RED : percentage >= 25 && percentage < 50 ? Color.YELLOW : + percentage >= 50 && percentage < 75 ? Color.BLUE : Color.GREEN) + .build()); + return panelComponent.render(graphics); + } + return null; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingPlugin.java new file mode 100644 index 0000000000..9d43d956d7 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/templetrekking/TempleTrekkingPlugin.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018, Frosty Fridge + * 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.templetrekking; + +import com.google.inject.Provides; +import java.util.HashSet; +import java.util.Set; +import javax.inject.Inject; +import lombok.Getter; +import net.runelite.api.Client; +import net.runelite.api.GroundObject; +import net.runelite.api.ObjectID; +import net.runelite.api.Varbits; +import net.runelite.api.events.GroundObjectSpawned; +import net.runelite.api.events.VarbitChanged; +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.PluginType; +import net.runelite.client.ui.overlay.OverlayManager; + +@PluginDescriptor( + name = "Temple Trekking", + description = "Helpers for the Temple Trek minigame", + tags = {"minigame", "overlay", "temple trek"}, + type = PluginType.MINIGAME +) +public class TempleTrekkingPlugin extends Plugin +{ + + @Getter + private final Set bogList = new HashSet(); + @Inject + private Client client; + @Inject + private OverlayManager overlayManager; + @Inject + private TempleTrekkingOverlay overlay; + @Inject + private TempleTrekkingBogOverlay bogOverlay; + @Inject + private TempleTrekkingConfig config; + @Getter + private boolean inTrek = false; + + @Provides + TempleTrekkingConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(TempleTrekkingConfig.class); + } + + @Override + protected void startUp() + { + overlayManager.add(overlay); + overlayManager.add(bogOverlay); + } + + @Override + protected void shutDown() + { + overlayManager.remove(overlay); + overlayManager.remove(bogOverlay); + bogList.clear(); + } + + @Subscribe + public void onGroundObjectSpawned(GroundObjectSpawned event) + { + GroundObject obj = event.getGroundObject(); + if (obj.getId() == ObjectID.BOG) + { + bogList.add(obj); + } + } + + //onGroundObjectDespawned is having issues handling this, so bogmap removal is here instead. + @Subscribe + public void onVarbitChanged(VarbitChanged event) + { + if (!bogList.isEmpty() && client.getVar(Varbits.TREK_EVENT) == 0) + { + bogList.clear(); + } + if (!inTrek && client.getVar(Varbits.TREK_STARTED) == 1) + { + inTrek = true; + } + else if (inTrek) + { + if (client.getVar(Varbits.TREK_STATUS) == 0 && client.getVar(Varbits.TREK_POINTS) == 0) + { + inTrek = false; + } + } + } + + protected int getRewardPoints() + { + return client.getVar(Varbits.TREK_POINTS); + } + + protected double getRewardPercentage() + { + double percentage = 0.000126945 * getRewardPoints() - 0.0357188951; + return Math.max(percentage, 0); + } + +}