Skip to content

Fix preview roll chances ignoring permission-locked rewards - #327

Open
GenOpenDiesel wants to merge 1 commit into
nulli0n:masterfrom
GenOpenDieselorg:fix/preview-permission-odds
Open

Fix preview roll chances ignoring permission-locked rewards#327
GenOpenDiesel wants to merge 1 commit into
nulli0n:masterfrom
GenOpenDieselorg:fix/preview-permission-odds

Conversation

@GenOpenDiesel

Copy link
Copy Markdown

Problem

Roll chances shown in the crate preview are always computed against the global reward pool (getRollChance() sums weights over crate.getRewards(rarity), ignoring the viewer).

However, the actual roll excludes rewards a player cannot winCrate.rollReward(player, rarity) builds its pool from getRewards(player, rarity), which filters by canWin(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; returns 0% for a reward the player cannot win.
  • PreviewMenu now fills %reward_roll_chance% / %reward_rarity_roll_chance% using the viewer.

The existing no-arg getRollChance() simply delegates to getRollChance(null) (the global pool), so editor/admin displays and any other callers are unchanged.

Behaviour after the fix

  • Player without permission: locked reward stays hidden, remaining rewards show their real odds and sum to 100%.
  • Player with permission: unchanged.
  • With Hide_Unavailable: false: a locked reward shows 0% 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.

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%.
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