forked from billfreeman44/ow_loot_box_calc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
186 lines (135 loc) · 4.14 KB
/
main.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
print "test"
#PLAN!
# USE random numbers to
#simulate loot box openings
#use percentages from reddit for each rarity
#use random numbers to decide rarity of each
#item found.
#assume item distribution is even
#(each legendary has same chance of appearing
#if loot box gives a legendary item)
#account for duplicates
#once enough money to buy remaining items, simulation stops.
import random
import numpy
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
#percent PER item, not per loot box. (x100)
p_common=5866
p_rare=3169
p_epic=722
p_leg=243
n_boxes_max=50000
n_trials_max=3000
n_heroes=21
###number of skins per hero
##n_leg=4
##n_epic=2
##n_rare=4
##n_common=1
##n_sprays=25 #common
##n_emotes=3 #rare
##n_voicelines=9
##n_victoryposes=3 #rare
##n_intros=3 #epic
##
#### wrong?
##total_leg=n_heroes*n_leg
##total_epic=n_heroes*n_epic*n_intros
##total_rare=n_heroes*n_rare*n_emotes*n_victoryposes
##total_common=n_heroes*n_sprays*n_voicelines
#duplicate gold
dup_common=5
dup_rare =15
dup_epic =50
dup_leg =200
#cost of buying items
common_cost=25
rare_cost=75
epic_cost=250
leg_cost=1000
## updated values?
total_leg=n_heroes*4
total_epic=n_heroes*8
total_rare=n_heroes*7
total_common=n_heroes*35
total_common=total_common + 27 #add in all hero spray
total_rare = total_rare + 118 #add hero icons
print total_leg
print total_epic
print total_rare
print total_common
total_cost = total_common*common_cost
total_cost = total_cost + total_rare*rare_cost
total_cost = total_cost + total_epic*epic_cost
total_cost = total_cost + total_leg*leg_cost
print 'total cost'
print total_cost
#player icons
n_p_icons=45 #rarity?
boxes_needed=[]
print "running"
for i in range(n_trials_max):
#if int(i/100) == 0:
# print i
leg_have=0.0
epic_have=0.0
rare_have=0.0
common_have=0.0
gold_have=0.0
box_number=0
got_all_items=0
while got_all_items == 0 and box_number < n_boxes_max:
box_number=box_number+1
rarity_num=random.randint(0,9999)
duplicate_chance=random.random()
if rarity_num < p_leg:
#print 'LEGENDARY'
#print leg_have/total_leg
if leg_have/total_leg < duplicate_chance:
leg_have=leg_have+1
else:
gold_have=gold_have+dup_leg
elif rarity_num < p_leg+p_epic:
#print 'EPIC'
#print epic_have/total_epic , duplicate_chance
if epic_have/total_epic < duplicate_chance:
epic_have=epic_have+1
else:
gold_have=gold_have+dup_epic
elif rarity_num < p_leg+p_epic+p_rare:
#print 'rare'
if rare_have/total_rare < duplicate_chance:
rare_have=rare_have+1
else:
gold_have=gold_have+dup_rare
#elif rarity_num < p_leg+p_epic+p_rare+p_common:
else:
#print 'common'
if common_have/total_common < duplicate_chance:
common_have=common_have+1
else:
gold_have=gold_have+dup_common
#check if we can buy the rest of the items.
gold_needed=(total_leg - leg_have) * leg_cost
gold_needed=gold_needed + (total_epic - epic_have) * epic_cost
gold_needed=gold_needed + (total_rare - rare_have) * rare_cost
gold_needed=gold_needed + (total_common - common_have) * common_cost
if gold_have >= gold_needed:
#print "WE HAVE ALL THE ITEMS"
#print 'in the '+str(box_number/4)+'rd box'
got_all_items=1
#print "final stats:"
#print "total gold: "+str(int(gold_have))
#print "total legendary: "+str(int(leg_have))
#print "total epic: "+str(int(epic_have))
#print "total rare: "+str(int(rare_have))
#print "total common: "+str(int(common_have))
boxes_needed.append(box_number/4.0)
n, bins, patches = plt.hist(boxes_needed, 50, normed=1, facecolor='green')
print "final statistics"
print
print "average: "+str(numpy.mean(boxes_needed))
print "median: "+str(numpy.median(boxes_needed))
#print "std dev: "+str(numpy.stdev(boxes_needed))
plt.show()