Greasy Fork

Greasy Fork is available in English.

Kittens tools

Trimps tools (visual)

当前为 2017-05-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Kittens tools
// @namespace    http://bloodrizer.ru/games/kittens/
// @version      1.025
// @description  Trimps tools (visual)
// @author       Anton
// @match        http://bloodrizer.ru/games/kittens/
// ==/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.btnContent').find('span').filter(function(){
            return $(this).text().indexOf(itemName) === 0;
        });
        if (btn && btn.length == 1) {
            _log('Autobuy ' + itemName);
            btn.click();
        }
    }

    var _autoBuyItem = function(bldName) {
        if (_canBuy(bldName)) {
            var bld = game.bld.get(bldName);
            var itemName = bld.stages && bld.stages.length > 0 ? bld.stages[bld.stage].label : bld.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 = '<style type="text/css">' +
            '.modern .btnContent, .btn.bldEnabled.modern div.btnContent, .btn.bldlackResConvert.modern div.btnContent {padding: 5px 0 5px 10px;}'+
            '.btn.modern a {padding: 5px 6px 5px 6px !important;margin:-5px 0;}'+
            '</style>';
        $('body').append($(style));
    }

    var _init = function() {
        var $a = $('<a href="#" id="botbutton">Bot (' + (tStarted ? 'on' : 'off') + ')</a>');
        $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;
            }  
        });
        
        game.canBuy = _canBuy;
    }

    var tAuto, tStarted = true;

    setTimeout(function() {
        tAuto = setInterval(_auto, 1000);
        _fixStyles();
        _init();
        _log('Started version ' + version);
    }, 1000);
})();