Jump to content

Preview of my noob-friendly API


Recommended Posts

Posted

I'm working on an extremely high-level API that sits on top of the OSBot API, makes it a bit more beginner friendly and adds plenty of shortcuts.

 

Here's how a simple pickpocketer looks like (works flawlessly):

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.ScriptManifest;

/**
 * Created by Bjorn on 21/07/2015.
 */

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

public class PickpocketScript extends BasicScript {

    private EntityDefinition definition = 
            new EntityDefinition(this)
                    .name("Man")
                    .action("Pickpocket")
                    .reachable();

    private Target<NPC> target = new Target<>(definition, Searcher.closest(this, definition));

    @Override
    public void loop() {
        if(target.valid() || target.find()){
            target.get().interact("Pickpocket");
        }
    }

}
  • Like 2
Posted

Nice dude! I had a similar idea where I was going to create my own scripting language for my scripts for presets, the following would be something that thieved from a guard:

walkto varrock
tag GUARD "Guard" NPC_TYPE
interact GUARD "Pickpocket"

My API would handle it flawlessly, with built in variables (varrock being varrock square for example), and the script would handle when to stop and restart etc.

 

Good luck :D

  • Like 1
Posted (edited)
  private EntityDefinition definition = 
            new EntityDefinition(this)
                    .name("Man")
                    .action("Pickpocket")
                    .reachable(); 

Is this supposed to be more clear than using a constructor?

 

new EntityDefinition(this 
.name("Man") 
.action("Pickpocket") 
.reachable());

vs

new EntityDefinition(
this,
"Man",
"Pickpocket",
true);

1 constructor

0 ambiguity

100% modular

100% extendable

 

So... yes? doge.png

 

On top of that, the class is wrapped around a predicate: the ability to add properties in the sequence you want makes tactical logical shortcutting a piece of pie among other cool things.

 

Source: 

public class EntityDefinition<T extends Entity> implements Predicate<T> {

    private Predicate<T> predicate;

    private MethodProvider mp;

    public EntityDefinition(MethodProvider mp) {
        this.mp = mp;
        predicate = o -> o != null && o.exists();
    }

    public EntityDefinition name(String name) {
        predicate = predicate.and(o -> o.getName().equals(name));
        return this;
    }

    public EntityDefinition action(String action) {
        predicate = predicate.and(o -> o.hasAction(action));
        return this;
    }

    public EntityDefinition reachable() {
        predicate = predicate.and(o -> mp.getMap().canReach(o.getPosition()));
        return this;
    }

    @Override
    public boolean test(T t) {
        return predicate.test(t);
    }
    
} 
Edited by Botre
  • Like 1
Posted
new EntityDefinition(this 
.name("Man") 
.action("Pickpocket") 
.reachable());

vs

new EntityDefinition(
this,
"Man",
"Pickpocket",
true);

1 constructor

0 ambiguity

100% modular

100% extendable

 

So... yes? doge.png

 

On top of that, the class is wrapped around a predicate: the ability to add properties in the sequence you want makes tactical logical shortcutting a piece of pie among other cool things.

 

Source: 

public class EntityDefinition<T extends Entity> implements Predicate<T> {

    private Predicate<T> predicate;

    private MethodProvider mp;

    public EntityDefinition(MethodProvider mp) {
        this.mp = mp;
        predicate = o -> o != null && o.exists();
    }

    public EntityDefinition name(String name) {
        predicate = predicate.and(o -> o.getName().equals(name));
        return this;
    }

    public EntityDefinition action(String action) {
        predicate = predicate.and(o -> o.hasAction(action));
        return this;
    }

    public EntityDefinition reachable() {
        predicate = predicate.and(o -> mp.getMap().canReach(o.getPosition()));
        return this;
    }

    @Override
    public boolean test(T t) {
        return predicate.test(t);
    }
    
} 

 

That's actually really good use of Predicate, props to you! :doge:

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