Skip to content

Commit

Permalink
Add fight cave plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
devinfrench authored and Adam- committed Oct 10, 2017
1 parent b05fc2e commit 348d338
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 16 deletions.
4 changes: 4 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/AnimationID.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ public final class AnimationID
public static final int MINING_MOTHERLODE_INFERNAL = 0; // placeholder, unknown
public static final int HERBLORE_POTIONMAKING = 363; //used for both herb and secondary
public static final int MAGIC_CHARGING_ORBS = 726;

// NPC animations
public static final int TZTOK_JAD_MAGIC_ATTACK = 2656;
public static final int TZTOK_JAD_RANGE_ATTACK = 2652;
}
3 changes: 3 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package net.runelite.api;

import java.awt.Canvas;

import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;

Expand Down Expand Up @@ -143,4 +144,6 @@ public interface Client
void setGameDrawingMode(int gameDrawingMode);

void refreshChat();

Widget getViewportWidget();
}
34 changes: 34 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WidgetID
static final int FIXED_VIEWPORT_GROUP_ID = 548;
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID = 161;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID = 164;
static final int PRAYER_GROUP_ID = 541;

static class PestControl
{
Expand Down Expand Up @@ -102,4 +103,37 @@ static class Viewport
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX = 12;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE = 12;
}

static class Prayer
{
static final int THICK_SKIN = 4;
static final int BURST_OF_STRENGTH = 5;
static final int CLARITY_OF_THOUGHT = 6;
static final int SHARP_EYE = 22;
static final int MYSTIC_WILL = 23;
static final int ROCK_SKIN = 7;
static final int SUPERHUMAN_STRENGTH = 8;
static final int IMPROVED_REFLEXES = 9;
static final int RAPID_RESTORE = 10;
static final int RAPID_HEAL = 11;
static final int PROTECT_ITEM = 12;
static final int HAWK_EYE = 24;
static final int MYSTIC_LORE = 25;
static final int STEEL_SKIN = 13;
static final int ULTIMATE_STRENGTH = 14;
static final int INCREDIBLE_REFLEXES = 15;
static final int PROTECT_FROM_MAGIC = 16;
static final int PROTECT_FROM_MISSILES = 17;
static final int PROTECT_FROM_MELEE = 18;
static final int EAGLE_EYE = 26;
static final int MYSTIC_MIGHT = 27;
static final int RETRIBUTION = 19;
static final int REDEMPTION = 20;
static final int SMITE = 21;
static final int PRESERVE = 32;
static final int CHIVALRY = 28;
static final int PIETY = 29;
static final int RIGOUR = 30;
static final int AUGURY = 31;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ public enum WidgetInfo

FIXED_VIEWPORT(WidgetID.FIXED_VIEWPORT_GROUP_ID, WidgetID.Viewport.FIXED_VIEWPORT),
RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX(WidgetID.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID, WidgetID.Viewport.RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX),
RESIZABLE_VIEWPORT_BOTTOM_LINE(WidgetID.RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID, WidgetID.Viewport.RESIZABLE_VIEWPORT_BOTTOM_LINE);
RESIZABLE_VIEWPORT_BOTTOM_LINE(WidgetID.RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID, WidgetID.Viewport.RESIZABLE_VIEWPORT_BOTTOM_LINE),

PRAYER_PROTECT_FROM_MAGIC(WidgetID.PRAYER_GROUP_ID, WidgetID.Prayer.PROTECT_FROM_MAGIC),
PRAYER_PROTECT_FROM_MISSILES(WidgetID.PRAYER_GROUP_ID, WidgetID.Prayer.PROTECT_FROM_MISSILES);


private final int groupId;
private final int childId;

private WidgetInfo(int groupId, int childId)
WidgetInfo(int groupId, int childId)
{
this.groupId = groupId;
this.childId = childId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void loadPlugins()
plugins.add(new ClueScrollPlugin());
plugins.add(new Timers());
plugins.add(new Runepouch());
plugins.add(new FightCave());

if (RuneLite.getOptions().has("developer-mode"))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 348d338

Please sign in to comment.