l2- / template-plugin

BSD 2-Clause "Simplified" License
7 stars 8 forks source link

Predicted hit often off by +1 #52

Closed CreativeTechGuy closed 1 year ago

CreativeTechGuy commented 1 year ago

I've noticed that the predicted hit is either correct, or +1 higher than the real value. I've started to track the XP values and situations which cause this and I cannot seem to figure out what the math is that would result in it. At first I assumed a rounding error but it doesn't seem like it.

Situation: Fire bolt, 42 xp drop, 11 predicted hit, actual hit 10. Since the spell gives a base XP of 22.5, that would leave 19.5 xp left for the damage which would be 9.75. Similarly, a 43 xp drop was predicted at 11 and actually hit a 10. But sometimes I'll see a 42 xp drop and it'll predict a 10 and actually hit a 10.

I'm guessing there's some rounding happening somewhere but it's unclear why it's inconsistent. It makes sense if it's not perfectly accurate, but it'd be ideal if the predicted hit was more conservative (opting for -1 of the real value) than overestimating. It's better to think you only hit a 10 and end up hitting 11 than thinking you hit 11 and only hit a 10.

Is it possible to round down and/or subtract one when there's ambiguity in the predicted hit amount?

l2- commented 1 year ago

Not much to fix here sadly. The problem you are seeing is because the plugin uses the HP xp gained to calculate hit hit = round(HP xp * 3 / 4) assuming no xp bonuses for the target you're hitting. The HP xp isn't alway accurate since the server rounds it before sending it to the client leading to the off by 1 errors you've seen. No real way for the plugin to figure out the xp has been rounded either so to the plugin there aren't any ambiguities. It is just following the same formula.

CreativeTechGuy commented 1 year ago

I think the round part is the ambiguity I'm referring to. I started collecting data and running the numbers. Here's one example I found.

Similarly:

Or another example

It seems like a lot of the mistakes are when the hit calculation ends in a .5.

I see 3 different groups:

I think this can be reasonably solved and will result in a more accurate estimate as the middle values will be rounded down rather than up.

l2- commented 1 year ago

Your anecdotal evidence is not enough to prove the current formula wrong. Very simply; 2 HP xp can be and often is a 2 hit. I need a reputable source before I start testing a new formula. Also you have to accept it will never be perfect because of the server side rounding. The predicted hit functionality is just a small gimmick that tries to predict the actual hit with imperfect information hence why it is called predicted hit.

Also side note, in case you encounter very wrong predicted hits in the future, this is all assuming the target has 1.0 bonus xp multiplier and there is countless of npcs in the game that have a different multiplier. Some are included in a json file in the plugin but some are not.

CreativeTechGuy commented 1 year ago

Also you have to accept it will never be perfect because of the server side rounding.

I am not trying to make it perfect. I'm trying to make it so that whenever it's wrong it's always wrong with a number lower than the real, currently it's always wrong with a predicted number that is higher than the real. You have to admit that gameplay wise and human psychology wise, it's better to be surprised by something being wrong in your favor than something wrong not in your favor.

Let's take the 2 HP XP example, let's just assume that 50% of the time it's a 1 and 50% it's a 2. Currently it always says 2, it'd be better if it always said 1. It's still just as wrong, but it'll be a benefit to the player when it's wrong rather than a detriment.

CreativeTechGuy commented 1 year ago

For the record, I tested the theory with Wyrms which have a 2.5% xp boost. The predicted hit incorrect less often, but always incorrect by predicting lower than the actual hit by 1.

I think a very safe change to make would be the following:

This would be very conservative and just improve the case which leads to predicting one too high without affecting anything else.

l2- commented 1 year ago

I'm not going to change to formula to miss predict hits just so it accidentally correctly predicts edge cases. If you want the behavior you're describing you can just set the xp multiplier in the config to something slightly above 1 such as 1.01. This should cause the value before rounding to shift slightly resulting in behavior you want.