// ==UserScript==
// @name Kittens tools
// @namespace http://bloodrizer.ru/games/kittens/
// @version 1.022
// @description Trimps tools (visual)
// @author Anton
// @match http://bloodrizer.ru/games/kittens/
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var $ = jQuery, isStarted = false,
version = typeof GM_info == 'function' ? GM_info().script.version :
(typeof GM_info == 'object' ? GM_info.script.version : '?');
var _log = function(message) {
var mes = 'BOT: ' + message;
game.msg(mes, 'msg');
game.ui.renderConsoleLog();
}
var isUnlocked = function(res) {
var resource = game.resPool.get(res);
return resource.unlocked;
}
var _craftAll = function(res) {
if (isUnlocked(res)) {
_log("Crafting " + res);
game.craftAll(res);
}
}
var _getAstronomy = function() {
if (game.calendar.observeRemainingTime > 0) {
if (typeof game.calendar.observeHandler === 'function') {
_log('Collecting astronomy');
game.calendar.observeHandler();
}
}
}
var _flushCatnip = function() {
var catnip = game.resPool.get("catnip");
if (catnip.value >= catnip.maxValue) {
_log('Catnip to Wood');
game.craftAll('wood');
}
}
var _collectFaith = function() {
var faith = game.resPool.get("faith");
if (faith.value >= faith.maxValue) {
_log('Praise');
game.religion.praise();
}
}
var _sendHunters = function() {
var manpower = game.resPool.get("manpower");
if (manpower.value >= manpower.maxValue) {
_log('Sending hunters');
game.village.huntAll();
_craftAll('parchment');
}
}
var _ironToSteel = function() {
var iron = game.resPool.get("iron");
var coal = game.resPool.get("coal");
if (iron.value >= iron.maxValue || coal.value >= coal.maxValue) {
if (coal.value >= 100 && iron.value >= 100 && isUnlocked('steel')) {
_log('Iron to Steel');
game.craftAll('steel');
} else if (iron.value >= 125 && isUnlocked('plate')) {
_log('Iron to Plate');
game.craft('plate', 1);
}
}
}
var _woodToBeams = function() {
var wood = game.resPool.get("wood");
if (wood.value >= wood.maxValue && isUnlocked('beam')) {
_log('Wood to Beam');
game.craft('beam', 1);
}
}
var _mineralsToSlabs = function() {
var minerals = game.resPool.get("minerals");
if (minerals.value >= minerals.maxValue && isUnlocked('slab')) {
_log('Minerals to Slab');
game.craft('slab', 1);
}
}
var _fixFontSize = function() {
var fnt1 = $('#leftColumn').css('font-size');
var fnt2 = $('#midColumn').css('font-size');
var fnt3 = $('#rightColumn').css('font-size');
if (fnt2 != fnt1 || fnt3 != fnt1) {
_log('Fixing font size');
$('#midColumn').css('font-size', fnt1)
$('#rightColumn').css('font-size', fnt1)
}
}
var _buyAll = function() {
for (var x in game.bld.metaCache) {
var name = game.bld.metaCache[x].meta.name;
if (game.bld.metaCache[x].meta.unlocked && game.resPool.hasRes(game.bld.getPrices(name))) {
_log('AUTOBUY ' + name);
// TODO
}
}
}
var _cultureToManuscript = function() {
var culture = game.resPool.get("culture");
var parchment = game.resPool.get("parchment");
if (culture.value >= culture.maxValue && isUnlocked('manuscript') && culture.value >= 400 && parchment.value >= 25) {
_log('Culture to Manuscript');
game.craft('manuscript', 1);
}
}
var _canBuy = function(bldName) {
var prices = game.bld.getPrices(bldName);
for (var x in prices) {
if (prices.hasOwnProperty(x)) {
if (prices[x].val > game.resPool.get(prices[x].name).value) {
return false;
}
}
}
return true;
}
var _makeABuy = function(itemName) {
var btn = $('.bldGroupContainer').find('div.btn').find('span:startsWith("' + itemName +'")');
if (btn && btn.length == 1) {
_log('Autobuy ' + itemName);
btn.click();
}
}
var _autoBuyItem = function(bldName) {
if (_canBuy(bldName)) {
var itemName = game.bld.get(bldName).label;
_makeABuy(itemName);
}
}
var _autoBuy = function() {
_autoBuyItem('field');
_autoBuyItem('pasture');
_autoBuyItem('unicornPasture');
}
var _auto = function() {
_getAstronomy();
_fixFontSize();
if (!tStarted) return;
_woodToBeams();
_mineralsToSlabs();
_flushCatnip();
_collectFaith();
_ironToSteel();
_sendHunters();
_cultureToManuscript();
//_buyAll(); // TODO
_autoBuy();
}
var _fixStyles = function() {
var style = '';
$('body').append($(style));
}
var _init = function() {
var $a = $('Bot');
$a.on("click", function() {
tStarted = !tStarted;
_log((tStarted ? 'Started' : 'Stopped') + ' version ' + version);
$('#botbutton').text(tStarted ? 'Bot (on)' : 'Bot (off)');
})
$('#headerLinks .links-block').append(' | ').append($a);
$.extend($.expr[':'], {
startsWith: function(elem,match) {
return (elem.textContent || elem.innerText || "").indexOf(match[3]) == 0;
}
});
}
var tAuto, tStarted = true;
setTimeout(function() {
tAuto = setInterval(_auto, 1000);
_fixStyles();
_init();
_log('Started version ' + version);
}, 1000);
})();