IdlePixel Lucky

Calculates how lucky you are with your drops.

当前为 2023-07-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         IdlePixel Lucky
// @namespace    com.missnobody.idlepixel.lucky
// @version      1.0.6
// @description  Calculates how lucky you are with your drops.
// @author       MissNobody
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require https://gf.qytechs.cn/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==

(function()
{
    'use strict';

    class LuckyPlugin extends IdlePixelPlusPlugin
    {
        constructor()
        {
            super("Lucky",
            {
                about:
                {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
        }

        onLogin()
        {
            updateCombat();
        }

        onVariableSet(key, before, after)
        {
            if (before != after)
            {
                updateCombat();
            }
        }

        onCombatEnd()
        {
            updateCombat();
        }

        updateCombat()
        {
            let table = $('table[class="combat-log-table"]');
            let header = table.find('th:contains("Luck")');
            let rows = table.find("tr");
            let column;
            
            if (header.length <= 0)
            {
                column = rows.first().children().length;
                rows.first().append('<th style="background-color:#DEDEED;padding:10px;text-align:center;">Luck</th>');
            }
            else
            {
                column = header.parent().children().index(header);
                header.text("0.0");
            }

            $.each(rows, function(index, row)
            {
                if (index > 0)
                {
                    let columns = row.children();

                    let amount = columns[2].text();
                    let chance = columns[3].text();

                    if (column >= columns.length)
                    {
                        row.append('<td>0.0</td>');
                    }
                    else
                    {
                        columns[column].text("0.0");
                    }
                }
            });
        }

        luckFactor(n, N)
        {
            let b = solveForB(N);
            return 2 * Math.exp(b * n) - 1;
        }

        solveForB(N)
        {
            let b = -0.01;
            let precision = 0.0001;
            let maxIterations = 100;
            let delta;
            let iteration = 0;

            do
            {
                let f = 2 * Math.exp(b * N) - 1;
                let df = 2 * N * Math.exp(b * N);

                if (Math.abs(df) < 1e-6) return -2.0;

                delta = -f / df;
                b += delta;

                if (++iteration > maxIterations) return b;

            } while (Math.abs(delta) > precision);

            return b;
        }
    }

    const plugin = new LuckyPlugin();
    IdlePixelPlus.registerPlugin(plugin);

})();

QingJ © 2025

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