Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SluttyTree extends Script {
- private CachedNPC cache;
- @Override
- public int onLoop() throws InterruptedException {
- if (cache == null || cache.isDead()) {
- NPC npc = getNpcs().closest("Ent");
- if (npc != null) {
- cache = new CachedNPC(npc);
- }
- } else {
- cache.checkPosition(getBot());
- if (cache.isSafeSpotted(myPlayer())) {
- if (!myPlayer().isInteracting(cache.getNpc())) {
- //TODO - Attack
- }
- } else {
- //TODO - Walk to position
- }
- }
- return 600;
- }
- @Override
- public void onPaint(Graphics2D g) {
- if (cache != null) cache.draw(g);
- }
- }
- class CachedNPC {
- private final NPC npc;
- private Position position;
- private Area area;
- private List<Polygon> polygons;
- public CachedNPC(NPC npc) {
- this.npc = npc;
- }
- public boolean isDead() {
- return npc == null || !npc.exists();
- }
- public void checkPosition(Bot bot) {
- Position pos = npc.getPosition();
- if (position == null || pos.distance(position) != 0) {
- this.position = pos;
- this.area = new Area(pos.getX(), pos.getY(), pos.getX() + 1, pos.getY() + 1);
- this.polygons = new ArrayList<>();
- this.area.getPositions().forEach(p -> this.polygons.add(p.getPolygon(bot)));
- }
- }
- public void draw(Graphics2D g) {
- if (polygons != null && polygons.size() > 0) {
- polygons.forEach(g::drawPolygon);
- }
- }
- public boolean isSafeSpotted(Player player) {
- if (!player.isUnderAttack()) {
- if (npc.isInteracting(player)) {
- if (!npc.isMoving()) {
- return true;
- }
- }
- }
- return false;
- }
- public NPC getNpc() {
- return npc;
- }
- public Area getArea() {
- return area;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement