@@ -18,25 +18,26 @@ const queryCurrentGameMode = async (credentials) => {
1818}
1919
2020// 获取最近的比赛记录
21- const getRencentMatchHistoty = async ( credentials , session , summonerId ) => {
21+ const getRencentMatchHistoty = async ( credentials , session , summonerId ) => {
2222 const matchList = ( await createHttp2Request ( {
2323 method : "GET" ,
24- url : `/lol-match-history/v3/matchlist/account/${ summonerId } ` ,
24+ url : `/lol-match-history/v3/matchlist/account/${ summonerId } ?begIndex=0&endIndex=10 ` ,
2525 } , session , credentials ) ) . json ( ) [ 'games' ] [ 'games' ] . reverse ( )
26- return matchList . slice ( 0 , 10 )
26+ return matchList
2727}
2828
29- // 查询比赛记录 (最近5场排位 )
30- const queryMatchHistory = async ( credentials , session , summonerId ) => {
29+ // 查询比赛记录 (最近10场排位 )
30+ const queryMatchHistory = async ( credentials , session , summonerId ) => {
3131 const currentGameMode = await queryCurrentGameMode ( credentials )
3232 console . log ( '当前游戏模式:' , currentGameMode )
33- if ( currentGameMode === null ) {
34- return await getRencentMatchHistoty ( credentials , session , summonerId )
33+ if ( currentGameMode === null ) {
34+ return await getRencentMatchHistoty ( credentials , session , summonerId )
3535 }
3636
3737 let classicMode = [ ]
3838 let matchCount = 0
3939 for ( let i = 0 ; i < 100 ; i += 20 ) {
40+ console . log ( 123 )
4041 const matchList = ( await createHttp2Request ( {
4142 method : "GET" ,
4243 url : `/lol-match-history/v3/matchlist/account/${ summonerId } ?begIndex=${ i } &endIndex=${ i + 20 } ` ,
@@ -46,29 +47,33 @@ const queryMatchHistory = async (credentials,session,summonerId) => {
4647 if ( matchListElement . queueId == currentGameMode && matchCount < 10 ) {
4748 matchCount += 1
4849 classicMode . push ( matchListElement )
50+ } else if ( matchCount === 10 ) {
51+ return classicMode
4952 }
5053 }
51- if ( matchCount === 10 ) {
52- break
53- }
5454 }
5555 return classicMode
5656}
5757
5858// 获取召唤师游戏评分分数
59- export const getGameScore = async ( credentials , summonerId , session ) => {
60- let classicModeGames = await queryMatchHistory ( credentials , session , summonerId )
59+ export const getGameScore = async ( credentials , summonerId , session ) => {
60+ let classicModeGames = await queryMatchHistory ( credentials , session , summonerId )
6161 const simpleMatchHistory = getSimpleMatchHistory ( classicModeGames )
6262 let gameScore = 0
63- let gameCount = classicModeGames . length
63+ let gameCount = classicModeGames . slice ( 0 , 5 ) . length
6464 let kdaHistory = ''
65- for ( const modeGame of classicModeGames ) {
65+ for ( const modeGame of classicModeGames . slice ( 0 , 5 ) ) {
6666 gameScore += analyseSingleMatch ( modeGame . participants [ 0 ] . stats )
6767 let tempKad = `${ modeGame . participants [ 0 ] . stats . kills } /${ modeGame . participants [ 0 ] . stats . deaths } /${ modeGame . participants [ 0 ] . stats . assists } `
6868 kdaHistory += tempKad
6969 }
7070 gameScore = parseInt ( gameScore / gameCount )
71- return { score : gameScore , horse : jundgeHorse ( gameScore ) , kdaHistory : kdaHistory , simpleMatchHistory :simpleMatchHistory }
71+ return {
72+ score : gameScore ,
73+ horse : jundgeHorse ( gameScore ) ,
74+ kdaHistory : kdaHistory ,
75+ simpleMatchHistory : simpleMatchHistory
76+ }
7277}
7378
7479// 获取简单的历史战绩信息
@@ -78,39 +83,42 @@ const getSimpleMatchHistory = (matchList) => {
7883 let simpleMatch = [ ]
7984 for ( const match of matchList ) {
8085 simpleMatch . push ( {
81- champImg :`https://game.gtimg.cn/images/lol/act/img/champion/${ champDict [ String ( match . participants [ 0 ] . championId ) ] . alias } .png` ,
82- position :match . participants [ 0 ] . timeline . lane ,
83- kill :match . participants [ 0 ] . stats . kills ,
84- deaths :match . participants [ 0 ] . stats . deaths ,
85- assists :match . participants [ 0 ] . stats . assists ,
86- isWin :match . participants [ 0 ] . stats . win ,
87- gameId :match . gameId
86+ champImg : `https://game.gtimg.cn/images/lol/act/img/champion/${ champDict [ String ( match . participants [ 0 ] . championId ) ] . alias } .png` ,
87+ position : match . participants [ 0 ] . timeline . lane ,
88+ kill : match . participants [ 0 ] . stats . kills ,
89+ deaths : match . participants [ 0 ] . stats . deaths ,
90+ assists : match . participants [ 0 ] . stats . assists ,
91+ isWin : match . participants [ 0 ] . stats . win ,
92+ gameId : match . gameId
8893 } )
8994 position . push ( match . participants [ 0 ] . timeline . lane )
9095 winOrLoss . push ( match . participants [ 0 ] . stats . win )
9196 }
9297 const winInfo = inferMatchWinRat ( winOrLoss )
9398 const regularPostion = inferRegularPosition ( position )
94- return { winInfo, regularPostion, simpleMatch}
99+ return { winInfo, regularPostion, simpleMatch}
95100}
96101
97102// 判断最近战绩情况
98103const inferMatchWinRat = ( arr ) => {
99104 const firstMatch = arr [ 0 ]
100105 let count = 0
101106 for ( const arrElement of arr ) {
102- if ( arrElement === firstMatch ) {
103- count += 1
104- } else {
107+ if ( arrElement === firstMatch ) {
108+ count += 1
109+ } else {
105110 break
106111 }
107112 }
108- if ( count === 1 ) {
109- return firstMatch === true ? { 'info' :'一胜一负' , isWin :firstMatch } : { 'info' :'一负一胜' , isWin :firstMatch }
110- } else if ( count === 0 ) {
111- return { 'info' :'暂无数据' , isWin :firstMatch }
113+ if ( count === 1 ) {
114+ return firstMatch === true ? { 'info' : '一胜一负' , isWin : firstMatch } : { 'info' : '一负一胜' , isWin : firstMatch }
115+ } else if ( count === 0 ) {
116+ return { 'info' : '暂无数据' , isWin : firstMatch }
112117 } else {
113- return firstMatch === true ? { 'info' :`${ count } 连胜中` , isWin :firstMatch } :{ 'info' :`${ count } 连败中` , isWin :firstMatch }
118+ return firstMatch === true ? { 'info' : `${ count } 连胜中` , isWin : firstMatch } : {
119+ 'info' : `${ count } 连败中` ,
120+ isWin : firstMatch
121+ }
114122 }
115123}
116124
@@ -121,10 +129,10 @@ const inferRegularPosition = (arr) => {
121129 let res = { }
122130 let maxNum = 0
123131 let maxValue = null
124- for ( let i = 0 ; i < arr . length ; i ++ ) {
132+ for ( let i = 0 ; i < arr . length ; i ++ ) {
125133 let val = arr [ i ]
126134 res [ val ] === undefined ? res [ val ] = 1 : res [ val ] ++
127- if ( res [ val ] > maxNum ) {
135+ if ( res [ val ] > maxNum ) {
128136 maxNum = res [ val ]
129137 maxValue = val
130138 }
@@ -172,11 +180,16 @@ const jundgeHorse = (score) => {
172180// 判断玩家位置
173181const querySummonerPosition = ( lane ) => {
174182 switch ( lane ) {
175- case 'MIDDLE' : return '中单' ;
176- case 'JUNGLE' : return '打野' ;
177- case 'BOTTOM' : return '下路' ;
178- case 'TOP' : return '上单' ;
179- case 'NONE' : return '未知'
183+ case 'MIDDLE' :
184+ return '中单' ;
185+ case 'JUNGLE' :
186+ return '打野' ;
187+ case 'BOTTOM' :
188+ return '下路' ;
189+ case 'TOP' :
190+ return '上单' ;
191+ case 'NONE' :
192+ return '未知'
180193 }
181194 return '未知'
182195}
0 commit comments