1
- < script >
2
- // 计算抽中新英雄的概率
3
- // 计算抽中新英雄的概率
4
- function calculateProbability ( obtainedHeroesSize ) {
5
- // 使用平方根函数调整概率增长曲线
6
- const factor = Math . sqrt ( obtainedHeroesSize ) / Math . sqrt ( 50 ) ;
7
- const probability = 0.01 + 0.49 * factor ;
8
- return probability > 0.5 ? 0.5 : probability ;
9
- }
10
-
11
- // 抽奖函数,抽中后返回抽中英雄的ID
12
- function drawHero ( allHeroes , obtainedHeroes ) {
13
- // 转换obtainedHeroes为Set对象以优化搜索效率
14
- const obtainedHeroesSet = new Set ( obtainedHeroes ) ;
15
-
16
- // 如果已经抽中所有英雄,返回null
17
- if ( obtainedHeroesSet . size >= allHeroes . length ) {
18
- return null ;
19
- }
20
-
21
- // 计算当前的抽奖概率
22
- const probability = calculateProbability ( obtainedHeroesSet . size ) ;
23
- const randomNumber = Math . random ( ) ; // 随机数在0到1之间
24
- let drawnHeroId ;
25
-
26
- if ( randomNumber <= probability ) {
27
- // 成功抽中新英雄的情况
28
- let newHeroPool = allHeroes . filter ( ( heroId ) => ! obtainedHeroesSet . has ( heroId ) ) ;
29
- let randomIndex = Math . floor ( Math . random ( ) * newHeroPool . length ) ;
30
- drawnHeroId = newHeroPool [ randomIndex ] ;
31
- } else {
32
- // 抽中已有英雄的情况
33
- let randomIndex = Math . floor ( Math . random ( ) * allHeroes . length ) ;
34
- drawnHeroId = allHeroes [ randomIndex ] ;
35
- // 如果恰好抽中新英雄,则返回
36
- if ( ! obtainedHeroesSet . has ( drawnHeroId ) ) {
37
- return drawnHeroId ;
38
- }
39
- }
40
-
41
- return drawnHeroId ;
42
- }
43
- // 示例
44
- const allHeroes = [
45
- 107 , 109 , 115 , 120 , 136 , 146 , 105 , 110 , 116 , 127 , 139 , 148 , 106 , 112 , 117 , 133 , 156 , 108 , 113 ,
46
- 118 , 129 , 134 , 150 , 166 , 111 , 114 , 119 , 130 , 135 , 144 , 152 , 142 , 128 , 124 , 168 , 167 , 121 , 141 ,
47
- 123 , 154 , 169 , 171 , 170 , 153 , 162 , 131 , 175 , 173 , 149 , 157 , 174 , 140 , 184 , 126 , 183 , 132 , 163 ,
48
- 177 , 178 , 186 , 180 , 190 , 192 , 191 , 187 , 182 , 189 , 193 , 196 , 195 , 194 , 198 , 179 , 501 , 199 , 176 ,
49
- 502 , 197 , 503 , 504 , 125 , 510 , 137 , 509 , 508 , 312 , 507 , 513 , 515 , 511 , 529 , 505 , 506 , 522 , 518 ,
50
- 523 , 525 , 524 , 531 , 527 , 533 , 536 , 528 , 537 , 155 , 538 , 540 , 542 , 534 , 548 , 521 , 544 , 545 , 564 ,
51
- 514 , 159 ,
52
- ] ;
53
- //额外道具
54
- const obtainedHeroes = localStorage . getItem ( "obtainedHeroes" )
55
- ? JSON . parse ( localStorage . getItem ( "obtainedHeroes" ) )
56
- : [ ] ;
57
-
58
- // 抽奖操作
59
- const newHeroId = drawHero ( allHeroes , obtainedHeroes ) ;
60
- if ( newHeroId !== null ) {
61
- if ( obtainedHeroes . includes ( newHeroId ) ) {
62
- console . warn ( "抽到相同的" ) ;
63
- } else {
64
- console . log ( "抽到了:" , newHeroId ) ;
65
- }
66
- obtainedHeroes . push ( newHeroId ) ; // 更新已抽中英雄列表
67
- localStorage . setItem ( "obtainedHeroes" , JSON . stringify ( obtainedHeroes ) ) ;
68
- } else {
69
- console . error ( "抽完了" ) ;
70
- }
71
-
72
- console . log ( JSON . parse ( JSON . stringify ( obtainedHeroes , null , 2 ) ) ) ;
73
- </ script >
1
+ < h1 > 独立开发者:</ h1 > < div class ='content '> < a target ='_blank ' href ='https://github.com/lengyibai '> < div class ='user '> < img src ='https://files.lyb.im/wzry-material/image/lyb.png ' class ='head-img ' alt ='' /> < div class ='name '> 冷弋白(lengyibai)</ div > </ div > </ a > </ div > < h1 > Github仓库:</ h1 > < div class ='content '> < p > < a target ='_blank ' href ='https://github.com/lengyibai/wzry ' class ='link iconfont wzry-mark-github ' > < span class ='link__name '> 王者图鉴</ span > </ a > </ p > </ div > < h1 > 注意:</ h1 > < div class ='content '> < p > 请勿将项目内的游戏素材用于商业用途</ p > < p > 本站用户数据存在本地不与服务器交互</ p > < p > 对于开发者而言此项目仅供交流与学习</ p > </ div > < h1 > 友情赞助:</ h1 > < div class ='content '> < a target ='_blank ' href ='https://lucent.blog '> < div class ='user '> < img src ='https://files.lyb.im/wzry-material/image/ddm.png ' class ='head-img ' alt ='' /> < div class ='name '> 呆呆木(服务器及域名)</ div > </ div > </ a > </ div >
0 commit comments