Merge pull request #683 from NotFoxtrot/pyramid-plunder

Pyramid plunder
This commit is contained in:
Adam
2018-02-26 10:09:32 -05:00
committed by GitHub
6 changed files with 241 additions and 2 deletions

View File

@@ -208,7 +208,13 @@ public enum Varbits
BLAST_FURNACE_SILVER_BAR(948),
BLAST_FURNACE_GOLD_BAR(947),
BLAST_FURNACE_COFFER(5357);
BLAST_FURNACE_COFFER(5357),
/**
* Pyramid plunder
*/
PYRAMID_PLUNDER_TIMER(2375),
PYRAMID_PLUNDER_ROOM(2377);
/**
* varbit id

View File

@@ -68,6 +68,7 @@ public class WidgetID
public static final int NIGHTMARE_ZONE_GROUP_ID = 202;
public static final int BLAST_FURNACE_GROUP_ID = 474;
public static final int WORLD_MAP = 595;
public static final int PYRAMID_PLUNDER_GROUP_ID = 428;
static class WorldMap
{

View File

@@ -177,7 +177,9 @@ public enum WidgetInfo
RAIDS_POINTS_INFOBOX(WidgetID.RAIDS_GROUP_ID, WidgetID.Raids.POINTS_INFOBOX),
BLAST_FURNACE_COFFER(WidgetID.BLAST_FURNACE_GROUP_ID, 0);
BLAST_FURNACE_COFFER(WidgetID.BLAST_FURNACE_GROUP_ID, 0),
PYRAMID_PLUNDER_DATA(WidgetID.PYRAMID_PLUNDER_GROUP_ID, 0);
private final int groupId;
private final int childId;

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2018, NotFoxtrot <http://github.com/NotFoxtrot>
* 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.pyramidplunder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.PanelComponent;
public class PyramidPlunderOverlay extends Overlay
{
private final Client client;
private final PanelComponent panelComponent = new PanelComponent();
private PyramidTimer timer;
@Inject
PyramidPlunderOverlay(Client client)
{
setPosition(OverlayPosition.TOP_LEFT);
this.client = client;
}
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
Widget pyramidPlunderInfo = client.getWidget(WidgetInfo.PYRAMID_PLUNDER_DATA);
if (pyramidPlunderInfo == null)
{
timer = null;
return null;
}
panelComponent.getLines().clear();
pyramidPlunderInfo.setHidden(true);
if (timer == null)
{
startTimer();
}
panelComponent.getLines().add(new PanelComponent.Line(
"Time left: ", Color.WHITE, timer.getText(), timer.getTextColor()
));
panelComponent.getLines().add(new PanelComponent.Line(
"Room: ", String.valueOf(client.getSetting(Varbits.PYRAMID_PLUNDER_ROOM)) + "/8"
));
return panelComponent.render(graphics, parent);
}
public void showWidget()
{
Widget pyramidPlunderInfo = client.getWidget(WidgetInfo.PYRAMID_PLUNDER_DATA);
if (pyramidPlunderInfo != null)
{
pyramidPlunderInfo.setHidden(false);
}
}
private void startTimer()
{
int plunderingTime = client.getSetting(Varbits.PYRAMID_PLUNDER_TIMER);
int timeLeft = (int) ((505 - plunderingTime) * 0.6);
timer = new PyramidTimer(timeLeft);
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018, NotFoxtrot <http://github.com/NotFoxtrot>
* 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.pyramidplunder;
import javax.inject.Inject;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
@PluginDescriptor(
name = "Pyramid Plunder"
)
public class PyramidPlunderPlugin extends Plugin
{
@Inject
private PyramidPlunderOverlay overlay;
@Override
public Overlay getOverlay()
{
return overlay;
}
@Override
protected void shutDown() throws Exception
{
overlay.showWidget();
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2018, NotFoxtrot <http://github.com/NotFoxtrot>
* 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.pyramidplunder;
import com.google.common.base.Preconditions;
import java.awt.Color;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
class PyramidTimer
{
private final Instant endTime;
PyramidTimer(long period)
{
Preconditions.checkArgument(period > 0, "negative period!");
endTime = Instant.now().plus(period, ChronoUnit.SECONDS);
}
public String getText()
{
if (isFinished())
{
return "0:00";
}
Duration timeLeft = Duration.between(Instant.now(), endTime);
int totalSeconds = (int) timeLeft.get(ChronoUnit.SECONDS);
int minutes = (totalSeconds % 3600) / 60;
int seconds = totalSeconds % 60;
return String.format("%d:%02d", minutes, seconds);
}
public Color getTextColor()
{
Duration timeLeft = Duration.between(Instant.now(), endTime);
if (timeLeft.getSeconds() < 30)
{
return Color.RED.brighter();
}
return Color.WHITE;
}
private boolean isFinished()
{
return Instant.now().isAfter(endTime);
}
}