Jump to content

Loot Painter


Recommended Posts

Posted (edited)

This will paint all the loot that is on the screen and will condense same items together if the items are in the same loot pile.

To Use, simply call Painter.paintGroundItems() in your onPaint() Method.

It takes 4 parameters:

  1. Graphics2D
  2. Color - This will be the color of Tile Outline
  3. Color - This will be the color of the Loot Text
  4. Script

Example Usage:

Spoiler

Painter.paintGroundItems(g, Color.orange, Color.magenta, this)

Picture:

Spoiler

screenshot_14_09_2019-19_29_15.png.e21ed1952e2d36f7818d257ff9ae4518.png

Code:

Spoiler

Painter.java

Spoiler

 



import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.script.Script;

import java.awt.*;

public abstract class Painter {

    private static Font textFont = new Font("TimesNewRoman", Font.BOLD, 10);

    public static void paintGroundItems(Graphics2D g, Color tileOutlineColor, Color itemTextColor, Script script) {
        g.setFont(textFont);
        CustomGroundItemsList customGroundItemsList = new CustomGroundItemsList();
        Position position = new Position(0, 0, 0);
        int currentY = 15;
        for (GroundItem groundItem : script.getGroundItems().getAll()) {
            if (groundItem.isOnScreen()) {
                Rectangle groundItemBounds = groundItem.getPosition().getPolygon(script.getBot()).getBounds();
                Position groundItemPosition = groundItem.getPosition();
                CustomGroundItem customGroundItem = new CustomGroundItem(groundItem.getName(), groundItemPosition, groundItem.getAmount(), currentY, groundItemBounds);
                if (position.equals(groundItem.getPosition()) && !customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) {
                    currentY += 15;
                    customGroundItem.setYOffset(currentY);
                    customGroundItemsList.add(customGroundItem);
                } else if (!position.equals(groundItem.getPosition()) && !customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) {
                    currentY = 15;
                    customGroundItem.setYOffset(currentY);
                    customGroundItemsList.add(customGroundItem);
                } else if (position.equals(groundItem.getPosition()) && customGroundItemsList.listContainsCustomGroundItem(customGroundItem)) {
                    customGroundItem.setYOffset(currentY);
                    customGroundItemsList.add(customGroundItem);
                }
            }
            position = groundItem.getPosition();
        }

        for (CustomGroundItem customGroundItem : customGroundItemsList.getCustomGroundItems()) {
            g.setColor(tileOutlineColor);
            g.drawString(customGroundItem.toString(), customGroundItem.getBounds().x, customGroundItem.getBounds().y - customGroundItem.getYOffset());
            g.setColor(itemTextColor);
            g.draw(customGroundItem.getPosition().getPolygon(script.getBot()));
        }
    }

}

CustomGroundItem.java

Spoiler


import org.osbot.rs07.api.map.Position;

import java.awt.*;

public class CustomGroundItem {
    private String name;
    private Position position;
    private int amount;
    private int yOffset;
    private Rectangle bounds;

    public CustomGroundItem(String name, Position position, int amount, int yOffset, Rectangle bounds) {
        this.name = name;
        this.position = position;
        this.amount = amount;
        this.yOffset = yOffset;
        this.bounds = bounds;
    }

    public boolean equals(CustomGroundItem customGroundItemToCompare) {
        return customGroundItemToCompare.getName().equals(this.getName()) && customGroundItemToCompare.getPosition().equals(this.getPosition());
    }

    public Position getPosition() {
        return position;
    }

    public void addAmount(int amount) {
        this.amount += amount;
    }

    public int getAmount() {
        return amount;
    }

    public String getName() {
        return name;
    }

    public int getYOffset() {
        return yOffset;
    }

    public void setYOffset(int yOffset) {
        this.yOffset = yOffset;
    }

    public Rectangle getBounds() {
        return bounds;
    }

    @Override
    public String toString() {
        return this.name + " [" + this.amount + "]";
    }
}

CustomGroundItemsList.java

Spoiler


import java.util.ArrayList;

public class CustomGroundItemsList {

    private ArrayList<CustomGroundItem> customGroundItems;


    public CustomGroundItemsList() {
        this.customGroundItems = new ArrayList<>();
    }

    public ArrayList<CustomGroundItem> getCustomGroundItems() {
        return customGroundItems;
    }

    public boolean listContainsCustomGroundItem(CustomGroundItem customGroundItemToCompare) {
        for (CustomGroundItem customGroundItem : customGroundItems) {
            if (customGroundItem.equals(customGroundItemToCompare)) {
                return true;
            }
        }
        return false;
    }

    public void add(CustomGroundItem customGroundItem) {
        boolean needsToLoop = true;
        boolean broke = false;
        int index = 0;
        while (needsToLoop) {
            for (int i = 0; i < customGroundItems.size(); i++) {
                if (customGroundItem.equals(customGroundItems.get(i))) {
                    customGroundItem.addAmount(customGroundItems.get(i).getAmount());
                    customGroundItem.setYOffset(customGroundItems.get(i).getYOffset());
                    index = i;
                    customGroundItems.remove(i);
                    broke = true;
                    break;
                }
            }
            if (!broke) {
                customGroundItems.add(index, customGroundItem);
                needsToLoop = false;
            } else {
                broke = false;
            }
        }
    }

}

 

 

 

Edited by BravoTaco

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...