Merge pull request #114 from farhan1666/olm-cripple-timer

Added olm cripple timer overlay
This commit is contained in:
gazivodag
2019-04-25 09:48:34 -04:00
committed by GitHub
2 changed files with 155 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
package net.runelite.client.plugins.olmcrippletimer;
import java.awt.*;
import java.util.*;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.*;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldArea;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
public class OlmCrippleTimerOverlay extends Overlay {
private final Client client;
private final OlmCrippleTimerPlugin plugin;
@Inject
private OlmCrippleTimerOverlay(Client client, OlmCrippleTimerPlugin plugin){
this.client = client;
this.plugin = plugin;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
setLayer(OverlayLayer.ABOVE_SCENE);
}
@Override
public Dimension render(Graphics2D graphics) {
if(plugin.isHandCripple()){
int tick = plugin.getTimer();
NPC olmHand = plugin.getHand();
final String tickStr = String.valueOf(tick);
Point canvasPoint = olmHand.getCanvasTextLocation(graphics, tickStr, 50);
renderTextLocation(graphics, tickStr, 12 , Font.BOLD, Color.GRAY, canvasPoint);
}
return null;
}
//this is just copy pasted btw
private void renderTextLocation(Graphics2D graphics, String txtString, int fontSize, int fontStyle, Color fontColor, Point canvasPoint)
{
graphics.setFont(new Font("Arial", fontStyle, fontSize));
if (canvasPoint != null)
{
final Point canvasCenterPoint = new Point(
canvasPoint.getX(),
canvasPoint.getY());
final Point canvasCenterPoint_shadow = new Point(
canvasPoint.getX() + 1,
canvasPoint.getY() + 1) ;
OverlayUtil.renderTextLocation(graphics, canvasCenterPoint_shadow, txtString, Color.BLACK);
OverlayUtil.renderTextLocation(graphics, canvasCenterPoint, txtString, fontColor);
}
}
}

View File

@@ -0,0 +1,90 @@
package net.runelite.client.plugins.olmcrippletimer;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
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;
import javax.inject.Inject;
@PluginDescriptor(
name="Olm Cripple Timer",
description = "Shows a timer over the olm hand cripple",
tags = {"cox", "raid", "clench", "melee", "hand"},
type = PluginType.PVM
)
public class OlmCrippleTimerPlugin extends Plugin{
private static final String OLM_HAND_CRIPPLE = "The Great Olm\'s left claw clenches to protect itself temporarily.";
@Inject
private Client client;
@Getter(AccessLevel.PACKAGE)
private boolean HandCripple;
@Getter(AccessLevel.PACKAGE)
private int timer = 45;
@Getter(AccessLevel.PACKAGE)
private NPC hand;
@Inject
private OverlayManager overlayManager;
@Inject
private OlmCrippleTimerOverlay olmCrippleTimerOverlay;
@Override
protected void startUp() throws Exception {
overlayManager.add(olmCrippleTimerOverlay);
}
@Override
protected void shutDown() throws Exception {
overlayManager.remove(olmCrippleTimerOverlay);
HandCripple = false;
timer = 45;
hand = null;
}
@Subscribe
public void onChatMessage(ChatMessage event)
{
String message = event.getMessage();
if(message.startsWith(OLM_HAND_CRIPPLE)){
HandCripple = true;
timer = 45;
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned npcdespawned){
if(npcdespawned.getNpc().getId() == NpcID.GREAT_OLM_RIGHT_CLAW_7553 || npcdespawned.getNpc().getId() == NpcID.GREAT_OLM_RIGHT_CLAW){
HandCripple = false;
}
}
@Subscribe
public void onNpcSpawned(NpcSpawned npcSpawned)
{
if(npcSpawned.getNpc().getId() == NpcID.GREAT_OLM_LEFT_CLAW_7555 || npcSpawned.getNpc().getId() == NpcID.GREAT_OLM_LEFT_CLAW){
hand = npcSpawned.getNpc();
}
}
@Subscribe
public void onGameTick(GameTick event)
{
if(HandCripple) {
timer--;
if (timer <= 0) {
HandCripple = false;
timer = 45;
}
}
}
}