Add fight cave plugin
This commit is contained in:
@@ -43,6 +43,7 @@ import net.runelite.client.plugins.combatnotifier.CombatNotifier;
|
||||
import net.runelite.client.plugins.config.ConfigPlugin;
|
||||
import net.runelite.client.plugins.devtools.DevTools;
|
||||
import net.runelite.client.plugins.examine.ExaminePlugin;
|
||||
import net.runelite.client.plugins.fightcave.FightCave;
|
||||
import net.runelite.client.plugins.fishing.FishingPlugin;
|
||||
import net.runelite.client.plugins.fpsinfo.FPS;
|
||||
import net.runelite.client.plugins.grounditems.GroundItems;
|
||||
@@ -111,6 +112,7 @@ public class PluginManager
|
||||
plugins.add(new ClueScrollPlugin());
|
||||
plugins.add(new Timers());
|
||||
plugins.add(new Runepouch());
|
||||
plugins.add(new FightCave());
|
||||
|
||||
if (RuneLite.getOptions().has("developer-mode"))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
|
||||
* 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.fightcave;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Query;
|
||||
import net.runelite.api.queries.NPCQuery;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class FightCave extends Plugin
|
||||
{
|
||||
private final RuneLite runelite = RuneLite.getRunelite();
|
||||
private final Client client = RuneLite.getClient();
|
||||
private final FightCaveOverlay overlay = new FightCaveOverlay(this);
|
||||
|
||||
private JadAttack attack;
|
||||
|
||||
@Override
|
||||
public Overlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Schedule(
|
||||
period = 600,
|
||||
unit = ChronoUnit.MILLIS
|
||||
)
|
||||
public void update()
|
||||
{
|
||||
if (client == null || client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NPC jad = findJad();
|
||||
if (jad != null)
|
||||
{
|
||||
if (jad.getAnimation() == JadAttack.MAGIC.getAnimation())
|
||||
{
|
||||
attack = JadAttack.MAGIC;
|
||||
}
|
||||
else if (jad.getAnimation() == JadAttack.RANGE.getAnimation())
|
||||
{
|
||||
attack = JadAttack.RANGE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attack = null;
|
||||
}
|
||||
}
|
||||
|
||||
private NPC findJad()
|
||||
{
|
||||
Query query = new NPCQuery().nameContains("TzTok-Jad");
|
||||
NPC[] result = runelite.runQuery(query);
|
||||
return result.length >= 1 ? result[0] : null;
|
||||
}
|
||||
|
||||
JadAttack getAttack()
|
||||
{
|
||||
return attack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
|
||||
* 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.fightcave;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class FightCaveOverlay extends Overlay
|
||||
{
|
||||
private static final int WIDTH = 70;
|
||||
private static final int SPACER = 6;
|
||||
private static final int BOTTOM_BORDER = 4;
|
||||
private static final Color GREEN_BACKGROUND = new Color(0, 255, 0, 100);
|
||||
private static final Color RED_BACKGROUND = new Color(255, 0, 0, 100);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FightCaveOverlay.class);
|
||||
|
||||
private final FightCave plugin;
|
||||
private final Client client = RuneLite.getClient();
|
||||
private Image protectFromMagicImg;
|
||||
private Image protectFromMissilesImg;
|
||||
|
||||
FightCaveOverlay(FightCave plugin)
|
||||
{
|
||||
super(OverlayPosition.DYNAMIC);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
JadAttack attack = plugin.getAttack();
|
||||
Rectangle viewport = getViewportBounds();
|
||||
if (attack == null || viewport == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Image img = getPrayerImage(attack);
|
||||
if (img == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Color bgColor;
|
||||
Color outlineColor;
|
||||
Widget prayer = client.getWidget(attack.getPrayerWidgetInfo());
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
int height = fm.getHeight() + img.getHeight(null) + SPACER + BOTTOM_BORDER;
|
||||
|
||||
if (client.isPrayerActive(attack.getPrayer()))
|
||||
{
|
||||
bgColor = GREEN_BACKGROUND;
|
||||
outlineColor = Color.GREEN.darker();
|
||||
}
|
||||
else
|
||||
{
|
||||
bgColor = RED_BACKGROUND;
|
||||
outlineColor = Color.RED.darker();
|
||||
}
|
||||
|
||||
int bgX = (int) (viewport.getX() + viewport.getWidth() - WIDTH);
|
||||
int bgY = (int) (viewport.getY() + viewport.getHeight() - height);
|
||||
graphics.setColor(bgColor);
|
||||
graphics.fillRect(bgX, bgY, WIDTH, height);
|
||||
|
||||
if (prayer != null)
|
||||
{
|
||||
graphics.setColor(outlineColor);
|
||||
graphics.draw(prayer.getBounds());
|
||||
}
|
||||
|
||||
graphics.setColor(Color.WHITE);
|
||||
graphics.drawString("TzTok-Jad", bgX + (WIDTH - fm.stringWidth("TzTok-Jad")) / 2, bgY + fm.getHeight());
|
||||
graphics.drawImage(img, bgX + (WIDTH - img.getWidth(null)) / 2, bgY + fm.getHeight() + SPACER, null);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Rectangle getViewportBounds()
|
||||
{
|
||||
Widget viewport = client.getViewportWidget();
|
||||
return viewport != null ? viewport.getBounds() : null;
|
||||
}
|
||||
|
||||
private Image getPrayerImage(JadAttack attack)
|
||||
{
|
||||
return attack == JadAttack.MAGIC ? getProtectFromMagicImage() : getProtectFromMissilesImage();
|
||||
}
|
||||
|
||||
private Image getProtectFromMagicImage()
|
||||
{
|
||||
if (protectFromMagicImg == null)
|
||||
{
|
||||
String path = "/prayers/protect_from_magic.png";
|
||||
protectFromMagicImg = getImage(path);
|
||||
}
|
||||
return protectFromMagicImg;
|
||||
}
|
||||
|
||||
private Image getProtectFromMissilesImage()
|
||||
{
|
||||
if (protectFromMissilesImg == null)
|
||||
{
|
||||
String path = "/prayers/protect_from_missiles.png";
|
||||
protectFromMissilesImg = getImage(path);
|
||||
}
|
||||
return protectFromMissilesImg;
|
||||
}
|
||||
|
||||
private Image getImage(String path)
|
||||
{
|
||||
Image image = null;
|
||||
try
|
||||
{
|
||||
InputStream in = FightCaveOverlay.class.getResourceAsStream(path);
|
||||
image = ImageIO.read(in);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.warn("Error loading image", e);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
|
||||
* 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.fightcave;
|
||||
|
||||
import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.Prayer;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
|
||||
public enum JadAttack
|
||||
{
|
||||
MAGIC(AnimationID.TZTOK_JAD_MAGIC_ATTACK, Prayer.PROTECT_FROM_MAGIC, WidgetInfo.PRAYER_PROTECT_FROM_MAGIC),
|
||||
RANGE(AnimationID.TZTOK_JAD_RANGE_ATTACK, Prayer.PROTECT_FROM_MISSILES, WidgetInfo.PRAYER_PROTECT_FROM_MISSILES);
|
||||
|
||||
private final int animation;
|
||||
private final Prayer prayer;
|
||||
private final WidgetInfo prayerWidgetInfo;
|
||||
|
||||
JadAttack(int animation, Prayer prayer, WidgetInfo prayerWidgetInfo)
|
||||
{
|
||||
this.animation = animation;
|
||||
this.prayer = prayer;
|
||||
this.prayerWidgetInfo = prayerWidgetInfo;
|
||||
}
|
||||
|
||||
public int getAnimation()
|
||||
{
|
||||
return animation;
|
||||
}
|
||||
|
||||
public Prayer getPrayer()
|
||||
{
|
||||
return prayer;
|
||||
}
|
||||
|
||||
public WidgetInfo getPrayerWidgetInfo()
|
||||
{
|
||||
return prayerWidgetInfo;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,6 @@ import net.runelite.api.Player;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.Region;
|
||||
import net.runelite.api.Tile;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
@@ -124,19 +123,7 @@ public class GroundItemsOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
WidgetInfo viewportInfo = WidgetInfo.FIXED_VIEWPORT;
|
||||
if (client.isResized())
|
||||
{
|
||||
if (client.getSetting(Varbits.SIDE_PANELS) == 1)
|
||||
{
|
||||
viewportInfo = WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE;
|
||||
}
|
||||
else
|
||||
{
|
||||
viewportInfo = WidgetInfo.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX;
|
||||
}
|
||||
}
|
||||
Widget viewport = client.getWidget(viewportInfo);
|
||||
Widget viewport = client.getViewportWidget();
|
||||
|
||||
if (viewport != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user