Lyliya / RocketStats

BakkesMod plugin for session information (MMR, Win, Loss, Streak, eg.) in game and in OBS
https://bakkesplugins.com/plugins/view/30
MIT License
29 stars 7 forks source link

Streak counter should check all counters when determining if it will reset to 0 #33

Closed CWO333 closed 11 months ago

CWO333 commented 1 year ago

I have been tracking down an issue with the streak counter and I found the cause. When in game, I would start a new session and play a few games on one playlist. Let's say I win 2 games so my streak is +2. Then I switch playlists and I lose the next game. My streak should be -1 but it's not, it's +1. This is because only the streak counter for the current playlist is checked. Another example, I start a new game after being on a 3 game winning streak last time I played. My streak variables should be:

always.streak = 3;
session.streak = 0;
stats[current.playlist].streak = 0;
always_gm[current.playlist].streak = 3;

Let's say I lose my first game.

GameEnd -> Game Lost says:

if (stats[current.playlist].streak > 0)
            {
                always.streak = 0;
                session.streak = 0;
                stats[current.playlist].streak = 0;
                always_gm[current.playlist].streak = 0;
            }

            --always.streak;
            --session.streak;
            --stats[current.playlist].streak;
            --always_gm[current.playlist].streak;

Since stats[current.playlist].streak == 0 my variables look like this:

always.streak = 2;
session.streak = -1;
stats[current.playlist].streak = -1;
always_gm[current.playlist].streak = 2;

When they should look like this:

always.streak = -1;
session.streak = -1;
stats[current.playlist].streak = -1;
always_gm[current.playlist].streak = -1;

20230522140504_1

Arubinu commented 1 year ago

To confirm, were you in "Session" or "Always" mode? And thank you very much for this feedback 👍

CWO333 commented 1 year ago

I'm currently in Session mode.

CWO333 commented 1 year ago

I just tested a change to fix this and make the code look somewhat clean. I don't program in C/C++ but this seems benign enough that it won't hurt anything.

For GameEnd -> Game Won instead of

if (stats[current.playlist].streak < 0)
            {
                always.streak = 0;
                session.streak = 0;
                stats[current.playlist].streak = 0;
                always_gm[current.playlist].streak = 0;
            }

You could use

            always.streak = std::max(0, always.streak);
            session.streak = std::max(0, session.streak);
            stats[current.playlist].streak = std::max(0, stats[current.playlist].streak);
            always_gm[current.playlist].streak = std::max(0, always_gm[current.playlist].streak);

For GameEnd -> Game Lost and GameDestroyed

            always.streak = std::min(0, always.streak);
            session.streak = std::min(0, session.streak);
            stats[current.playlist].streak = std::min(0, stats[current.playlist].streak);
            always_gm[current.playlist].streak = std::min(0, always_gm[current.playlist].streak);
Arubinu commented 1 year ago

Thanks, I'll try that when I have a moment :)

Arubinu commented 1 year ago

So I just did a test and thought about it. The Streak is correct since it is based on a "Session" save.

If you change playlists you stay in the session until you restart the game.

Arubinu commented 1 year ago

I tangle my brushes... Is it the heat xD

Yes so the streak is sence whatever happens return to 0 when we lose and we are positive, and the same for the reverse, hmm.

I will test your code in the coming days I think.

And indeed there is a problem because it comes back to zero one game after only.

CWO333 commented 1 year ago

Basically this is why all 4 streaks need to be evaluated independently to see if they need to be reset since all 4 are being increased or decreased. They could still be a mixed combination of winning and losing streaks and still be correct. To be cleaner I just removed the if and turned them into min/max functions with 0.

Lyliya commented 11 months ago

Hey @CWO333 , thanks for your feedback

It was indeed a bug from the streak calculation, this has been fixed in https://github.com/Lyliya/RocketStats/pull/34 thanks to your suggestion

Thank you