Ephenia / Pokeclicker-Scripts

Various scripts & enhancements for the game Pokéclicker.
https://github.com/Ephenia/Pokeclicker-Scripts
GNU General Public License v3.0
195 stars 261 forks source link

Fix unlimited protein usage #307

Open Grobak opened 1 year ago

Grobak commented 1 year ago

A "recent" update added 2 new vitamin types, Calcium and Carbos. This updates the listener in the "item bag" part of the "item" menu so each vitamin can be affected by this script. The pokemon list sorted for protein seems to work in console, but not in here so i used the in game code to get it to work.

I also seperated the bypassProtein function from the "main" script for readability and changed variable name to better reflect the in-game change in vitamin mecanics.

Also, this will most likely not work for the 4rth, 5th [...] vitamin added if more are added. To fix it, just add X new assignment in line 36 (but it would be great to use a better way to get this to work, this selector is shit).

Line 43 and 44 are only used if the user doesn't click on the vitamin img element but on the text or the outer box.

umbralOptimatum commented 1 year ago

A few suggestions:

And there's definitely some way to avoid that awkward interval. And probably better to just override PartyPokemon.useVitamin() than keep adding event listeners over the game's existing ones... y'know what, I have the time today, I'll make my own PR

Grobak commented 1 year ago

yeah, i didn't take that much time to find a better selector, feel free to improve it of you like. I didn't got deep inside the game code, so i have no idea how to check if the egg steps is at a X or Y value. i guess it's linked to the pokemon object, but i haven't looked into it yet

About the interval, i think it is needed because the pokemon filtered list isn't loaded at the same time the click is made, but a bit after. There is only 3 listeners, one for each vitamin type.

where is the all vitamin menu ? i haven't seen it yet, or maybe i forgot.

Edit : Just noticed the "All vitamin" button right under the vitamins. I honnestly don't think i'l look into it. I think the same listener can be used but there must be a switch or something to add. It would most likely be easier to export the vitamin override part into a separate function and call it in a new listener + the one existing now

umbralOptimatum commented 1 year ago

Yes, the interval is used because the menu isn't part of the DOM at the time, but there are other options like tying the code to execute alongside other game functions or adding the listeners once during loading before the menu is hidden. Doesn't really matter though as the listeners definitely aren't the right approach—just noticed they also interfere with the button to remove vitamins.

I rewrote the script to just modify useVitamin() in #308. Much less tangly, works for all the menus, and should support any future vitamins that get added.