Last active
June 28, 2018 04:00
-
-
Save danikaze/84eafecbb02fa01a2553913fdc8023b0 to your computer and use it in GitHub Desktop.
Steam summerSaliens auto player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* https://steamcommunity.com/saliengame/play/ | |
* 1. Choose the planet you have interest in. | |
* 2. Run this code in the browser console to have methods available in `window.salienGame` | |
* 3. Then just run `salienGame.start()` to farm or `salienGame.stop()` ... to stop ;) | |
* 4. You can also run `salienGame.stopAfterFight = true;` to schedule a stop after the fight | |
*/ | |
(function() { | |
const AUTOFIRE_DELAY = { 0: 250, 1: 500, 2: 400, 3: 250 }; | |
const MONSTER_ATTACK_DELAY = 1000; | |
const EXPLOSION_ATTACK_DELAY = 6500; | |
const DELAY_AFTER_VICTORY = 1500; | |
const DELAY_AFTER_CONTINUE = 2500; | |
const DELAY_AFTER_GRID = 1000; | |
const RETURN_TO_GRID_RETRY_DELAY = 500; | |
const DELAY_LOADING = 2000; | |
const DELAY_BATTLE_START = 200; | |
const STOP_FIGHT_BEFORE_MS = 500; | |
const DELAY_BEFORE_BACK_TO_GRID = 500; | |
const GRID_ROWS = 8; | |
const GRID_COLUMNS = 12; | |
let timeoutHandler; | |
let intervalHandler; | |
let planetDifficulty; | |
function log(msg) { | |
if (salienGame.verbose) { | |
console.log(`[saliengame] ${msg}`); | |
} | |
} | |
function start() { | |
if (!gGame || !gGame.m_State) { | |
stop('Game not detected'); | |
return; | |
} | |
salienGame.running = true; | |
const state = gGame.m_State; | |
if (gGame.m_IsStateLoading) { | |
timeoutHandler = setTimeout(start, DELAY_LOADING); | |
} else if (state instanceof CBootState) { | |
gGame.m_State.button.click(); | |
timeoutHandler = setTimeout(start, DELAY_LOADING); | |
} else if (state instanceof CBattleSelectionState) { | |
selectTile(); | |
} else if (state instanceof CBattleState) { | |
if (state.m_VictoryScreen) { | |
returnToGrid(); | |
} else { | |
timeoutHandler = setTimeout(fight, DELAY_AFTER_GRID); | |
} | |
} else { | |
stop('Unknown state'); | |
} | |
} | |
function stop(msg) { | |
log(msg || 'stop'); | |
clearInterval(intervalHandler); | |
clearTimeout(timeoutHandler); | |
salienGame.running = false; | |
salienGame.stopAfterFight = false; | |
} | |
function fight() { | |
clearInterval(timeoutHandler); | |
if (!gGame.m_State.m_rtBattleStart) { | |
timeoutHandler = setTimeout(fight, DELAY_BATTLE_START); | |
return; | |
} | |
function fireTurret() { | |
gGame.m_State.m_EnemyManager.m_EnemyContainer.children.forEach(enemy => enemy.pointertap && enemy.pointertap()); | |
} | |
function specialAttack(type, method) { | |
function chooseEnemy() { | |
const enemies = gGame.m_State.m_EnemyManager.m_EnemyContainer.children; | |
const i = (Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)) % enemies.length; | |
return enemies[i]; | |
} | |
if (!gGame.m_State.m_AttackManager) { | |
return; | |
} | |
const attack = attackManager.m_mapCooldowns.get(type); | |
if (attack && new Date().getTime() + attack.m_typeData.cooldown * 1000 > attack.m_rtAttackLastUsed) { | |
const enemy = chooseEnemy(); | |
if (enemy) { | |
gApp.renderer.plugins.interaction.mouse.global.x = type ==='boulder' ? gSalien.x + 250 : enemy._bounds.minX - 20; | |
gApp.renderer.plugins.interaction.mouse.global.y = type === 'blackhole' ? gSalien.y : enemy._bounds.maxY - 20; | |
gGame.m_State.m_AttackManager[method](); | |
} | |
} | |
} | |
function getMonsterAttackType() { | |
const types = 'SlimeAttack,BeastAttack,PsychicAttack'.split(','); | |
for(let i = 0; i < types.length; i++) { | |
if(attackManager.m_mapCooldowns.get(types[i].toLowerCase())) { | |
return [types[i].toLowerCase(), types[i]]; | |
} | |
} | |
} | |
function updateFight() { | |
if (new Date().getTime() >= (gGame.m_State.m_rtBattleEnd || 0) - STOP_FIGHT_BEFORE_MS) { | |
stop('Autofire: Battle ended'); | |
timeoutHandler = setTimeout(returnToGrid, DELAY_AFTER_VICTORY); | |
return; | |
} | |
fireTurret() | |
// special attacks | |
monsterAttackData = monsterAttackData || getMonsterAttackType(); | |
specialAttack(monsterAttackData[0], monsterAttackData[1]); | |
specialAttack('explosion', 'ExplosionAttack'); | |
specialAttack('flashfreeze', 'FlashFreezeAttack'); | |
specialAttack('blackhole', 'BlackholeAttack'); | |
specialAttack('boulder', 'BoulderAttack'); | |
} | |
let monsterAttackData; | |
const attackManager = gGame.m_State.m_AttackManager; | |
const playerLevel = gPlayerInfo && gPlayerInfo.level || 0; | |
const remaining = gGame.m_State.m_rtBattleEnd - new Date().getTime() - STOP_FIGHT_BEFORE_MS; | |
intervalHandler = setInterval(updateFight, AUTOFIRE_DELAY[planetDifficulty || 0]); | |
log(`Starting fight. Stops in ${remaining / 1000} sec.`); | |
} | |
function returnToGrid() { | |
function click() { | |
const popup = gGame.m_State.m_VictoryScreen || gGame.m_State.m_LevelUpScreen; | |
popup.children.forEach(c => { | |
if (c.pointertap) { | |
if (!c.result) { | |
timeoutHandler = setTimeout(click, DELAY_BEFORE_BACK_TO_GRID); | |
} else { | |
log('Returning to the grid'); | |
c.pointertap(); | |
timeoutHandler = setTimeout(start, DELAY_AFTER_CONTINUE); | |
} | |
} | |
}); | |
} | |
if (salienGame.stopAfterFight) { | |
stop('Scheduled stop'); | |
return; | |
} | |
if (gGame.m_State && (gGame.m_State.m_VictoryScreen || gGame.m_State.m_LevelUpScreen)) { | |
timeoutHandler = setTimeout(click, DELAY_BEFORE_BACK_TO_GRID); | |
return; | |
} | |
timeoutHandler = setTimeout(returnToGrid, RETURN_TO_GRID_RETRY_DELAY); | |
} | |
function selectTile() { | |
const playerLevel = gPlayerInfo && gPlayerInfo.level || 0; | |
const difficultyOrder = playerLevel > 6 ? [3, 2, 1] : (playerLevel > 4 ? [2, 1, 3] : [1, 2, 3]); | |
const tiles = gGame.m_State.m_Grid.m_Tiles; | |
for(let d = 0; d < difficultyOrder.length; d++) { | |
planetDifficulty = difficultyOrder[d]; | |
for(let i = 0; i < tiles.length; i++) { | |
if (!tiles[i].Info.captured && tiles[i].Info.difficulty === planetDifficulty) { | |
const x = i % GRID_COLUMNS; | |
const y = Math.floor(i / GRID_COLUMNS); | |
log(`Entering tile (${x}, ${y})`); | |
gGame.m_State.m_Grid.click(x, y); | |
timeoutHandler = setTimeout(start, DELAY_AFTER_GRID); | |
return; | |
} | |
} | |
} | |
stop('No available tiles in this planet. Choose a different one.'); | |
} | |
let wasRunning = false; | |
if (window.salienGame) { | |
wasRunning = salienGame.running; | |
salienGame.stop(wasRunning ? 'Restarting' : ''); | |
} | |
window.salienGame = { | |
start, | |
stop, | |
stopAfterFight: false, | |
verbose: true, | |
running: false, | |
}; | |
log('salienGame functions enabled! Execute salienGame.start() to start farming'); | |
if (wasRunning) { | |
salienGame.start(); | |
} | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment