Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async function($, forGroup, canPlanetChange) {
- const gameUrlPrefix = 'https://community.steam-api.com/ITerritoryControlMinigameService'
- const leavePrefix = 'https://community.steam-api.com/IMiniGameService'
- const groupId = 28722429
- let token
- let gameTimer
- let errorTime = 0
- let difficulty
- let score
- let bestPlanet
- try {
- token = (await $.get('https://steamcommunity.com/saliengame/gettoken')).token
- } catch (e) {
- console.error('Get token failed, exit...')
- return
- }
- async function joinGame() {
- clearTimeout(gameTimer)
- log(`==============================================================`)
- try {
- log(`获取信息中...`)
- var {response} = await $.post(`${gameUrlPrefix}/GetPlayerInfo/v0001/`,`access_token=${token}`)
- var {active_planet, level, score: _score, next_level_score, active_zone_game, clan_info} = response
- if (active_zone_game) {
- log('已经在游戏中,尝试退出当前游戏...')
- await $.post(`${leavePrefix}/LeaveGame/v0001/`,`access_token=${token}&gameid=${active_zone_game}`)
- }
- if (canPlanetChange) {
- var {response} = await $.get(`${gameUrlPrefix}/GetPlanets/v0001/?active_only=1&language=schinese`)
- bestPlanet = response.planets.sort((a,b)=>a.state.capture_progress-b.state.capture_progress)[0]
- log(`当前攻占率最低星球:${bestPlanet.state.name}(id:${bestPlanet.id})`)
- if (bestPlanet.id==active_planet) {
- log(`已在攻占率最低星球,不需要更换星球`)
- } else {
- log('不在攻占率最低星球,尝试更换星球...')
- await $.post(`${leavePrefix}/LeaveGame/v0001/`,`access_token=${token}&gameid=${active_planet}`)
- try {
- await $.post(`${gameUrlPrefix}/JoinPlanet/v0001/`,`access_token=${token}&id=${bestPlanet.id}`)
- var {response} = await $.post(`${gameUrlPrefix}/GetPlayerInfo/v0001/`,`access_token=${token}`)
- var {active_planet, level, score: _score, next_level_score, active_zone_game, clan_info} = response
- } catch (e) {
- console.error(e)
- log(`进入星球失败,5秒后重试...`)
- gameTimer = setTimeout(joinGame, 5000)
- }
- }
- }
- if (forGroup && (!clan_info || clan_info.accountid !== groupId)) {
- await $.post(`${gameUrlPrefix}/RepresentClan/v0001/`,`clanid=103582791429777370&access_token=${token}`)
- }
- // var {response} = await $.get(`${gameUrlPrefix}/GetPlanet/v0001/?id=${parseInt(active_planet)+1}&language=schinese`)
- // const state = response.planets[0].state
- // log(state.active==false?`下一星球“${state.name}” 【尚未】开放`:`下一星球“${state.name}” 【已经】开放`)
- var {response} = await $.get(`${gameUrlPrefix}/GetPlanet/v0001/?id=${active_planet}&language=schinese`)
- const planet = response.planets[0]
- log(`当前星球:${planet.state.name}(id:${planet.id}) 等级:${level} 经验:${_score}/${next_level_score}`+(forGroup?`队伍:${clan_info?clan_info.name:'None'}`:``))
- let zones = planet.zones.filter(({captured})=>!captured)
- let targetZone
- if (forGroup && clan_info && clan_info.accountid === groupId) {
- targetZone = findTarget(zones.filter(({difficulty})=>difficulty === 3).length>0?
- zones.filter(({difficulty})=>difficulty === 3):
- (zones.filter(({difficulty})=>difficulty === 2).length>0?
- zones.filter(({difficulty})=>difficulty === 2):zones))
- } else {
- zones = zones.reverse()
- targetZone = zones.find(({difficulty})=>difficulty === 3) || zones.find(({difficulty})=>difficulty === 2) || zones[0]
- }
- const {zone_position, difficulty, capture_progress: progress} = targetZone
- score = difficulty === 1 ? 595 : difficulty === 2 ? 1190 : 2380
- log(`尝试进入战斗区域...`)
- var {response} = await $.post(`${gameUrlPrefix}/JoinZone/v0001/`,`zone_position=${zone_position}&access_token=${token}`)
- if (response['zone_info']) {
- log(`进入战斗区域${zone_position}(${zone_position % 12 + 1 | 0},${zone_position / 12 + 1 | 0})成功`)
- log(`区域攻占进度:${(progress * 100).toFixed(2)}%,将在110秒后获得经验:${score},约${Math.round((next_level_score-_score)/score*110/60)}分钟后升级`)
- gameTimer = setTimeout(sendScore, 110000)
- } else {
- throw 'Service reject.'
- }
- } catch (e) {
- console.error(e)
- log(`进入区域失败,5秒后重试...`)
- gameTimer = setTimeout(joinGame, 5000)
- }
- }
- async function sendScore() {
- clearTimeout(gameTimer)
- log(`获得经验中...`)
- try {
- var {response} = await $.post(`${gameUrlPrefix}/ReportScore/v0001/`,`access_token=${token}&score=${score}&language=schinese`)
- if (response['new_score']) {
- errorTime = 0
- log(`获得经验成功,当前经验:${response['new_score']}`)
- gameTimer = setTimeout(joinGame, 100)
- } else {
- throw 'Service reject.'
- }
- } catch (e) {
- if (errorTime++ < 3) {
- console.error(e)
- log(`获得经验失败${errorTime}次,1.5秒后重试...`)
- gameTimer = setTimeout(sendScore, 1500)
- } else {
- log(`获得经验失败${errorTime-1}次,重置中...`)
- gameTimer = setTimeout(joinGame, 100)
- errorTime = 0
- }
- }
- }
- function findTarget(_zones) {
- let zones = _zones.sort(({capture_progress: a},{capture_progress: b})=>b - a)
- for (let i = 0; i < 3; i++) {
- target = zones.filter(({capture_progress, top_clans})=>(capture_progress < 1 / (i + 1)) && top_clans[i] && top_clans[i].accountid === groupId)[0]
- if (target) {
- return target
- }
- }
- return zones.pop()
- }
- function log() {
- const date = new Date()
- const time = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]\t`
- console.log(time, ...arguments)
- }
- joinGame()
- }
- )(jQuery, 0, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement