Wet-Boys / LookingGlass

A QoL UI mod that exposes statistics for items and the player, adjusts the size and features of command and scrapper menus, and much more. Fully open source and compatible with RiskUI!
https://thunderstore.io
GNU Lesser General Public License v3.0
9 stars 5 forks source link

critWithLuck bugged with negative luck #12

Closed Shiranui-Izayoi closed 1 month ago

Shiranui-Izayoi commented 1 month ago

critWithLuck seemed bugged when the player had negative luck AKA Purity. When playing yesterday I had 100% crit chance and 1 purity and the UI was showing I had 1% crit chance. Despite how in game I am critting on every single shot.

So I had a look at the github code for how it is calculated and found that the calculation for negative luck found here looked kinda to simple compared to the one for positive luck. So I ran it through a complier to check, and no matter the value of crit it always output a value of 1.

And well maybe a dumb idea but I wanted to see if I could help solve it so the rest of this message is that. I apologise if I should have just reported the error and not messed around trying to find a fix when I don't know the mod.

Basically I then looked at some other UI mods as well as online Probability Calculators to try to get an idea of how to calculate/code it. And I did notice that that most would seperate the luck calculation into it's own part/static/function. Then call that from a single calculation.

Admittedly I don't know C# very well, so I messed around with the calculation in Python which I know ever so slightly better. Then used an online code translator to convert it to C#. So apologises if what follows is completely broken and unusable. I did run it through a C# complier just to see and it did work. But I know that it can be very different when loaded into a mod or program. Instead of just compling. Either way maybe at least the general idea helps? Not sure.

static float LuckCalculation(float chance, float luck) {
    if (luck == 0)
    {
        return chance;
    }
    else if (luck < 0)
    {
        return (int) chance + (float) Math.Pow(chance % 1, Math.Abs(luck) + 1);
    }
    else
    {
        return (int) chance + (1 - (float) Math.Pow(1 - (chance % 1), Math.Abs(luck) + 1));
    }
}

This was for calculating the luck. And for the actual crit chance calculation it was as follows. ( 100 * ((int)crit / 100) + 100 * LuckCalculation(crit % 100 * 0.01f,luck))

Though I am not sure if it might need a tostring etc. Though the variables most likely need to be changed to fit what you have. I would guess it needs cachedUserBody in front but not sure. Either way hope my messing around helps solve the issue a little bit.

ToastedOven commented 1 month ago

Thanks for the report, when I was making the calculation for crit/bleed in this case, I was just basing it off of the calculation on the wiki firefox_mVjsJVKSbv Which is correct as far as I know. I did a quick look at my code to verify and I found the root cause of this issue.

Comparing my code: devenv_1TFZuYHxfU

To the real equation: firefox_I2dbeWRule I pass in luck (a negative numbver), whereas the real equation passes in Purities held. (a positive number)

So the simple fix here is to just take the absolute value of the luck value.

Thanks for the report, I'll get this fixed later today

EDIT: and yeah it seems like you came to a similar conclusion. Not sure how I missed passing a negative number into the equation but it be like that

ToastedOven commented 1 month ago

fixed in v1.2.4, thanks for the report!