Hook to actor health being updated to detect death
This commit is contained in:
@@ -34,6 +34,7 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MainBufferProvider;
|
import net.runelite.api.MainBufferProvider;
|
||||||
@@ -46,6 +47,7 @@ import net.runelite.api.RenderOverview;
|
|||||||
import net.runelite.api.TextureProvider;
|
import net.runelite.api.TextureProvider;
|
||||||
import net.runelite.api.WorldMapManager;
|
import net.runelite.api.WorldMapManager;
|
||||||
import net.runelite.api.coords.LocalPoint;
|
import net.runelite.api.coords.LocalPoint;
|
||||||
|
import net.runelite.api.events.ActorDeath;
|
||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
@@ -55,7 +57,6 @@ import net.runelite.api.widgets.Widget;
|
|||||||
import static net.runelite.api.widgets.WidgetID.WORLD_MAP;
|
import static net.runelite.api.widgets.WidgetID.WORLD_MAP;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.chat.ChatMessageManager;
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
import net.runelite.client.game.DeathChecker;
|
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.input.MouseManager;
|
import net.runelite.client.input.MouseManager;
|
||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
@@ -81,7 +82,6 @@ public class Hooks
|
|||||||
private static final OverlayRenderer renderer = injector.getInstance(OverlayRenderer.class);
|
private static final OverlayRenderer renderer = injector.getInstance(OverlayRenderer.class);
|
||||||
private static final MouseManager mouseManager = injector.getInstance(MouseManager.class);
|
private static final MouseManager mouseManager = injector.getInstance(MouseManager.class);
|
||||||
private static final KeyManager keyManager = injector.getInstance(KeyManager.class);
|
private static final KeyManager keyManager = injector.getInstance(KeyManager.class);
|
||||||
private static final DeathChecker death = new DeathChecker(client, eventBus);
|
|
||||||
private static final GameTick tick = new GameTick();
|
private static final GameTick tick = new GameTick();
|
||||||
|
|
||||||
private static Dimension lastStretchedDimensions;
|
private static Dimension lastStretchedDimensions;
|
||||||
@@ -103,8 +103,6 @@ public class Hooks
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
death.check();
|
|
||||||
|
|
||||||
// tick pending scheduled tasks
|
// tick pending scheduled tasks
|
||||||
scheduler.tick();
|
scheduler.tick();
|
||||||
|
|
||||||
@@ -383,4 +381,14 @@ public class Hooks
|
|||||||
{
|
{
|
||||||
eventBus.post(tick);
|
eventBus.post(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onSetCombatInfo(Actor actor, int combatInfoId, int gameCycle, int var3, int var4, int healthRatio, int health)
|
||||||
|
{
|
||||||
|
if (healthRatio == 0)
|
||||||
|
{
|
||||||
|
ActorDeath death = new ActorDeath();
|
||||||
|
death.setActor(actor);
|
||||||
|
eventBus.post(death);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, 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.game;
|
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import net.runelite.api.Actor;
|
|
||||||
import net.runelite.api.Client;
|
|
||||||
import net.runelite.api.Player;
|
|
||||||
import net.runelite.api.events.ActorDeath;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class DeathChecker
|
|
||||||
{
|
|
||||||
private final EventBus eventBus;
|
|
||||||
private final Client client;
|
|
||||||
private WeakReference<Actor> last = new WeakReference<>(null);
|
|
||||||
|
|
||||||
public DeathChecker(Client client, EventBus eventBus)
|
|
||||||
{
|
|
||||||
this.client = client;
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void check()
|
|
||||||
{
|
|
||||||
Actor opponent = getOpponent();
|
|
||||||
if (opponent == null || opponent.getHealthRatio() != 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Actor lastActor = last.get();
|
|
||||||
if (lastActor != null && lastActor.equals(opponent))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last = new WeakReference<>(opponent);
|
|
||||||
log.debug("Actor {} has died", opponent.getName());
|
|
||||||
|
|
||||||
ActorDeath death = new ActorDeath();
|
|
||||||
death.setActor(opponent);
|
|
||||||
|
|
||||||
eventBus.post(death);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Actor getOpponent()
|
|
||||||
{
|
|
||||||
Player player = client.getLocalPlayer();
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return player.getInteracting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user