Jump to content

Man pickpocket suicider source


Botre

Recommended Posts

Some code I toyed around with yesterday to test out a few things:

 

Core:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.util.Comparator;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ScriptManifest(author = "Botre", info = "", logo = "", name = "Experiment", version = 0.0)

public class ExperimentalScript extends Script {

    private ScriptClock clock = new ScriptClock(1.6);

    private String name = "Man";

    private String action = "Pickpocket";

    private Predicate<NPC> validityPredicate = o -> o != null && o.exists() && o.getName().equals(name) && o.hasAction(action) && getMap().canReach(o.getPosition());

    private Comparator<Entity> distanceComparator = EntityComparator.create(this, EntityComparator.Type.DISTANCE_FROM_PLAYER);

    private Target<NPC> target = new Target<>(validityPredicate, () -> getNpcStream().filter(validityPredicate).min(distanceComparator));

    @Override
    public int onLoop() throws InterruptedException {
        if (target.valid() || target.find()) {
            target.get().interact(action);
        }
        return clock.tick();
    }

    private Stream<RS2Object> getObjectStream() {
        return getObjects().getAll().stream();
    }

    private Stream<NPC> getNpcStream() {
        return getNpcs().getAll().stream();
    }

}

Target:

import java.util.Optional;
import java.util.function.Predicate;

/**
 * Created by Bjorn on 19/07/2015.
 */
public class Target<T> {

    private T target;
    private TargetSearcher<T> searcher;
    private Predicate<T> validity;

    public Target(Predicate<T> validity, TargetSearcher<T> searcher) {
        this.validity = validity;
        this.searcher = searcher;
    }

    /**
     * @return The current target.
     */
    public T get() {
        return target;
    }

    /**
     * @return Whether the current target is valid.
     */
    public boolean valid() {
        if (validity.test(target)) {
            return true;
        } else {
            target = null;
            return false;
        }
    }

    /**
     * Searches for and assigns a new target by making a call to the search() method.
     *
     * @return Whether a new target was find.
     */
    public boolean find() {
        Optional<T> optional = searcher.search();
        if (optional.isPresent()) {
            target = optional.get();
            return true;
        } else {
            return false;
        }
    }

}

Target searcher:

import java.util.Optional;

/**
 * Created by Bjorn on 21/07/2015.
 */
public interface TargetSearcher<T> {

    /**
     * Searches for a new target.
     *
     * @return The new target.
     */
    Optional<T> search();

}

Script clock:

/**
 * Created by Bjorn on 19/07/2015.
 */
public class ScriptClock {

    private double loopsPerSecond ;
    private int millisecondsPerLoop;
    private long systemMilliseconds;
    private long deltaMilliseconds;
    private int sleepMilliseconds;

    public ScriptClock(double loopsPerSecond) {
        this.loopsPerSecond = loopsPerSecond;
        millisecondsPerLoop = (int) ((1 / loopsPerSecond) * 1000);
        systemMilliseconds = System.currentTimeMillis();
    }

    public int tick() {
        deltaMilliseconds = System.currentTimeMillis() - systemMilliseconds;
        systemMilliseconds = System.currentTimeMillis();
        sleepMilliseconds = (int) (millisecondsPerLoop - deltaMilliseconds);
        return sleepMilliseconds > 0 ? sleepMilliseconds : 0;
    }

}

Entity comparator:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;

import java.util.Comparator;

/**
 * Created by Bjorn on 20/07/2015.
 */
public final class EntityComparator {

    public enum Type {
        DISTANCE_FROM_PLAYER,
    }

    public static Comparator<Entity> create(MethodProvider mp, Type type) {
        switch(type) {
            case DISTANCE_FROM_PLAYER: return (a, b) -> mp.getMap().distance(a.getPosition()) - mp.getMap().distance(b.getPosition());
        }
        return null;
    }

}

  • Like 2
Link to comment
Share on other sites

You're running me out of business here :'(

Looks good though! Remember that map.distance() is deprecated though smile.png

 

Sowyyy, tbh I don't think many people even know how to compile this so dw :p

 

I think it was just getMap().distance(Entity) that was deprecated, getMap().distance(Entity.getPosition()); hasn't been touched (yn).

Link to comment
Share on other sites

Sowyyy, tbh I don't think many people even know how to compile this so dw tongue.png

 

I think it was just getMap().distance(Entity) that was deprecated, getMap().distance(Entity.getPosition()); hasn't been touched (yn).

 

I have no idea lol, I've never touched those functions :p better be safe than sorry!

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.
Note: Your post will require moderator approval before it will be visible.

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