missionpinball / mpf

Mission Pinball Framework: Open source software to run a real pinball machine.
http://missionpinball.org
MIT License
217 stars 143 forks source link

Bugfix bonus unset player vars #1833

Closed avanwinkle closed 2 months ago

avanwinkle commented 2 months ago

Summary

This PR fixes a bug in how bonus scores are calculated for player variables. Includes tests to validate.

Currently, MPF does a single evaluation on bonus entries to look for player vars, and if the player variable is not set then it assumes that the bonus entry is static and not variable-dependent. This is the correct behavior for entries without player_score_entry, but erroneously includes the bonus score for entries that have player_score_entry but that entry variable is not defined on the player. In either case, the bonus calculation falls back to a multiplier value of 1 for calculating the bonus score.

The Fix

This PR improves the logic to only look for a player variable if player_score_entry is defined, and to accept the player fallback value of 0 for the multiplier. If player_score_entry is not defined, then a fallback value of 1 is used.

With this change, bonus-driving player variables no longer need to be explicitly initialized in the player_vars: config section and will behave as expected.

Also, corrects a few leftover attributes lookups that should not iterate over collections directly.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud