Created
September 10, 2016 10:04
-
-
Save EvidentlyCube/bc5c26a2443509c07f8aa4c90145d30b to your computer and use it in GitHub Desktop.
A simple autoscript for Trimps game for personal use, is not very intelligent. Press "a" to toggle on/off. In order to run it open the game page, press open developer tools (F12 in Chrome and FF), select console, now refresh the page,, wait for it to load, paste the script and press enter. It runs by default, press a in game window to toggle it …
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
window.isAutomaticTrimpsRunning = true; | |
if (typeof game !== 'undefined'){ | |
window.game = game; | |
} | |
if (typeof window.game === 'undefined' || window.game == null){ | |
console.error("Save and refresh the page and run the script again"); | |
throw new Error(""); | |
} | |
function _createAutoTrimps(){ | |
var resetTooltip = false; | |
var game = window.game; | |
var isRunning = true; | |
var isSavingForGymystic = false; | |
var currentZone = 1; | |
addEvent(document, "keypress", function (e) { | |
e = e || window.event; | |
console.log("Pressed ", e.keyCode); | |
if (e.keyCode == 65 || e.keyCode == 97){ | |
if (isRunning){ | |
isRunning = false; | |
message("Autoplay disabled!", "Notices"); | |
} else { | |
isRunning = true; | |
message("Autoplay Enabled!", "Notices"); | |
} | |
} | |
}); | |
message("Autoplay enabled!", "Notices"); | |
return function(){ | |
if (!isRunning){ | |
return; | |
} | |
resetTooltip = false; | |
currentZone = game.global.world; | |
isSavingForGymystic = elementExists('#Gymystic'); | |
setMyJob(); | |
buyUpgrades(); | |
buyBuildings(); | |
buyEquipmentUpgrades(); | |
buyJobs(); | |
buyStorageSpace(); | |
if (resetTooltip){ | |
tooltip('hide'); | |
} | |
} | |
function setMyJob(){ | |
var buildingInQueue = game.global.buildingsQueue.length > 0; | |
var isBuildingRightNow = hasClass(getFirstElement('#buildingsCollectBtn'), 'workColorOn'); | |
if (buildingInQueue && !isBuildingRightNow){ | |
doUncheckedClick('#buildingsCollectBtn'); | |
} else if (!buildingInQueue){ | |
guessCollecting(); | |
} | |
} | |
function guessCollecting(){ | |
if (isSavingForGymystic){ | |
doUncheckedClick('#woodCollectBtn'); | |
} else { | |
doUncheckedClick('#metalCollectBtn'); | |
} | |
} | |
function buyUpgrades(){ | |
doClick('#Coordination'); | |
doClick('#Gymystic'); | |
doClick('#Speedlumber'); | |
doClick('#Speedfarming'); | |
doClick('#Speedminer'); | |
doClick('#Speedscience'); | |
doClick('#Bounty'); | |
doClick('#Efficiency'); | |
doClick('#Potency'); | |
doClick('#TrainTacular'); | |
doClick('#Anger'); | |
doClick('#Egg'); | |
doClick('#UberHut'); | |
doClick('#UberHouse'); | |
doClick('#UberMansion'); | |
doClick('#UberHotel'); | |
if (!isSavingForGymystic){ | |
doClick('#Supershield'); | |
} | |
doClick('#Dagadder'); | |
doClick('#Bootboost'); | |
doClick('#Megamace'); | |
doClick('#Hellishmet'); | |
doClick('#Polierarm'); | |
doClick('#Pantastic'); | |
doClick('#Axeidic'); | |
doClick('#Smoldershoulder'); | |
doClick('#Greatersword'); | |
doClick('#Bestplate'); | |
} | |
function buyStorageSpace(){ | |
if (game.resources.food.max * 0.9 < game.resources.food.owned){ | |
doClick('#Barn'); | |
} | |
if (game.resources.metal.max * 0.9 < game.resources.metal.owned){ | |
doClick('#Forge'); | |
} | |
if (game.resources.wood.max * 0.9 < game.resources.wood.owned){ | |
doClick('#Shed'); | |
} | |
} | |
function buyBuildings(){ | |
if (!isSavingForGymystic){ | |
doClick('#Hut'); | |
doClick('#House'); | |
doClick('#Mansion'); | |
doClick('#Hotel'); | |
doClick('#Resort'); | |
} | |
doClick('#Gateway'); | |
doClick('#Collector'); | |
if (!isSavingForGymystic){ | |
doClick('#Gym'); | |
} | |
doClick('#Tribute'); | |
doClick('#Nursery'); | |
} | |
function buyJobs(){ | |
var expectedScientists = 10; | |
if (currentZone < 10){ | |
expectedScientists = game.global.world * 5; | |
} else if (currentZone < 20){ | |
expectedScientists = game.global.world * 10; | |
} else { | |
expectedScientists = game.global.world * 20; | |
} | |
for(var i = 0; i < 300; i++){ | |
var workspaces = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed; | |
var farmer = game.jobs.Farmer.owned; | |
var lumberjack = game.jobs.Lumberjack.owned; | |
var miner = game.jobs.Miner.owned; | |
var trainer = game.jobs.Trainer.owned; | |
var explorer = game.jobs.Explorer.owned; | |
var scientist = game.jobs.Scientist.owned; | |
if (expectedScientists > scientist){ | |
doClick('#Scientist'); | |
} else if (isAvailable('#Trainer')){ | |
doClick('#Trainer'); | |
} else if (isAvailable('#Explorer')){ | |
doClick('#Explorer'); | |
} else if (workspaces > 10){ | |
if (miner < lumberjack){ | |
doClick('#Miner'); | |
} else if (lumberjack < farmer){ | |
doClick('#Lumberjack'); | |
} else { | |
doClick('#Farmer'); | |
} | |
} else { | |
break; | |
} | |
} | |
} | |
function buyEquipmentUpgrades(){ | |
var names = ['Battleaxe', 'Boots', 'Breastplate', 'Dagger', 'Greatsword', 'Helmet', 'Mace', 'Pants', 'Polearm', 'Shield', 'Shoulderguards']; | |
for(var i = 0; i < names.length; i++){ | |
var name = names[i]; | |
if (name === 'Shield' && isSavingForGymystic){ | |
continue; | |
} | |
var prestige = game.equipment[name].prestige; | |
var maxLevel = 1; | |
if (prestige === 1){ | |
maxLevel = 20; | |
} | |
if (prestige === 2){ | |
maxLevel = 15; | |
} | |
if (prestige === 3){ | |
maxLevel = 9; | |
} | |
if (prestige === 4){ | |
maxLevel = 6; | |
} | |
if (prestige === 5){ | |
maxLevel = 4; | |
} | |
if (prestige === 6){ | |
maxLevel = 5; | |
} | |
if (game.equipment[name].level < maxLevel){ | |
doClick('#' + name); | |
} | |
} | |
} | |
function isAvailable(name){ | |
var elements = getElements(name); | |
for(var key in elements){ | |
if (!elements.hasOwnProperty(key)){ | |
continue; | |
} | |
var element = elements[key]; | |
if (hasClass(element, 'thingColorCanAfford')){ | |
return true; | |
} | |
} | |
return false; | |
} | |
function doClick(name){ | |
var elements = getElements(name); | |
for(var key in elements){ | |
if (!elements.hasOwnProperty(key)){ | |
continue; | |
} | |
var element = elements[key]; | |
if (!hasClass(element, 'thingColorCanAfford')){ | |
continue; | |
} | |
elements[key].click(); | |
resetTooltip = true; | |
} | |
} | |
function doUncheckedClick(name){ | |
var elements = getElements(name); | |
for(var key in elements){ | |
if (!elements.hasOwnProperty(key)){ | |
continue; | |
} | |
var element = elements[key]; | |
elements[key].click(); | |
resetTooltip = true; | |
} | |
} | |
function getElements(name){ | |
if (name.substr(0, 1) === "."){ | |
return document.getElementsByName(name.substr(1)); | |
} else if (name.substr(0, 1) === "#"){ | |
var element = document.getElementById(name.substr(1)); | |
return element ? [element] : []; | |
} else { | |
return []; | |
} | |
} | |
function getFirstElement(name){ | |
var elements = getElements(name); | |
return elements.length > 0 ? elements[0] : null; | |
} | |
function elementExists(name){ | |
return getElements(name).length > 0; | |
} | |
function hasClass(domElement, className){ | |
return domElement ? domElement.className.indexOf(className) !== -1 : false; | |
} | |
function addEvent(element, eventName, callback) { | |
if (element.addEventListener) { | |
element.addEventListener(eventName, callback, false); | |
} else if (element.attachEvent) { | |
element.attachEvent("on" + eventName, callback); | |
} else { | |
element["on" + eventName] = callback; | |
} | |
} | |
} | |
if (typeof window.autoTrimpIntervalId !== 'undefined'){ | |
clearInterval(window.autoTrimpIntervalId); | |
} | |
window.autoTrimpIntervalId = setInterval(_createAutoTrimps(), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment