added weighted random item drops based on player needs
This commit is contained in:
@@ -13,3 +13,24 @@ func angle_velocity_aligned(source:Node, source_angle:Vector3, body:Node, max_an
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
#pass in a dictornary of weighted random choices, returns id of selection
|
||||
func weighted_random(choices):
|
||||
var sum_of_choices = 0.0
|
||||
|
||||
#Get sum of all choices
|
||||
for i in choices:
|
||||
sum_of_choices += choices[i]
|
||||
|
||||
var random_number = randf_range(0,sum_of_choices)
|
||||
print("----------------------------------------------------------------")
|
||||
print("CHOICES: ",choices)
|
||||
print("SUM OF CHOICES: ",sum_of_choices)
|
||||
print("RANDOM NUMBER: ",random_number)
|
||||
|
||||
for i in choices:
|
||||
if random_number < choices[i]:
|
||||
print("SELECTION: ", i)
|
||||
print("----------------------------------------------------------------")
|
||||
return i
|
||||
random_number -= choices[i]
|
||||
|
||||
Reference in New Issue
Block a user