Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold
Fluffee

[Snippet] Alternate Wilderness Level Calculation

Recommended Posts

The API method for getting the wilderness level does so by parsing the interfaces in the game. At times, this can be finnicky (due to an outdated interface) or slow if on LG. At any rate, the calculation in RuneScape is actually done client side, so we can copy their method.

In particular. the following code is a fork of the RuneLite code for this method, which itself is a fork of the .cs2 scripts (first, second) that the game uses to calculate the level.

As a note, you could use an instance of RSArea instead of the tileIsInBounds methods but I prefer this, less overhead. Also, why the weird math on the Y coord? I'm not sure, it's just how RS calculates the level.

    /**
     * Calculates the player's wilderness level based on their game coordinates, and not the wilderness level interface.
     * This code is based on the cs2 scripts from the RuneScape client itself, therefore the coordinates seem arbitrary
     * but they're the same one's the client uses. This same logic applies to the math on the y coordinate, which also
     * seems arbitrary but it's how the client determines the level.
     *
     * @return int containing the player's wilderness level, or 0 if the player is not in the wilderness.
     */
    public static int getWildernessLevel() {
        RSVarBit inWildernessVarbit = RSVarBit.get(5963);
        if (inWildernessVarbit == null || inWildernessVarbit.getValue() == 0) {
            return 0;
        } else if (
            tileIsInBounds(
                new RSTile(2944, 3520, 0),
                new RSTile(3391, 4351, 3),
                Player.getPosition()
            )
        ) {
            return ((Player.getPosition().getY() - (55 * 64)) / 8) + 1;
        } else if (
            tileIsInBounds(
                new RSTile(3008, 10112, 0),
                new RSTile(3071, 10175, 3),
                Player.getPosition()
            )
        ) {
            return ((Player.getPosition().getY() - (155 * 64)) / 8) - 1;
        } else if (
            tileIsInBounds(
                new RSTile(2944, 9920, 0),
                new RSTile(3391, 10879, 3),
                Player.getPosition()
            )
        ) {
            return ((Player.getPosition().getY() - (155 * 64)) / 8) + 1;
        }
        return 0;
    }

    /**
     * Checks if the player's current position is inside the passed bounds
     *
     * @param lowerBound RSTile representing the tile the player must be above
     * @param upperBound RSTile representing the tile the player must be below
     * @param checkingTile RSTile representing the tile we're checking to see if it's in the bounds
     * @return True if the player is inside the bounds, false otherwise.
     */
    public static boolean tileIsInBounds(RSTile lowerBound, RSTile upperBound, RSTile checkingTile) {
        if (checkingTile.getX() < lowerBound.getX() || checkingTile.getX() > upperBound.getX()) {
            return false;
        }
        if (checkingTile.getY() < lowerBound.getY() || checkingTile.getY() > upperBound.getY()) {
            return false;
        }

        return checkingTile.getPlane() >= lowerBound.getPlane() &&
                checkingTile.getPlane() <= upperBound.getPlane();
    }

 

  • Like 1

Share this post


Link to post
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.


  • Our picks

    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
        • Like
      • 30 replies
    • Come give us feedback on the next version of TRiBot!
        • Thanks
        • Like
      • 74 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
        • Like
      • 23 replies
    • Over the last three weeks, I've been working on upgrading our server infrastructure. It's finally ready and is now live!

      Why?

      Increased reliability - less server errors


      Increased availability - less downtime


      Increased security - keeping us and you secure


      Increased capacity - ability to serve you better


      Increased speed - less waiting for things to load


      Faster development - server and service updates will come faster


      What are the changes?

      Move from a single AWS EC2 instance to AWS ECS (Elastic Container Service)


      Distributed computing


      Load balancing


      Git management of server files and filesystem


      Redis caching


      How?

      AWS ECS (with 10 EC2 instances)


      AWS ElastiCache (Redis)


      AWS Load Balancing


      AWS EFS (Elastic file system)


      Please bare with us as I continue to tune the server for maximum performance. Slow loading speeds may occur temporarily. I thank everyone for their patience.

      Please post on this thread if you experience any issues other than slow loading times.
        • Like
      • 51 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...