Greasy Fork

Greasy Fork is available in English.

GOTA_Extender_Auxiliary

Auxiliary functions for the page and the extender.

当前为 2014-10-11 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/5618/20834/GOTA_Extender_Auxiliary.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

var extender = {
    command: function (name, args) {
        var cmd = { name: name, args: args };
        $("textarea#observable").attr("command", JSON.stringify(cmd));
    },
    lastcommand: function () {
        return $("textarea#observable").attr("command");
    },
    option: function (option, val) {
        if (typeof option == "string") {
            this.command("option", [option, val]);
        } else {
            error("Please specify name and value as parameters.", "COMMAND");
        }
    }
};

var productionQueue = [];
function attemptProduction() {
    if (!productionQueue || productionQueue.length == 0) {
        log('Attempted production, but queue was missing or empty. Exiting...', "PRODUCTION");
        return;
    }

    for (var i = 0; i < userContext.buildingsData.length; i++) {
        var b = userContext.buildingsData[i];

        if (buildingProducing(b)) {
            log("Building " + b.symbol + " is busy.", "PRODUCTION");
            continue;
        }

        if (buildingFinished(b)) {
            log("Building " + b.symbol + " finished production.", "PRODUCTION");
            doFinishProduction(b.item_id, attemptProduction);
            return;
        }

        var element = getElement(b.symbol);
        if (element) {
            executeElement(element, attemptProduction);
            return;
        }
    }
};

function getElement(buildingSymbol) {
    if (!productionQueue || productionQueue.length == 0) {
        log('Attempted to extract item from queue, but the production queue was missing or empty. Exiting...', "PRODUCTION");
        return null;
    }

    var element;

    for (var i = 0; i < productionQueue.length; i++) {

        if (productionQueue[i].activeBuildingPanel == buildingSymbol) {
            element = productionQueue[i];
            break;
        }
    }

    if (!element) {
        log('No elements enqueued for building ' + buildingSymbol + '. Array size: ' + productionQueue.length, "PRODUCTION");
        return null;
    }

    return element;
};

function executeElement(element, callback) {

    var index = productionQueue.indexOf(element);
    log('Production of element ' + element.name + ' : ' + element.type + ' with index ' + index + ' initiated.', "PRODUCTION");

    if (element.type == "item") {
        userContext.recipeData = element.recipeData;
        userContext.activeBuildingPanel = element.activeBuildingPanel;

        doProduction(element.outputSymbol, element.recipeCategory, null, null, element.recipeName, callback);
        productionQueue.splice(index, 1);

        log('Production details: ' + element.name + ' at ' + element.activeBuildingPanel + ', ' + element.outputSymbol + ', ' + element.recipeCategory + ', ' + element.recipeName + ';', "PRODUCTION");
    } else {

        var buildingId = buildingBySymbol(element.activeBuildingPanel).id;

        applySelectedUpgrade({ building_id: buildingId, id: element.upgradeId, gold: 0, silver: 0 }, null, callback);
        productionQueue.splice(index, 1);

        log('Production details: ' + element.name + ' : ' + element.type + ' at ' + element.activeBuildingPanel + ', ' + element.symbol + ';', "PRODUCTION");

    }
};

function buildingFinished(b) {
    return b.producing_archetype_id && !b.build_remaining;
}

function buildingProducing(b) {
    return b.producing_archetype_id && b.build_remaining;
}

var bruteForceTimeout;
function bruteForce(enabled) {

    if (typeof enabled == "boolean" && !enabled) {
        bruteForceTimeout = clearTimeout(bruteForceTimeout);
        log("Terminated.", "BRUTING");
        return;
    }

    if (extender_bruteWounds && extender_bruteWounds == 0) {
        warn("Disabled. Please set number of max wounds from options to continue.", "BRUTING");
        bruteForce(false);
    }

    var s = userContext.setSwornSword;

    if (!s) {
        error("Failed, no sworn sword set.", "BRUTING");
        bruteForce(false);
        return;
    }

    if (s.damage < extender_bruteWounds) {

        doAdventure("", s.modifier, false, function () {
            bruteForce(true);
        });

        return;
    }

    if (extender_bruteSwitchOff) {

        warn("Sworn sword recieved " + extender_bruteWounds + " wounds! Brute timer will self terminate.", "BRUTING");
        bruteForce(false);
        return;

    }

    // Add a minute to the cooldown, and then multiply by wounds
    var interval = extender_bruteWounds * (s.damage_cooldown + 60);
    warn("Sworn sword recieved " + extender_bruteWounds + " wounds! " +
            "Brute timer will self adjust. Wait " + interval + " seconds.", "BRUTING");

    bruteForceTimeout = setTimeout(function () {
        bruteForce(true);
    }, interval * 1000);
};

$(document).on("keyup", function (e) {
    if (e.keyCode == 27 && typeof bruteForceTimeout != "undefined") {
        e.preventDefault();
        e.stopPropagation();

        bruteForceTimeout = clearTimeout(bruteForceTimeout);
        bruteForce();

        alert("Bruting terminated.");
    }
});

function increment(me) {
    var opt = $(me);

    var min = parseInt(opt.attr("min"));
    var max = parseInt(opt.attr("max"));
    var step = parseInt(opt.attr("step"));
    var val = parseInt(opt.text());

    if (isNaN(min) || isNaN(max) || isNaN(step) || isNaN(val)) {
        error("Parsing of attributes failed!", "number option");
        return;
    }

    var newVal = val + step > max ? min : val + step;
    opt.text(newVal);
};

function check(me) {
    $(me).toggleClass('checked');
};

function bruteSwitchToggle(me) {
    var bSwitch = $(me).find("a.btngold");
    bSwitch.text() == "switch off"
    ? bSwitch.text("adjust")
    : bSwitch.text("switch off");
};