Cookie clicker tools

Cookie clicker tools (visual)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Cookie clicker tools
// @namespace    orteil.dashnet.org
// @version      2.033
// @description  Cookie clicker tools (visual)
// @author       Anton
// @match        http://orteil.dashnet.org/cookieclicker/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    var log = [], logTitle = '<div class="section">Cookies 2.0.33 is here!</div>', newLogs = 0;

    var started = false, t2, t3, tClick, tClickFrenzy, oldTitle = '';
    
    var _caption = function(txt) {
        var $v = jQuery('#versionNumber');
        if ($v.text() != txt) $v.text(txt);
    }
    var _title = function(txt) {
        var newTitle = (newLogs > 0 ? '(' + newLogs + ') ' : '') + txt;
        if (document.title != newTitle) {
            oldTitle = txt;
            document.title = newTitle;
        }
    }
    var _titlePercent = function(have, need, txt) {
        var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
        _title((percent < 10 ? '00' : (percent < 100 ? '0' : '')) + String(percent) + "% - " + txt);
    }
    var _addLog = function(text) {
        log.push(text);
        Game.updateLog = logTitle + '<div class="subsection"><div class="listing">' +
            log.join('</div><div class="listing">') + '</div></div>';
        newLogs++;
        jQuery('#logButton').text('Log (' + newLogs + ')')
        _title(oldTitle);
    }
    jQuery('#logButton').text('Log').on("click", function() {
        newLogs = 0;
        jQuery('#logButton').text('Log');
    });
    
    var startT = function() {
        t2 = setInterval(function() {
            
            var wrinklersCount = 0, maxWrinkler = -1, maxSucked = 0;
            for (i in Game.wrinklers) {
                if (Game.wrinklers[i].sucked > 0) {
                    wrinklersCount++;
                }
            }
            if (wrinklersCount >= 10 || Game.hasBuff('Elder frenzy')) {
                var wrinklesIncome = 0;
                for (i in Game.wrinklers) {
                    wrinklesIncome += Game.wrinklers[i].sucked;
                    Game.wrinklers[i].hp = 0; // kill ALL
                }
                if (wrinklesIncome > 0) {
                    _addLog('Killed all Wrinkles for ' + Beautify(wrinklesIncome) + ' because of ' + (Game.hasBuff('Elder frenzy') ? '"Elder frenzy"' : 'count 10.'));
                }
            }

            var buffMult = 1;
            for (var buff in Game.buffs) {
                if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
                    buffMult = buffMult * Game.buffs[buff].multCpS;
                }
            }
            
            var normalCookiesPs = Game.cookiesPs / (buffMult !== 0 ? buffMult : 1);
            var minimalMoney = normalCookiesPs * 42100;
            var moneyCanSpend = Game.cookies - minimalMoney;
            
            if (moneyCanSpend < 0) {
                _caption('Collecting minimum ' + Beautify(minimalMoney));
                _titlePercent(Game.cookies, minimalMoney, 'minimum');
                return;
            }
                
            var minNewObjectPrice = null;
            for (var i in Game.ObjectsById) {
                if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
                    if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
                        var p = Game.ObjectsById[i].price;
                        if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
                    }
                }
            }
            
            var u = null; // upgrade can buy
            var minUpgradePrice = null;
            for (var g in Game.UpgradesById) {
                if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
                    //u.push(Game.UpgradesById[g]);
                    if (minUpgradePrice === null) {
                        minUpgradePrice = Game.UpgradesById[g].basePrice;
                        u = g;
                    } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
                        minUpgradePrice = Game.UpgradesById[g].basePrice;
                        u = g;
                    }
                }
            }
            
            var longTime = (Game.cookiesPs < 100) ? 1 : (
                (Game.cookiesPs < 1000) ? 2 : (
                    (Game.cookiesPs < 10000) ? 3 : (
                        (Game.cookiesPs < 1E5) ? 4 : (
                            (Game.cookiesPs < 1E6) ? 5 : (
                                (Game.cookiesPs < 1E9) ? 10 : 15
                                )
                            )
                        )
                    )
                );
                
            var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) && 
                u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
                (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / Game.cookiesPs) <= (longTime*60));
                
            if (needUpgrade)
            {
                if (Game.UpgradesById[u].canBuy()) {
                    Game.UpgradesById[u].buy();
                    _addLog('Buy upgrade ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
                } else {
                    _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
                    _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
                }
            } else {
                var minInvert = null, minObj = null;
                for (i in Game.ObjectsById) {
                    if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
                        if (Game.ObjectsById[i].locked === 0) {
                            var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
                            if (minInvert === null) {
                                minInvert = interest;
                                minObj = i;
                            } else if (interest < minInvert) {
                                minInvert = interest;
                                minObj = i;
                            }
                        }
                    }
                }
                if (minObj !== null) {
                    if (Game.ObjectsById[minObj].price < moneyCanSpend) {
                        Game.ObjectsById[minObj].buy(1);
                        _addLog('Buy object ' + Game.ObjectsById[minObj].name + ' for ' + Beautify(Game.ObjectsById[minObj].price));
                    } else {
                        _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
                        _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
                    }
                }
                
            }

        }, 1000);
        
        started = true;
        _caption('Started');
        _addLog('Autobuy start!');
    }
    
    var stopT = function() {
        clearInterval(t2);
        started = false;
        _caption('Collecting gold...');
        _addLog('Autobuy stop.');
    }
    
    jQuery('#versionNumber').on("click", function() {
        if (!started)
            startT();
        else
            stopT();
    });
    
    setTimeout(function() {
        t3 = setInterval(function() {
            var golden = Game.shimmers;
            if (golden.length > 0) {
                for (var i in golden) {
                    golden[i].pop();
                }
            }
        }, 1000);
        
        tClickFrenzy = setInterval(function() {
            if (Game.hasBuff('Click frenzy') || Game.hasBuff('Cursed finger')) {
                Game.ClickCookie();
            }
        }, 75);
        
        if (Game.cookiesPs < 1E6) {
            tClick = setInterval(function() {
                Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
                Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
                Game.ClickCookie();
                if (Game.cookiesPs > 1E8) clearInterval(tClick);
            }, 300);
        }
        
        _caption('Collecting gold...');
    }, 5000);
})();