Skip to content

Commit c87a824

Browse files
committed
Use drop chance correctly
Given that `randf` output is in the range [0, 1] inclusive, and we want `chance = 0` to mean never, and `chance = 1` to mean always, we need to worry about the edge cases. We need the `>=` because when `randf() == 0` and `chance == 0` just using `>` would give us the wrong result. We need to compare against 1 because when `randf() == 1` and `chance == 1` we would get the wrong reasult due to the `>=`. This is the from I found easier to read.
1 parent 2829f56 commit c87a824

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

godot/src/combat/Rewards.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func _add_reward(battler: Battler):
2424
# Appends dictionaries with the form { 'item': Item.tres, 'amount': amount } of dropped items to the drops array.
2525
experience_earned += battler.drops.experience
2626
for drop in battler.drops.get_drops():
27-
if drop.chance - randf() > drop.chance:
27+
if drop.chance < 1 and randf() >= drop.chance:
2828
continue
2929
var amount: int = (
3030
1

0 commit comments

Comments
 (0)