added weighted random item drops based on player needs

This commit is contained in:
derek
2025-01-17 14:43:51 -06:00
parent cafcf57ef1
commit 5eb065830a
9 changed files with 83 additions and 31 deletions

View File

@@ -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]