Jump to content
Pegasus

"duplicate" objects?

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

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