Last active
March 1, 2018 17:55
-
-
Save scott-joe/c6e4a9845926f76b9596 to your computer and use it in GitHub Desktop.
Catnip Guard
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
// ==UserScript== | |
// @name Kitten Game | |
// @namespace www.soilandthesea.com | |
// @version 0.6.0 | |
// @description Automates certain production cycles | |
// @author Scott Williams | |
// @include http://bloodrizer.ru/games/kittens/ | |
// @include http://bloodrizer.ru/games/kittens/# | |
// @grant none | |
// ==/UserScript== | |
function start() { | |
// Bc this will certainly start before anything else is ready... | |
resources = [ | |
{ | |
'name': 'catnip', | |
'enabled': true, // TODO: get from state | |
'crafter': window.gamePage.craft.bind(window.gamePage), | |
'quantity': 10, | |
'goods': ['wood'], | |
'source': window.gamePage.resPool.get('catnip') | |
}, | |
{ | |
'name': 'wood', | |
'enabled': true, | |
'crafter': window.gamePage.craft.bind(window.gamePage), | |
'quantity': 2, | |
'goods': ['beam'], | |
'source': window.gamePage.resPool.get('wood') | |
}, | |
{ | |
'name': 'minerals', | |
'enabled': true, | |
'crafter': window.gamePage.craft.bind(window.gamePage), | |
'quantity': 2, | |
'goods': ['slab'], | |
'source': window.gamePage.resPool.get('minerals') | |
}, | |
{ | |
'name': 'iron', | |
'enabled': true, | |
'crafter': window.gamePage.craft.bind(window.gamePage), | |
'quantity': 2, | |
'goods': ['plate'], | |
'source': window.gamePage.resPool.get('iron') | |
}, | |
{ | |
'name': 'coal', | |
'enabled': true, | |
'crafter': window.gamePage.craftAll.bind(window.gamePage), | |
'quantity': undefined, | |
'goods': ['steel'], | |
'source': window.gamePage.resPool.get('coal') | |
}, | |
{ | |
'name': 'gold', | |
'enabled': true, | |
'crafter': window.gamePage.village.promoteKittens.bind(window.game.village), | |
'quantity': undefined, | |
'goods': undefined, | |
'source': window.gamePage.resPool.get('gold') | |
}, | |
{ | |
'name': 'catpower', | |
'enabled': true, | |
'crafter': $("#fastHuntContainer a"), | |
'quantity': undefined, | |
'goods': 'click', | |
'source': window.gamePage.resPool.get('manpower') | |
}, | |
{ | |
'name': 'culture', | |
'enabled': true, | |
'crafter': window.gamePage.craftAll.bind(window.gamePage), | |
'quantity': undefined, | |
'goods': ['manuscript', 'compedium', 'blueprint'], | |
'source': window.gamePage.resPool.get('culture') | |
}, | |
{ | |
'name': 'furs', | |
'enabled': true, | |
'crafter': window.gamePage.craftAll.bind(window.gamePage), | |
'quantity': undefined, | |
'goods': ['parchment'], | |
'source': window.gamePage.resPool.get('furs') | |
}, | |
{ | |
'name': 'faith', | |
'enabled': true, | |
'crafter': window.gamePage.religion.praise.bind(window.gamePage.religion), | |
'quantity': undefined, | |
'goods': undefined, | |
'source': window.gamePage.resPool.get('faith') | |
} | |
]; | |
// Now, lets get on with it | |
setInterval(tick, 2000); | |
} | |
var resources = []; | |
var refresh = function() { | |
for (var i = resources.length - 1; i >= 0; i--) { | |
var current = resources[i]; | |
current.enabled = true; // TODO: pull from UI modified state later | |
} | |
}; | |
var dangerZone = function(resource) { | |
var threshold = 0.9; | |
return ( (resource.source.value / resource.source.maxValue) >= threshold ); | |
}; | |
// var quantity = function(resource) { | |
// return (resource.value * 0.1); | |
// } | |
function pause() { | |
if ( $('#advisorsContainer').children().length !== 0 ) { | |
$("#pauseBtn").trigger('click'); | |
} | |
} | |
function observe() { | |
if ( $('#observeButton').children().length !== 0 ) { | |
$('#observeBtn').trigger('click'); | |
} | |
} | |
var craft = function(current) { | |
if ( current.goods === 'click' ){ | |
current.crafter.trigger('click'); | |
} else if (current.goods !== undefined){ | |
for (var i = 0; i < current.goods.length; i++) { | |
var good = current.goods[i]; | |
current.crafter(good, current.quantity); | |
} | |
} else { | |
current.crafter(); | |
} | |
}; | |
var tick = function() { | |
refresh(); | |
pause(); | |
observe(); | |
for (var i = resources.length - 1; i >= 0; i--) { | |
var currentResource = resources[i]; | |
if (currentResource.enabled && dangerZone(currentResource)) { | |
craft(currentResource); | |
} | |
} | |
}; | |
if (!($ = window.jQuery)) { | |
var script = document.createElement( 'script' ); | |
script.src = 'https://code.jquery.com/jquery-2.1.3.min.js'; | |
script.onload = start; | |
document.body.appendChild(script); | |
} else { | |
setTimeout(start, 5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment