Add isLookingAt function

This commit is contained in:
Yuri Moens 2021-10-20 20:25:10 +02:00
parent 1523cb0289
commit 6d525c618a
Signed by: ymo
GPG Key ID: F6D51D6FE15BE924

View File

@ -3,8 +3,10 @@ package io.reisub.dreambot.util;
import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext; import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.interactive.Players; 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.Skill;
import org.dreambot.api.methods.skills.Skills; import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.wrappers.interactive.GameObject;
import org.dreambot.api.wrappers.interactive.Player; import org.dreambot.api.wrappers.interactive.Player;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -81,4 +83,35 @@ public class Util {
public static int getCurrentHP() { public static int getCurrentHP() {
return Skills.getBoostedLevels(Skill.HITPOINTS); 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;
}
} }