8000 Possible fix to XP per kill rounding/truncation issue by cpevors · Pull Request #740 · cmangos/mangos-tbc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Possible fix to XP per kill rounding/truncation issue #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cpevors
Copy link
@cpevors cpevors commented May 15, 2025

The multiplication steps return nBaseExp * (1.0f + (0.05f * nLevelDiff)); and return nBaseExp * (1.0f - (float(nLevelDiff) / ZD)); produce float values, but since the return type of BaseGain is uint32, the compiler implicitly truncates the XP value when converting from float to uint32.

By changing the return type of BaseGain from uint32 to float, this preserves the fractional XP value until the very end, when the XP value is converted to an integer using std:nearbyint().

I did very limited testing, but, for example, killing a Level 3 mob as Level 2 player did, in fact, yield 58 rather than 57 XP after this change, as intended (I observed on official Blizzard realms that XP per kill is always 8000 rounded up rather than truncated/rounded down).

This conversation was originally had over in VMaNGOS, where I proposed a similar change. I observed the same behaviour in CMaNGOS.

I, in no way, pretend to be an expert, and I'm happy to be educated in a different direction if this change is flawed in some way.

cpevors added 2 commits May 15, 2025 11:21
The multiplication step '(ownerlevel * 5 + nBaseExp) * BaseGainLevelFactor()' produces a 'float' value, but since the return type of 'BaseGain' is 'uint32', the compiler implicitly truncates the XP value when converting from 'float' to 'uint32'.

By changing the return type of 'BaseGain' from 'uint32' to 'float', this preserves the fractional XP value until the very end, when the XP value is converted to an integer using 'std:nearbyint()'.

I did very limited testing, but killing a Level 3 mob as Level 2 player did, in fact, yield '58' rather than '57' XP.
@al3xc1985
Copy link

Nice one. Ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0