Jump to content

Pouch algorithm for adding pouch support to your script.


Brainfree

Recommended Posts

If you would like to add pouches (any type) into your script, and want to know what type of rune, and how much is in that pouch, this snippet is for you.

 

Pouch

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

public enum Pouch {

    SMALL(5509, -1, 1, 3, 3),
    MEDIUM(5510, 5511, 50, 6, 3),
    LARGE(5512, 5513, 50, 9, 7),
    GIANT(5514, 5515, 75, 12, 9);

    public final int normalID;
    public final int degradedID;
    public final int requiredLevel;
    public final int normalHold;
    public final int degradedHold;

    private Pouch(int AssignedNormalID, int AssignedDegradedID,
                  int AssignedRequiredLevel, int AssignedNormalHold,
                  int AssignedDegradedHold
    ) {
        this.normalID = AssignedNormalID;
        this.degradedID = AssignedDegradedID;
        this.requiredLevel = AssignedRequiredLevel;
        this.normalHold = AssignedNormalHold;
        this.degradedHold = AssignedDegradedHold;
    }

    public static EssenceType getPouchEssenceType(Client client, Pouch p) {
        int setting = client.getConfig(720);
        switch (p) {
            case SMALL:
                return setting >= 128 ? EssenceType.PURE : (setting >= 0x40) &&
                        (setting < 0x80) ? EssenceType.NORMAL : null;
            case MEDIUM:
                if (setting >= 64)
                    setting %= 64;
                return setting >= 32 ? EssenceType.PURE : (setting >= 0x10) &&
                        (setting < 0x20) ? EssenceType.NORMAL : null;
            case LARGE:
                if (setting >= 64)
                    setting %= 64;
                if (setting >= 16)
                    setting %= 16;
                return setting >= 9 ? EssenceType.PURE : (setting >= 0x4) &&
                        (setting < 0x9) ? EssenceType.NORMAL : null;
            case GIANT:
                if (setting >= 64)
                    setting %= 64;
                if (setting >= 16)
                    setting %= 16;
                if (setting >= 4)
                    if (setting < 0x9) setting %= 0x4;
                    else
                        setting %= 0x9;
                return setting == 0x2 ? EssenceType.PURE :
                        setting == 0x1 ? EssenceType.NORMAL : null;
        }
        return null;
    }

    public static int getEssenceCount(Client client, Pouch p) {
        int setting = client.getConfig(486) - 0x40000000;
        switch (p) {
            case GIANT:
                return setting / 0x40000;
            case LARGE:
                setting %= 262144;
                return setting / 0x200;
            case MEDIUM:
                setting %= 262144;
                setting %= 512;
                return setting / 8;
            case SMALL:
                setting %= 262144;
                setting %= 512;
                return setting % 8;
        }
        return -1;
    }
        
    public int getNormalID() {
        return normalID; 
    }
    
    public int getDegradedID() {
        return degradedID;
    }
    
    public int getNormalHold() {
        return normalHold;
    }

    public int getDegradedHold() {
        return degradedHold;
    }
    
    public int getRequiredLevel() {
        return requiredLevel;
    }

    public EssenceType getEssencesType(Client client) {
        return getPouchEssenceType(client, this);
    }

    public int getEssencesAmount(Client client) {
        return getEssenceCount(client, this);
    }
} 

And for wrapping the rune types:

public enum EssenceType {
    PURE(7936),
    NORMAL(1436);
    final int ID;

    private EssenceType(int ID) {
        this.ID = ID;
    }

    public int getID() {
        return this.ID;
    }
}

Example:

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "Brainfree", info = "Pouch display", version = 1.0, name = "Pouch viewer")
public class Example extends Script {

    public int onLoop() {
        return 35;

    }

    public void onPaint(Graphics g) {
        int x = 10;
        int y = 15;
        EssenceType type;
        for (Pouch pouch : Pouch.values()) {
            type = pouch.getEssencesType(client);
            g.drawString(pouch.name() + ":[Type: " + (type == null ? "None" : type.name()) + ",Quantity: " + pouch.getEssencesAmount(client) + "]", x, y);
            y += 15;
        }
    }
}

Hope you enjoy.

Edited by Brainfree
  • Like 4
Link to comment
Share on other sites

Stark has pointed out a bug in the counting, which has now been fixed.

 

PS: The problem was solves my shifting the switch cases, if there is a problem with the essences, run my example as a debug, and see if simply adjusting the switch cases are the solution, if there is a problem. 

Edited by Brainfree
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...