Fix preview roll chances ignoring permission-locked rewards - #327
Open
GenOpenDiesel wants to merge 1 commit into
Open
Fix preview roll chances ignoring permission-locked rewards#327GenOpenDiesel wants to merge 1 commit into
GenOpenDiesel wants to merge 1 commit into
Conversation
The crate preview always computed roll chances against the global reward pool. Because the actual roll excludes rewards a player cannot win (gated by permissions/requirements), a player without access saw the locked reward hidden while the remaining rewards still displayed their global percentages, which no longer summed to 100%. Add a player-aware getRollChance(Player) that derives odds from the pool actually available to that player, at both the rarity and reward level, and use it in PreviewMenu. The no-arg getRollChance() now delegates to the global pool, so editor/admin displays are unchanged. A reward the player cannot win reports 0%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Roll chances shown in the crate preview are always computed against the global reward pool (
getRollChance()sums weights overcrate.getRewards(rarity), ignoring the viewer).However, the actual roll excludes rewards a player cannot win —
Crate.rollReward(player, rarity)builds its pool fromgetRewards(player, rarity), which filters bycanWin(player)(permissions/requirements), at both the rarity and the reward level.Result: a player without permission to a gated reward sees that reward hidden in the preview (
Hide_Unavailable), while every remaining reward still shows its global percentage. Those percentages no longer sum to 100% and understate the player's real odds, so the preview looks broken.Fix
Add a player-aware
getRollChance(@Nullable Player player)that derives the chance from the pool actually available to that player:Crate#getRarities(@Nullable Player)— rarities reachable by the player.Rarity#getRollChance(Crate, @Nullable Player)— rarity chance over the player's reachable rarities.AbstractReward#getRollChance(Player)— within-rarity weight over the player's winnable rewards; returns0%for a reward the player cannot win.PreviewMenunow fills%reward_roll_chance%/%reward_rarity_roll_chance%using the viewer.The existing no-arg
getRollChance()simply delegates togetRollChance(null)(the global pool), so editor/admin displays and any other callers are unchanged.Behaviour after the fix
Hide_Unavailable: false: a locked reward shows0%alongside the existing "no access" lore.Notes
Compile not run locally (no Maven configured on this machine); changes are additive and were reviewed by hand. The change is behaviorally scoped to the preview — rolling logic is untouched.