Last active
December 20, 2018 19:38
-
-
Save MitchBarnett/a7aae69930a107842af494df13b97281 to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name SMG2015 Saliens bot | |
// @version 1.1 | |
// @author Mitch Barnett (Ice) | |
// @match https://steamcommunity.com/saliengame | |
// @match https://steamcommunity.com/saliengame/ | |
// @match https://steamcommunity.com/saliengame/play | |
// @match https://steamcommunity.com/saliengame/play/ | |
// @downloadURL https://gist.githubusercontent.com/MitchBarnett/a7aae69930a107842af494df13b97281/raw/ | |
// @updateURL https://gist.githubusercontent.com/MitchBarnett/a7aae69930a107842af494df13b97281/raw/ | |
// @grant none | |
// ==/UserScript== | |
(function(context) { | |
"use strict"; | |
// when the error is fixed we should remove the following | |
CEnemyManager.prototype.BuildEnemy = function(){}; | |
CSalien.prototype.UpdateCustomizations = function() | |
{ | |
this.SetBodyType(BODY_TYPES[gSalienData.body_type]); | |
this.LoadAttachments(); | |
} | |
const app = gApp; | |
const GAME = gGame; | |
const SERVER = gServer; | |
const PLAYER = gPlayerInfo; | |
const Option = function Option(name, def) { | |
if (window.localStorage[name] === undefined) { | |
context.localStorage[name] = def; | |
} | |
return context.localStorage[name]; | |
} | |
const TryContinue = function TryContinue() { | |
let continued = false; | |
if (GAME.m_State.m_VictoryScreen) { | |
GAME.m_State.m_VictoryScreen.children.forEach(function(child) { | |
if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this | |
continued = true; | |
child.click(); | |
} | |
}) | |
} | |
if (GAME.m_State.m_LevelUpScreen) { | |
continued = false; | |
GAME.m_State.m_LevelUpScreen.children.forEach(function(child) { | |
if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this | |
continued = true; | |
child.click(); | |
} | |
}) | |
} | |
if(GAME.m_State instanceof CBootState && !isJoining) { // First screen | |
let newState = false; | |
if(PLAYER != null && PLAYER.active_planet !== undefined) { | |
newState = new CBattleSelectionState( PLAYER.active_planet ); | |
} | |
else { | |
newState = new CPlanetSelectionState(); | |
} | |
if(newState !== false) { | |
isJoining = true; | |
setTimeout(function tick() { | |
GAME.ChangeState( newState ); | |
isJoining = false; | |
}, 500); | |
continued = true; | |
} | |
} | |
if(GAME.m_State) { // Planet Selection | |
let planetId = GetWorstPlanet(); | |
if(planetId > 0) { | |
gGame.ChangeState( new CBattleSelectionState( planetId ) ); | |
continued = true; | |
} | |
} | |
return continued; | |
} | |
const GetBestZone = function GetBestZone() { | |
let bestZoneIdx = -1; | |
let maxProgress = 0; | |
let maxDifficulty = 0; | |
for (let idx = GAME.m_State.m_Grid.m_Tiles.length-1; idx >= 0; idx--) { | |
let zone = GAME.m_State.m_Grid.m_Tiles[idx].Info; | |
if(!zone.captured) { | |
if(zone.boss) { | |
return idx; | |
} | |
if(zone.difficulty > maxDifficulty) { | |
maxDifficulty = zone.difficulty; | |
bestZoneIdx = idx; | |
} | |
} | |
} | |
if(bestZoneIdx > -1) { | |
console.log(`zone ${bestZoneIdx} progress: ${GAME.m_State.m_Grid.m_Tiles[bestZoneIdx].Info.progress}`); | |
console.log(`zone ${bestZoneIdx} difficulty: ${GAME.m_State.m_Grid.m_Tiles[bestZoneIdx].Info.difficulty}`); | |
} | |
return bestZoneIdx; | |
} | |
const GetWorstPlanet = function GetWorstPlanet() { | |
let worstPlanet; | |
let leastProgress = 1.0; | |
if (!GAME.m_State.m_mapPlanets) | |
return; | |
for (let planetKV of GAME.m_State.m_mapPlanets) { | |
let planet = planetKV[1]; | |
if(planet.state.active && !planet.state.captured && planet.state.capture_progress < leastProgress) { | |
leastProgress = planet.state.capture_progress; | |
worstPlanet = planet; | |
} | |
} | |
if(worstPlanet) { | |
console.log(`selecting planet ${worstPlanet.state.name} with progress: ${worstPlanet.state.capture_progress}`); | |
return worstPlanet.id; | |
} | |
} | |
const InGame = function InGame() { | |
return GAME.m_State.m_bRunning; | |
} | |
const InZoneSelect = function InZoneSelect() { | |
return GAME.m_State instanceof CBattleSelectionState; | |
} | |
let isJoining = false; | |
if (context.BOT_FUNCTION) { | |
app.ticker.remove(context.BOT_FUNCTION); | |
context.BOT_FUNCTION = undefined; | |
} | |
context.BOT_FUNCTION = function ticker(delta) { | |
delta /= 100; | |
let buttonsOnErrorMessage = document.getElementsByClassName("btn_grey_white_innerfade btn_medium"); | |
if(buttonsOnErrorMessage[0] != null) { | |
buttonsOnErrorMessage[0].click(); | |
return; | |
} | |
if(GAME.m_IsStateLoading || !context.gPlayerInfo) { | |
return; | |
} | |
if (InZoneSelect() && !isJoining) { | |
let bestZoneIdx = GetBestZone(); | |
if(bestZoneIdx) { | |
isJoining = true; | |
console.log(GAME.m_State.m_SalienInfoBox.m_LevelText.text, GAME.m_State.m_SalienInfoBox.m_XPValueText.text); | |
console.log("join to zone", bestZoneIdx); | |
SERVER.JoinZone( | |
bestZoneIdx, | |
function (results) { | |
GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, bestZoneIdx)); | |
}, | |
GameLoadError | |
); | |
return; | |
} | |
} | |
if (!InGame()) { | |
if (TryContinue()) { | |
console.log("continued!"); | |
} | |
return; | |
} | |
isJoining = false; | |
} | |
app.ticker.add(context.BOT_FUNCTION); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment