From 00a5845c7e2d1ef0be4137640be543f21993c630 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 Jun 2018 21:07:01 -0400 Subject: [PATCH 1/4] actor mixin: fix getInteracting when index is 65535 There are short times where it is this before being set to -1 --- .../src/main/java/net/runelite/mixins/RSActorMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java index 01e479d98b..2ba4459def 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java @@ -68,7 +68,7 @@ public abstract class RSActorMixin implements RSActor public Actor getInteracting() { int i = getRSInteracting(); - if (i == -1) + if (i == -1 || i == 65535) { return null; } From d239a47d9898f2b1a004810d8049190177a5c7a9 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 Jun 2018 21:08:04 -0400 Subject: [PATCH 2/4] Add interacting changed event --- .../api/events/InteractingChanged.java | 42 +++++++++++++++++++ .../net/runelite/mixins/RSActorMixin.java | 9 ++++ 2 files changed, 51 insertions(+) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/InteractingChanged.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/InteractingChanged.java b/runelite-api/src/main/java/net/runelite/api/events/InteractingChanged.java new file mode 100644 index 0000000000..fdfe0d1272 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/InteractingChanged.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Value; +import net.runelite.api.Actor; + +/** + * An event called when the actor an actor is interacting with changes + */ +@Value +public class InteractingChanged +{ + private final Actor source; + + /** + * Target actor, may be null + */ + private final Actor target; +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java index 2ba4459def..04e2e348ab 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java @@ -41,6 +41,7 @@ import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.GraphicChanged; import net.runelite.api.events.HitsplatApplied; +import net.runelite.api.events.InteractingChanged; import net.runelite.api.events.LocalPlayerDeath; import net.runelite.api.mixins.FieldHook; import net.runelite.api.mixins.Inject; @@ -199,6 +200,14 @@ public abstract class RSActorMixin implements RSActor client.getCallbacks().post(graphicChanged); } + @FieldHook("interacting") + @Inject + public void interactingChanged(int idx) + { + InteractingChanged interactingChanged = new InteractingChanged(this, getInteracting()); + client.getCallbacks().post(interactingChanged); + } + @Inject @Override public Polygon getConvexHull() From f3f18b610f56c519bc05627173f47231a26123b6 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 24 Jun 2018 11:17:54 -0400 Subject: [PATCH 3/4] chat message manager: set default colors for GAME messages --- .../main/java/net/runelite/client/chat/ChatMessageManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/chat/ChatMessageManager.java b/runelite-client/src/main/java/net/runelite/client/chat/ChatMessageManager.java index cb89d755fe..ba4e4dee7f 100644 --- a/runelite-client/src/main/java/net/runelite/client/chat/ChatMessageManager.java +++ b/runelite-client/src/main/java/net/runelite/client/chat/ChatMessageManager.java @@ -189,6 +189,7 @@ public class ChatMessageManager case EXAMINE_ITEM: case EXAMINE_OBJECT: case EXAMINE_NPC: + case GAME: return Color.decode("#000000"); } } @@ -207,6 +208,7 @@ public class ChatMessageManager case EXAMINE_ITEM: case EXAMINE_OBJECT: case EXAMINE_NPC: + case GAME: return Color.decode("#FFFFFF"); } } From f126dcf041aa25ab3bb52fb675776a1670e6345f Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 Jun 2018 21:08:25 -0400 Subject: [PATCH 4/4] Add corporeal beast plugin --- .../main/java/net/runelite/api/Varbits.java | 7 +- .../net/runelite/api/widgets/WidgetID.java | 1 + .../client/plugins/corp/CoreOverlay.java | 68 ++++++ .../plugins/corp/CorpDamageOverlay.java | 135 ++++++++++++ .../client/plugins/corp/CorpPlugin.java | 203 ++++++++++++++++++ 5 files changed, 413 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/corp/CoreOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpDamageOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java diff --git a/runelite-api/src/main/java/net/runelite/api/Varbits.java b/runelite-api/src/main/java/net/runelite/api/Varbits.java index a3657552de..41fdef2104 100644 --- a/runelite-api/src/main/java/net/runelite/api/Varbits.java +++ b/runelite-api/src/main/java/net/runelite/api/Varbits.java @@ -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. diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index 8b965eab31..deef0797d5 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -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 { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CoreOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CoreOverlay.java new file mode 100644 index 0000000000..29c7dff16a --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CoreOverlay.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018, Adam + * 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; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpDamageOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpDamageOverlay.java new file mode 100644 index 0000000000..d23074cd46 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpDamageOverlay.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2018, Adam + * 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); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java new file mode 100644 index 0000000000..91cca066ba --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2018, Adam + * 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 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); + } +}