Speaax / Farming-Helper

Helps with farming
BSD 2-Clause "Simplified" License
0 stars 4 forks source link

Automatically check for Achievement diaries #14

Open Speaax opened 10 months ago

Speaax commented 10 months ago

Being worked on branch: check-achievement-diary image

Currently Ardy cloak and Explorers ring take one slot each for 2, 3 and 4. Automatically checking for what diary the player has completed will allow for 1 teleport option.

Also checking for Kandarin hard will allow for automatically selecting Seers Village teleport over Camelot teleport.

othyn commented 10 months ago

May be complicated, but would be cool for the option to default to an 'backup' teleport method once all of your uses on the cape/ring have been used for the day.

Speaax commented 10 months ago

It was fairly easy, but I had issues with something I'm not even sure what to describe. It was a sort of delay on fetching the information, had to be run in a different way than the rest of the code so referencing it caused issues. Looking back at it i probably could have fetched the information once and stored it in a separate variable, and reference it separate variable as a work around.

I decided to give up on it for the time being because of the headache of not understanding the problem.

And yes, a backup option for Ardy cloak/Explorers ring would be nice.

Speaax commented 10 months ago

https://static.runelite.net/api/runelite-api/net/runelite/api/Varbits.html

There is something called Varbits. I think the best way i can describe Varbits is that its player information stored on the account or something. Varbits is also the way i read the state of farming patches.

Edit: I just assumed you meant getting the information about the completion of diaries. If you were thinking about the logic of it all I guess that is some work as well.

Speaax commented 10 months ago

After giving it a little go I think remember why it was problematic last time.

I struggled with setupArdougneLocation(). Since it sets up all the locations at launch it can't check what Ardy diary you have done before you have logged in.

In Location.java we have this. Would it be possible to update the values of a location once to player has logged in? Same with item requirement?

public void setId(int id) {
            this.id = id;
        }
Speaax commented 10 months ago
public Integer CheckArdyDiaryAndReturnItemID()
    {
        if (client.getVarbitValue(Varbits.DIARY_ARDOUGNE_EASY) == 1) {
            return (ItemID.ARDOUGNE_CLOAK_1);
        }
        if (client.getVarbitValue(Varbits.DIARY_ARDOUGNE_MEDIUM) == 1) {
            return (ItemID.ARDOUGNE_CLOAK_2);
        }
        if (client.getVarbitValue(Varbits.DIARY_ARDOUGNE_HARD) == 1) {
            return (ItemID.ARDOUGNE_CLOAK_3);
        }
        if (client.getVarbitValue(Varbits.DIARY_ARDOUGNE_ELITE) == 1) {
            return (ItemID.ARDOUGNE_CLOAK_4);
        }
        return null;
    }

I think something like this is all that's needed to return the ardy cloak ID based on diaries completed.

If this seems like a reasonable and possible way of doing it I would like to try implementing it myself as a revenge from last time >:)

Speaax commented 10 months ago

Added logic for checking Ardy diary and returning cape ID based on wh…

CheckArdyDiaryAndReturnItemID() seems to return ID based on Achievement diary completed. Im not sure how to update teleport to the new values. I think the last requirement to get this to work is being able to add/update location.

Could need a review of the code.

public void setupDiarySpecificTeleports() {
        int ardyCloak = plugin.CheckArdyDiaryAndReturnItemID();

CheckArdyDiaryAndReturnItemID() cannot be run at the start or initialization as it requires the user to be logged in.

Is it an option to change when we initialize setupLocations() to when the user presses one of the start run buttons?

Edit: Changing when we do setupLocation() seems like it did the trick. Although it seems like its checking for int ardyCloak = plugin.CheckArdyDiaryAndReturnItemID(); every frame. This would need to be fixed. Edit 2: Did Ardougne herb run patch and the next one after that and had no issues.

othyn commented 10 months ago

Edit: I just assumed you meant getting the information about the completion of diaries. If you were thinking about the logic of it all I guess that is some work as well.

Yeah, I was just talking about the 'backup' logic, but it was still a really interesting read. Thanks for sharing!

Speaax commented 10 months ago

Yeah, I was just talking about the 'backup' logic,

Yesterday i realized it, but i figured it was just information that you potentially could need if you didn't know about it yet.

Currently setupLocation() is ran every time you press the herb run button. Should I clear the Location and Teleport before setupLocation() or will it just overwrite/ignore locations that already exist?

othyn commented 10 months ago

but i figured it was just information that you potentially could need if you didn't know about it yet.

Oh 100% it was an interesting read and useful info, thanks for sharing it.

Currently setupLocation() is ran every time you press the herb run button. Should I clear the Location and Teleport before setupLocation() or will it just overwrite/ignore locations that already exist?

This is part of the refactor I was trying to achieve. If I were approaching something like this from scratch, I would try to define the Teleport/Location bindings for each patch in some form of dataset, either in a static entity that can be loaded in at runtime (in code) or a flat file configuration like a json file that holds them all that again could just be loaded in at runtime. I build a timer app in Swift that did this and it made things really easy to define a new patch/'run', for an iOS app I sadly never released and is just sat in a repo somewhere complete and ready to ship 😂

Either way, it means that the static data is only loaded into memory and defined once centrally, the 'runs' should only then be calling in the ones it needs to build its own dynamic set of them when the button is pressed. This will become especially prevalent in #23 when the 'set' will have to be dynamically calculated at runtime, at the moment that will mean a re-definition and then at the run, where as we should aim to abstract out the definition side of it.

I still haven't quite got my head around the full end-to-end execution chain of all the classes/methods to understand properly what and where to refactor. But my gut feeling is we should be able to collapse back all the individual definitions centrally (which I did, but was met with a race condition similar to your one above) and simplify some of the entities that we have being passed around. Although doing that requires a full understanding of the above, which I don't yet have - which also may humble me on this whole idea as my idea may turn out to be complete poo with more of an understanding of how things are now 😄

Speaax commented 10 months ago

I still haven't quite got my head around the full end-to-end execution chain of all the classes/methods to understand properly what and where to refactor.

Don't worry, I don't fully understand it myself yet xD While ChatGPT can write functioning code, it didn't do well with files once they got too large or multiple files, I had to ask for small code samples that isolated would do what I wanted, and then stitch several pieces together. It got a bit out of hand for someone with my experience, so it became hard for me to add in features or simplify/combining existing ones.

In #23 Would each "run button" be able to be stored and loaded as a JSON, and just pass the whole JSON according to what button clicked to a class that just loops through all the locations, and only moves to the next location once all patches in a location is completed? If the panel code reads all JSON files in a folder and generates an expandable button for a run like #23 suggests, and each Location is a "Card" we can add in to any run, couldn't we create 1 class to run it all no matter what type of run it is? Maybe predefine some code for each individual card to ensure weird teleports and highlights are dealt with properly, idk. (I'm no longer sure if this is the play, as it sounds like a lot of work. I guess this would be a rewrite of everything almost)

The more I wrote the worse it sounded, My fever is all over the place and I'm not sure how well described this is. But I might as well post it again just incase it has something going on.