Jump to content

"duplicate" objects?


Recommended Posts

Posted (edited)
package org;


import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Plugin;

import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test extends Plugin {
    public String treeToCut = "Tree";

    private Predicate<RS2Object> suitableObj = n ->
            n.getName().equals(treeToCut) &&
                    getMap().canReach(n) &&
                    getMap().distance(n) < 4;

    private java.util.List<RS2Object> treeObjs;

    @Override
    public int onLoop() throws InterruptedException {
        log("onLoop: ");

        List<RS2Object> allObjs = getObjects().getAll();
        log("getObjects().getAll().size(): " + allObjs.size());

        int count = 0;
        for(RS2Object obj : allObjs){
            if (obj.getName().equals(treeToCut) && getMap().distance(obj) < 4) {
                log("AAA " + obj.getX() + " " + obj.getY());
                count++;
            }
        }
        log("count: " + count);


        treeObjs = getObjects().getAll().stream().filter(suitableObj).collect(Collectors.toList());

        if (!treeObjs.isEmpty()) {
            log("treeObjs.size(): " + treeObjs.size());
            treeObjs.sort(Comparator.<RS2Object>comparingInt(a -> getMap().distance(a)).thenComparingInt(b -> getMap().distance(b)));
            log("sort treeObjs.size(): " + treeObjs.size());

            treeObjs.forEach(obj -> log(obj.getX() + " " + obj.getY()));
        } else {
            log("treeObjs.isEmpty()");
        }


        return 2000;
    }


}
onLoop: 
getObjects().getAll().size(): 8618
AAA 3163 3454
AAA 3163 3454
AAA 3163 3454
AAA 3163 3454
count: 4
treeObjs.size(): 4
sort treeObjs.size(): 4
3163 3454
3163 3454
3163 3454
3163 3454

Why? What is the meaning and different of these "duplicate" objects?

Thanks:)

Edited by Pegasus
Posted (edited)

Just a guess, but it may be that Objects#getAll iterates the coordinates of the region graph, adding all InteractableObjects found. If this is the case, the result might be that an object of 2x2 size (large object that spans 4 tiles) would be added multiple times, as it can be found on multiple coordinates, even though the objects 'anchor position' is the same.

Depending on whether or not they're the same object instance, using Collectors.toSet might function as a workaround

Edited by FrostBug
  • Heart 1

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...