From 6d525c618a30d2deefd4bc1ea3c4b19f0650c3e4 Mon Sep 17 00:00:00 2001 From: Yuri Moens Date: Wed, 20 Oct 2021 20:25:10 +0200 Subject: [PATCH] Add isLookingAt function --- Util/src/io/reisub/dreambot/util/Util.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Util/src/io/reisub/dreambot/util/Util.java b/Util/src/io/reisub/dreambot/util/Util.java index 79ac970..a7b9868 100644 --- a/Util/src/io/reisub/dreambot/util/Util.java +++ b/Util/src/io/reisub/dreambot/util/Util.java @@ -3,8 +3,10 @@ package io.reisub.dreambot.util; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.MethodContext; import org.dreambot.api.methods.interactive.Players; +import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.skills.Skills; +import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.interactive.Player; @SuppressWarnings("unused") @@ -81,4 +83,35 @@ public class Util { public static int getCurrentHP() { return Skills.getBoostedLevels(Skill.HITPOINTS); } + + public static boolean isLookingAt(GameObject o) { + Tile playerTile = Players.localPlayer().getTile(); + int px = playerTile.getX(); + int py = playerTile.getY(); + + Tile objectTile = o.getTile(); + int ox = objectTile.getX(); + int oy = objectTile.getY(); + + switch (Players.localPlayer().getOrientation() / 256) { + case 0: // south + return oy < py; + case 1: // south-west + return oy <= py && ox <= px; + case 2: // west + return ox < px; + case 3: //north-west + return oy >= py && ox <= px; + case 4: // north + return oy > py; + case 5: // north-east + return oy >= py && ox >= px; + case 6: // east + return ox > px; + case 7: //south-east + return oy <= py && ox >= px; + } + + return false; + } }