Melvor Idle - AutoMastery

Automatically spends mastery when a pool is about to fill up

目前为 2020-10-23 提交的版本。查看 最新版本

// ==UserScript==
// @name        Melvor Idle - AutoMastery
// @description Automatically spends mastery when a pool is about to fill up
// @version     1.1
// @namespace   Visua
// @match       https://melvoridle.com/*
// @match       https://www.melvoridle.com/*
// @grant       none
// ==/UserScript==
/* jshint esversion: 6 */

((main) => {
    var script = document.createElement('script');
    script.textContent = `try { (${main})(); } catch (e) { console.log(e); }`;
    document.body.appendChild(script).parentNode.removeChild(script);
})(() => {
    'use strict';

    function autoSpendMasteryPool(skill, xpToBeAdded) {
        const poolXp = MASTERY[skill].pool;
        if (poolXp + xpToBeAdded >= getMasteryPoolTotalXP(skill)) {
            const availableXp = poolXp - getMasteryPoolTotalXP(skill) * window.autoMasteryThresholds[skill] / 100;
            if (availableXp <= 0) {
                return;
            }

            let masteryToLevel = window.autoMasterySelectedMasteries[skill];

            if (masteryToLevel !== -1) {
                if (getMasteryLevel(skill, masteryToLevel) >= 99) {
                    masteryToLevel = -1;
                }
            }

            if (masteryToLevel === -1) {
                masteryToLevel = MASTERY[skill].xp.map((xp, id) => ({ xp, id })).reduce((max, m) => {
                    const toNext = getMasteryXpForNextLevel(skill, m.id);
                    if (toNext > 0 && toNext <= availableXp && m.xp >= max.xp) {
                        return m;
                    } else {
                        return max;
                    }
                }, { xp: 0, id: -1 }).id;
            }

            if (masteryToLevel === -1) {
                const min = MASTERY[skill].xp.map((_, id) => ({ toNext: getMasteryXpForNextLevel(skill, id), id })).reduce((min, m) => (m.toNext > 0 && m.toNext < min.toNext) ? m : min);
                if (min.toNext > 0 && min.toNext < poolXp) {
                    masteryToLevel = min.id;
                }
            }

            if (masteryToLevel !== -1) {
                console.log(`AutoMastery: Leveling up ${getMasteryName(skill, masteryToLevel)} to ${getMasteryLevel(skill, masteryToLevel) + 1}`);
                const _showSpendMasteryXP = showSpendMasteryXP;
                showSpendMasteryXP = () => { };
                try {
                    levelUpMasteryWithPool(skill, masteryToLevel);
                } catch (e) {
                    console.error(e);
                } finally {
                    showSpendMasteryXP = _showSpendMasteryXP;
                }
            }
        }
    }

    function autoMastery() {
        window.autoMasteryThresholds = Array(Object.keys(SKILLS).length).fill(95);
        window.autoMasterySelectedMasteries = Array(Object.keys(SKILLS).length).fill(-1);

        const _addMasteryXPToPool = addMasteryXPToPool;
        addMasteryXPToPool = (...args) => {
            try {
                const skill = args[0];
                const xp = args[1];
                if (xp > 0) {
                    autoSpendMasteryPool(skill, xp);
                }
            } catch (e) {
                console.error(e);
            } finally {
                _addMasteryXPToPool(...args);
            }
        };
    }

    function loadScript() {
        if (typeof confirmedLoaded !== 'undefined' && confirmedLoaded && !currentlyCatchingUp) {
            clearInterval(interval);
            console.log('Loading AutoMastery');
            autoMastery();
        }
    }

    const interval = setInterval(loadScript, 500);
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址