Jump to content

Goal Based Event system


Septron

Recommended Posts

This is just something I threw together really quick

 

import org.osbot.script.rs2.skill.Skill;

public class Goal {
    
    public final Skill skill;
    public final int target;
    
    public final GoalEvent event;
    
    public Goal(Skill skill, int target, GoalEvent event) {
        this.skill = skill;
        this.target = target;
        this.event = event;
    }
}

import org.osbot.script.Script;

public abstract class GoalEvent {
    
    private final Script script;
    
    public GoalEvent(Script script) {
        this.script = script;
    }
    
    public abstract void onGoalReached();
}

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.osbot.script.Script;


public class HandleGoals {
    
    private final List<Goal> goals;
    
    private final Script script;
    
    public HandleGoals(Script script) {
        this.script = script;
        this.goals = new ArrayList<>();
    }
    
    public void provide(Goal... goals) {
        for(Goal goal : goals) {
            if(!this.goals.contains(goal))
                this.goals.add(goal);
        }
    }
    
    public void remove(Goal... goals) {
        for(Goal goal : goals) {
            if(this.goals.contains(goal))
                this.goals.remove(goal);
        }
    }
    
    public boolean check() {
        Iterator<Goal> iterator = this.goals.iterator();
        while(iterator.hasNext()) {
            Goal goal = iterator.next();
            if(goal.target >= this.script.client.getSkills().getCurrentLevel(goal.skill)) {
                goal.event.onGoalReached();
                this.remove(goal);
                return true;
            }
        }
        return false;
    }
}

Example Implementation...
 

        //put this anywhere in the script class
        private HandleGoals handle = null;

        //in your onStart put this...
        this.handle = new HandleGoals(this);
        handle.provide(new Goal(Skill.ATTACK, 99, new GoalEvent(this) {
            @Override
            public void onGoalReached() {
                log("I have reached my goal, tell me what to do now in this method");
            }
            
        }));
        
        //in your onLoop put this...
        if(handle != null)
            handle.check();
Edited by Septron
  • Like 4
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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