-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.gd
43 lines (35 loc) · 1.65 KB
/
utils.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extends Node
func _ready():
randomize()
func get_prob_s(all_range, range_percent): # secure (Utils.get_prob_s([-30,1000], [[-30,400,50], [401, 405, 400], [406,900,30],[901,1000,5]]))
var sum_percent =0
for percent in range_percent:
sum_percent += percent[2]
var find_percent = rand_range(0, sum_percent)
for find_range in range_percent:
find_percent -= find_range[2]
if find_percent <=0:
assert( all_range[0] <= find_range[0] and find_range[0] <=all_range[1] and all_range[0] <= find_range[1] and find_range[1] <=all_range[1] )
return rand_range(find_range[0], find_range[1])
func get_prob(range_percent): # unsecure (Utils.get_prob([[-30,400,50], [401, 405, 400], [406,900,30],[901,1000,5]]))
var sum_percent =0
for percent in range_percent:
sum_percent += percent[2]
var find_percent = rand_range(0, sum_percent)
for find_range in range_percent:
find_percent -= find_range[2]
if find_percent <=0:
return rand_range(find_range[0], find_range[1])
func get_prob_ps(all_range, range_percent): # percent secure (Utils.get_prob_ps([-30,1000], [[10,30,50], [31, 60, 400], [61,85,30],[86,100,5]]))
var sum_percent =0
var one_percent: float
for percent in range_percent:
sum_percent += percent[2]
var find_percent = rand_range(0, sum_percent)
for find_range in range_percent:
find_percent -= find_range[2]
if find_percent <=0:
assert( 0 <= find_range[0] and find_range[0] <=100 and 0 <= find_range[1] and find_range[1] <=100 )
one_percent = (float((all_range[1]) - all_range[0])/100)
var new_range = [all_range[0]+(find_range[0]*one_percent), all_range[0]+(find_range[1]*one_percent)]
return rand_range(new_range[0], new_range[1])