Merge pull request #2215 from xKylee/templetrekking

templetrekking: add plugin
This commit is contained in:
Owain van Brakel
2020-01-12 18:18:26 +01:00
committed by GitHub
4 changed files with 332 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018, Frosty Fridge <https://github.com/frostyfridge>
* 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;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2018, Frosty Fridge <https://github.com/frostyfridge>
* 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;
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2018, Frosty Fridge <https://github.com/frostyfridge>
* 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;
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2018, Frosty Fridge <https://github.com/frostyfridge>
* 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<GroundObject> bogList = new HashSet<GroundObject>();
@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);
}
}