Jump to content

Preview of my noob-friendly API


Botre

Recommended Posts

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

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

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

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