Add corporeal beast plugin
This commit is contained in:
@@ -367,7 +367,12 @@ public enum Varbits
|
||||
/**
|
||||
* The varbit that stores the players {@code AccountType}.
|
||||
*/
|
||||
ACCOUNT_TYPE(1777);
|
||||
ACCOUNT_TYPE(1777),
|
||||
|
||||
/**
|
||||
* Corp beast damage
|
||||
*/
|
||||
CORP_DAMAGE(999);
|
||||
|
||||
/**
|
||||
* The raw varbit ID.
|
||||
|
||||
@@ -100,6 +100,7 @@ public class WidgetID
|
||||
public static final int MTA_ENCHANTMENT_GROUP_ID = 195;
|
||||
public static final int MTA_GRAVEYARD_GROUP_ID = 196;
|
||||
public static final int MTA_TELEKINETIC_GROUP_ID = 198;
|
||||
public static final int CORP_DAMAGE = 13;
|
||||
|
||||
static class WorldMap
|
||||
{
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.corp;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
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.OverlayUtil;
|
||||
|
||||
class CoreOverlay extends Overlay
|
||||
{
|
||||
private final Client client;
|
||||
private final CorpPlugin corpPlugin;
|
||||
|
||||
@Inject
|
||||
private CoreOverlay(Client client, CorpPlugin corpPlugin)
|
||||
{
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||
this.client = client;
|
||||
this.corpPlugin = corpPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
NPC core = corpPlugin.getCore();
|
||||
if (core != null)
|
||||
{
|
||||
Polygon canvasTilePoly = core.getCanvasTilePoly();
|
||||
if (canvasTilePoly != null)
|
||||
{
|
||||
OverlayUtil.renderPolygon(graphics, canvasTilePoly, Color.RED.brighter());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.corp;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
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.components.ComponentConstants;
|
||||
import net.runelite.client.ui.overlay.components.LineComponent;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
import net.runelite.client.ui.overlay.components.TitleComponent;
|
||||
|
||||
class CorpDamageOverlay extends Overlay
|
||||
{
|
||||
private final Client client;
|
||||
private final CorpPlugin corpPlugin;
|
||||
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
|
||||
@Inject
|
||||
private CorpDamageOverlay(Client client, CorpPlugin corpPlugin)
|
||||
{
|
||||
setPosition(OverlayPosition.TOP_LEFT);
|
||||
setLayer(OverlayLayer.UNDER_WIDGETS);
|
||||
setPriority(OverlayPriority.LOW);
|
||||
this.client = client;
|
||||
this.corpPlugin = corpPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
Widget damageWidget = client.getWidget(WidgetID.CORP_DAMAGE, 0);
|
||||
if (damageWidget != null)
|
||||
{
|
||||
damageWidget.setHidden(true);
|
||||
}
|
||||
|
||||
NPC corp = corpPlugin.getCorp();
|
||||
if (corp == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int myDamage = client.getVar(Varbits.CORP_DAMAGE);
|
||||
int totalDamage = corpPlugin.getTotalDamage();
|
||||
int players = corpPlugin.getPlayers().size();
|
||||
|
||||
// estimate how much damage is required for kill based on number of players
|
||||
int damageForKill = players != 0 ? totalDamage / players : 0;
|
||||
|
||||
panelComponent.getChildren().clear();
|
||||
|
||||
panelComponent.getChildren().add(TitleComponent.builder()
|
||||
.text("Corporeal Beast")
|
||||
.build());
|
||||
|
||||
NPC core = corpPlugin.getCore();
|
||||
if (core != null)
|
||||
{
|
||||
WorldPoint corePoint = core.getWorldLocation();
|
||||
WorldPoint myPoint = client.getLocalPlayer().getWorldLocation();
|
||||
|
||||
String text = null;
|
||||
|
||||
if (core.getInteracting() == client.getLocalPlayer())
|
||||
{
|
||||
text = "The core is targeting you!";
|
||||
}
|
||||
else if (corePoint.distanceTo(myPoint) <= 1)
|
||||
{
|
||||
text = "Stay away from the core!";
|
||||
}
|
||||
|
||||
if (text != null)
|
||||
{
|
||||
final FontMetrics fontMetrics = graphics.getFontMetrics();
|
||||
int textWidth = Math.max(ComponentConstants.STANDARD_WIDTH, fontMetrics.stringWidth(text));
|
||||
|
||||
panelComponent.setPreferredSize(new Dimension(textWidth, 0));
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left(text)
|
||||
.leftColor(Color.RED)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left("Your damage")
|
||||
.right(Integer.toString(myDamage))
|
||||
.rightColor(damageForKill > 0 && myDamage >= damageForKill ? Color.GREEN : Color.RED)
|
||||
.build());
|
||||
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left("Total damage")
|
||||
.right(Integer.toString(totalDamage))
|
||||
.build());
|
||||
|
||||
return panelComponent.render(graphics);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* 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.corp;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NpcID;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.HitsplatApplied;
|
||||
import net.runelite.api.events.InteractingChanged;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.client.chat.ChatColorType;
|
||||
import net.runelite.client.chat.ChatMessageBuilder;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.chat.QueuedMessage;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Corporeal Beast"
|
||||
)
|
||||
public class CorpPlugin extends Plugin
|
||||
{
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private NPC corp;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private NPC core;
|
||||
|
||||
private int yourDamage;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private int totalDamage;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Set<Actor> players = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private CorpDamageOverlay corpOverlay;
|
||||
|
||||
@Inject
|
||||
private CoreOverlay coreOverlay;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
overlayManager.add(corpOverlay);
|
||||
overlayManager.add(coreOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
overlayManager.remove(corpOverlay);
|
||||
overlayManager.remove(coreOverlay);
|
||||
|
||||
corp = core = null;
|
||||
yourDamage = 0;
|
||||
totalDamage = 0;
|
||||
players.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||
{
|
||||
if (gameStateChanged.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
corp = core = null;
|
||||
players.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcSpawned(NpcSpawned npcSpawned)
|
||||
{
|
||||
NPC npc = npcSpawned.getNpc();
|
||||
|
||||
switch (npc.getId())
|
||||
{
|
||||
case NpcID.CORPOREAL_BEAST:
|
||||
corp = npc;
|
||||
yourDamage = 0;
|
||||
totalDamage = 0;
|
||||
players.clear();
|
||||
break;
|
||||
case NpcID.DARK_ENERGY_CORE:
|
||||
core = npc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||
{
|
||||
NPC npc = npcDespawned.getNpc();
|
||||
|
||||
if (npc == corp)
|
||||
{
|
||||
corp = null;
|
||||
players.clear();
|
||||
|
||||
if (npc.isDead())
|
||||
{
|
||||
// Show kill stats
|
||||
String message = new ChatMessageBuilder()
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append("Corporeal Beast: Your damage: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(Integer.toString(yourDamage))
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append(", Total damage: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append(Integer.toString(totalDamage))
|
||||
.build();
|
||||
|
||||
chatMessageManager.queue(QueuedMessage.builder()
|
||||
.type(ChatMessageType.GAME)
|
||||
.runeLiteFormattedMessage(message)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
else if (npc == core)
|
||||
{
|
||||
core = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onHitsplat(HitsplatApplied hitsplatApplied)
|
||||
{
|
||||
Actor actor = hitsplatApplied.getActor();
|
||||
|
||||
if (actor != corp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int myDamage = client.getVar(Varbits.CORP_DAMAGE);
|
||||
// sometimes hitsplats are applied after the damage counter has been reset
|
||||
if (myDamage > 0)
|
||||
{
|
||||
yourDamage = myDamage;
|
||||
}
|
||||
totalDamage += hitsplatApplied.getHitsplat().getAmount();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInteractingChanged(InteractingChanged interactingChanged)
|
||||
{
|
||||
Actor source = interactingChanged.getSource();
|
||||
Actor target = interactingChanged.getTarget();
|
||||
|
||||
if (corp == null || target != corp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
players.add(source);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user