Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. (async function($, forGroup, canPlanetChange) {
  2. const gameUrlPrefix = 'https://community.steam-api.com/ITerritoryControlMinigameService'
  3. const leavePrefix = 'https://community.steam-api.com/IMiniGameService'
  4. const groupId = 28722429
  5.  
  6. let token
  7. let gameTimer
  8. let errorTime = 0
  9. let difficulty
  10. let score
  11. let bestPlanet
  12.  
  13. try {
  14. token = (await $.get('https://steamcommunity.com/saliengame/gettoken')).token
  15. } catch (e) {
  16. console.error('Get token failed, exit...')
  17. return
  18. }
  19.  
  20. async function joinGame() {
  21. clearTimeout(gameTimer)
  22. log(`==============================================================`)
  23. try {
  24. log(`获取信息中...`)
  25. var {response} = await $.post(`${gameUrlPrefix}/GetPlayerInfo/v0001/`,`access_token=${token}`)
  26. var {active_planet, level, score: _score, next_level_score, active_zone_game, clan_info} = response
  27. if (active_zone_game) {
  28. log('已经在游戏中,尝试退出当前游戏...')
  29. await $.post(`${leavePrefix}/LeaveGame/v0001/`,`access_token=${token}&gameid=${active_zone_game}`)
  30. }
  31.  
  32. if (canPlanetChange) {
  33. var {response} = await $.get(`${gameUrlPrefix}/GetPlanets/v0001/?active_only=1&language=schinese`)
  34. bestPlanet = response.planets.sort((a,b)=>a.state.capture_progress-b.state.capture_progress)[0]
  35. log(`当前攻占率最低星球:${bestPlanet.state.name}(id:${bestPlanet.id})`)
  36. if (bestPlanet.id==active_planet) {
  37. log(`已在攻占率最低星球,不需要更换星球`)
  38. } else {
  39. log('不在攻占率最低星球,尝试更换星球...')
  40. await $.post(`${leavePrefix}/LeaveGame/v0001/`,`access_token=${token}&gameid=${active_planet}`)
  41. try {
  42. await $.post(`${gameUrlPrefix}/JoinPlanet/v0001/`,`access_token=${token}&id=${bestPlanet.id}`)
  43. var {response} = await $.post(`${gameUrlPrefix}/GetPlayerInfo/v0001/`,`access_token=${token}`)
  44. var {active_planet, level, score: _score, next_level_score, active_zone_game, clan_info} = response
  45. } catch (e) {
  46. console.error(e)
  47. log(`进入星球失败,5秒后重试...`)
  48. gameTimer = setTimeout(joinGame, 5000)
  49. }
  50. }
  51. }
  52.  
  53. if (forGroup && (!clan_info || clan_info.accountid !== groupId)) {
  54. await $.post(`${gameUrlPrefix}/RepresentClan/v0001/`,`clanid=103582791429777370&access_token=${token}`)
  55. }
  56. // var {response} = await $.get(`${gameUrlPrefix}/GetPlanet/v0001/?id=${parseInt(active_planet)+1}&language=schinese`)
  57. // const state = response.planets[0].state
  58. // log(state.active==false?`下一星球“${state.name}” 【尚未】开放`:`下一星球“${state.name}” 【已经】开放`)
  59. var {response} = await $.get(`${gameUrlPrefix}/GetPlanet/v0001/?id=${active_planet}&language=schinese`)
  60. const planet = response.planets[0]
  61. log(`当前星球:${planet.state.name}(id:${planet.id}) 等级:${level} 经验:${_score}/${next_level_score}`+(forGroup?`队伍:${clan_info?clan_info.name:'None'}`:``))
  62. let zones = planet.zones.filter(({captured})=>!captured)
  63. let targetZone
  64. if (forGroup && clan_info && clan_info.accountid === groupId) {
  65. targetZone = findTarget(zones.filter(({difficulty})=>difficulty === 3).length>0?
  66. zones.filter(({difficulty})=>difficulty === 3):
  67. (zones.filter(({difficulty})=>difficulty === 2).length>0?
  68. zones.filter(({difficulty})=>difficulty === 2):zones))
  69. } else {
  70. zones = zones.reverse()
  71. targetZone = zones.find(({difficulty})=>difficulty === 3) || zones.find(({difficulty})=>difficulty === 2) || zones[0]
  72. }
  73.  
  74. const {zone_position, difficulty, capture_progress: progress} = targetZone
  75. score = difficulty === 1 ? 595 : difficulty === 2 ? 1190 : 2380
  76. log(`尝试进入战斗区域...`)
  77. var {response} = await $.post(`${gameUrlPrefix}/JoinZone/v0001/`,`zone_position=${zone_position}&access_token=${token}`)
  78. if (response['zone_info']) {
  79. log(`进入战斗区域${zone_position}(${zone_position % 12 + 1 | 0},${zone_position / 12 + 1 | 0})成功`)
  80. log(`区域攻占进度:${(progress * 100).toFixed(2)}%,将在110秒后获得经验:${score},约${Math.round((next_level_score-_score)/score*110/60)}分钟后升级`)
  81. gameTimer = setTimeout(sendScore, 110000)
  82. } else {
  83. throw 'Service reject.'
  84. }
  85. } catch (e) {
  86. console.error(e)
  87. log(`进入区域失败,5秒后重试...`)
  88. gameTimer = setTimeout(joinGame, 5000)
  89. }
  90. }
  91.  
  92. async function sendScore() {
  93. clearTimeout(gameTimer)
  94. log(`获得经验中...`)
  95. try {
  96. var {response} = await $.post(`${gameUrlPrefix}/ReportScore/v0001/`,`access_token=${token}&score=${score}&language=schinese`)
  97. if (response['new_score']) {
  98. errorTime = 0
  99. log(`获得经验成功,当前经验:${response['new_score']}`)
  100. gameTimer = setTimeout(joinGame, 100)
  101. } else {
  102. throw 'Service reject.'
  103. }
  104. } catch (e) {
  105. if (errorTime++ < 3) {
  106. console.error(e)
  107. log(`获得经验失败${errorTime}次,1.5秒后重试...`)
  108. gameTimer = setTimeout(sendScore, 1500)
  109. } else {
  110. log(`获得经验失败${errorTime-1}次,重置中...`)
  111. gameTimer = setTimeout(joinGame, 100)
  112. errorTime = 0
  113. }
  114. }
  115. }
  116.  
  117. function findTarget(_zones) {
  118. let zones = _zones.sort(({capture_progress: a},{capture_progress: b})=>b - a)
  119. for (let i = 0; i < 3; i++) {
  120. target = zones.filter(({capture_progress, top_clans})=>(capture_progress < 1 / (i + 1)) && top_clans[i] && top_clans[i].accountid === groupId)[0]
  121. if (target) {
  122. return target
  123. }
  124. }
  125. return zones.pop()
  126. }
  127.  
  128. function log() {
  129. const date = new Date()
  130. const time = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]\t`
  131. console.log(time, ...arguments)
  132. }
  133. joinGame()
  134. }
  135. )(jQuery, 0, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement