Greasy Fork

Greasy Fork is available in English.

Kittens tools

Trimps tools (visual)

目前为 2017-04-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         Kittens tools
// @namespace    http://bloodrizer.ru/games/kittens/
// @version      1.018
// @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 _auto = function() {
        _getAstronomy();
        _flushCatnip();
        _collectFaith();
        _ironToSteel();
        _sendHunters();
        _woodToBeams();
        _mineralsToSlabs();
        _cultureToManuscript();
        _fixFontSize();
        //_buyAll(); // TODO
    }

    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 tAuto;

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