MediaWiki:Gadget-calc-skillingparty.js: Difference between revisions

From Idle Clans wiki
m (reverting and commenting out for now)
Tag: Reverted
mNo edit summary
Tag: Manual revert
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
/*
mw.loader.using(["jquery"], function () {
mw.loader.using(['jquery'], function() {
  $(document).ready(function () {
    $(document).ready(function() {
    // Create the Gatherers Upgrade Checkbox
        // Create the slider
    var gatherersCheckbox = $('<input type="checkbox" id="gatherers-upgrade">');
        var slider = $('<input type="range" min="0" max="80" value="0" id="time-slider">');
    var gatherersLabel = $(
        var sliderLabel = $('<p>Adjust skilling speed: <span id="slider-value">0</span>%</p>');
      '<label for="gatherers-upgrade"> Gatherers Upgrade</label><br>'
    );


        // Ticket chancing formula calculation
    // Create the slider
        function calculateChancePerAction(levelRequirement)
    var slider = $(
        {
      '<input type="range" min="0" max="80" value="0" id="time-slider">'
            return 1.2 * 0.000005 * ((levelRequirement / 10) * 1.033);
    );
         }
    var sliderLabel = $(
      '<p>Adjust skilling speed: <span id="slider-value">0</span>%</p>'
    );
 
    // Ticket chancing formula calculation
    function calculateChancePerAction(levelRequirement) {
      return 1.2 * 0.000005 * ((levelRequirement / 10) * 1.033);
    }
 
    // Function to determine if the skill qualifies for the Gatherers boost
    function isGatherersSkill(skill) {
      return ["Fishing", "Mining", "Woodcutting", "Foraging"].includes(skill);
    }
 
    // Task time with boost column
    function getTaskTimeWithBoost() {
         var lastSkill = ""; // Store the last seen skill
 
        $("tr").each(function () {
            var skillCell = $(this).find("td:first"); // First column might contain the skill
 
            // If this row has a skill name, update lastSkill
            if (skillCell.text().trim() !== "") {
                lastSkill = skillCell.text().trim();
            }
 
            // Apply task time adjustments to all rows
            $(this).find(".modified-time").each(function () {
                var time = parseFloat($(this).attr("data-time")) / 100; // Convert ms to seconds
                var sliderValue = parseFloat($("#time-slider").val()) / 100;
                var actionTimeWithSkillSpeed = time * (1 - sliderValue);
 
                // Apply 5% faster time if Gatherers is checked and the skill is a gathering skill
                if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(lastSkill)) {
                    actionTimeWithSkillSpeed *= 0.95;
                }


        // Average hours Column
                 $(this).text(actionTimeWithSkillSpeed.toFixed(2));
        function applyAverageHoursChanges()
        {
            $(".average-hours").each(function() {
                 var levelRequirement = $(this).data("level");
                var time = $(this).data("time") / 100;
                var decimalChance = calculateChancePerAction(levelRequirement);
                var actionTimeWithSkillSpeed = time * (1 - slider.val() / 100)
                var averageActionsPerTicket = 1 / decimalChance;
                var averageTimeSpentPerTicket = averageActionsPerTicket * actionTimeWithSkillSpeed;
                var averageHours = averageTimeSpentPerTicket / 3600 ;
                $(this).text(averageHours.toFixed(2));
             });
             });
        });
    }
    // Average hours Column
    function applyAverageHoursChanges() {
      $(".average-hours").each(function () {
        var levelRequirement = $(this).data("level");
        var time = $(this).data("time") / 100;
        var decimalChance = calculateChancePerAction(levelRequirement);
        var sliderValue = slider.val() / 100;
        var actionTimeWithSkillSpeed = time * (1 - sliderValue);
        // Apply 5% faster time if Gatherers is checked and skill qualifies
        var skill = $(this).closest("tr").find("td:first").text().trim();
        if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(skill)) {
          actionTimeWithSkillSpeed *= 0.95;
         }
         }
        var averageActionsPerTicket = 1 / decimalChance;
        var averageTimeSpentPerTicket =
          averageActionsPerTicket * actionTimeWithSkillSpeed;
        var averageHours = averageTimeSpentPerTicket / 3600;
        $(this).text(averageHours.toFixed(2));
      });
    }
    // Chance per action Column
    function applyChancePerActionChanges() {
      $(".chance-per-action").each(function () {
        var levelRequirement = $(this).data("level");
        var decimalChance = calculateChancePerAction(levelRequirement);
        var averageActionsPerTicket = 1 / decimalChance;
        var textChance =
          "1 in " + Math.ceil(averageActionsPerTicket).toLocaleString();
        $(this).text(textChance);
      });
    }


        // Chance per action Column
    // Chance for at least 1 ticket per day Column
        function applyChancePerActionChanges()
    function applyChancePerDayChanges() {
        {
      $(".chance-per-day").each(function () {
            $(".chance-per-action").each(function() {
        var levelRequirement = $(this).data("level");
                var levelRequirement = $(this).data("level");
        var time = $(this).data("time") / 100;
                var decimalChance = calculateChancePerAction(levelRequirement);
        var decimalChance = calculateChancePerAction(levelRequirement);
                var averageActionsPerTicket = 1 / decimalChance;
        var sliderValue = slider.val() / 100;
                var textChance = "1 in " + Math.ceil(averageActionsPerTicket).toLocaleString();
        var actionTimeWithSkillSpeed = time * (1 - sliderValue);
                $(this).text(textChance);
 
            });
        // Apply 5% faster time if Gatherers is checked and skill qualifies
        var skill = $(this).closest("tr").find("td:first").text().trim();
        if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(skill)) {
          actionTimeWithSkillSpeed *= 0.95;
         }
         }
        var actionsPerDay = (24 * 3600) / actionTimeWithSkillSpeed;
        var failureChance = 1 - decimalChance;
        var consecutiveFailureChance = Math.pow(failureChance, actionsPerDay);
        var successChance = 1 - consecutiveFailureChance;
        var successPercentage = (successChance * 100).toFixed(2);
        $(this).text(successPercentage + "%");
      });
    }
    // Append slider to the page
    $(".mw-slider-md").append(sliderLabel).append(slider);


        // Chance for at least 1 ticket per day Column
    // Append checkbox below slider
        function applyChancePerDayChanges()
    $(".mw-slider-md").append("<br>").append($('<label>').append(gatherersCheckbox).append(" Gatherers Upgrade"));
        {
 
            $(".chance-per-day").each(function() {
    // Initial calculation after load
                var levelRequirement = $(this).data("level");
    getTaskTimeWithBoost();
                var time = $(this).data("time") / 100;
    applyChancePerActionChanges();
                var decimalChance = calculateChancePerAction(levelRequirement);
    applyChancePerDayChanges();
                var actionTimeWithSkillSpeed = time * (1 - slider.val() / 100)
    applyAverageHoursChanges();
                var actionsPerDay = 24 * 3600 / actionTimeWithSkillSpeed;
 
                var failureChance = 1 - decimalChance;
    // Update the table values when the slider or checkbox changes
                var consecutiveFailureChance = Math.pow(failureChance, actionsPerDay);
    $(document).on("change", "#gatherers-upgrade", function () {
                var successChance = 1 - consecutiveFailureChance;
      getTaskTimeWithBoost();
                var successPercentage = (successChance * 100).toFixed(2);
      applyChancePerDayChanges();
                $(this).text(successPercentage + "%");
      applyAverageHoursChanges();
            });
    });
        }
       
        // Append slider to the page
        $(".mw-slider-md").append(sliderLabel).append(slider);


        // Initial calcualtion after load
    // Reapply updates after sorting happens
         applyChancePerActionChanges();
    $(document).on("sortEnd", function () {
         getTaskTimeWithBoost();
         applyChancePerDayChanges();
         applyChancePerDayChanges();
         applyAverageHoursChanges();
         applyAverageHoursChanges();
    });


        // Update the table values when the slider is moved
    // Update the table values when the slider is moved
        slider.on("input", function() {
    slider.on("input", function () {
            var sliderValue = $(this).val();
      var sliderValue = $(this).val();
            $("#slider-value").text(sliderValue);
      $("#slider-value").text(sliderValue);


            applyChancePerDayChanges();
      getTaskTimeWithBoost();
            applyAverageHoursChanges();
      applyChancePerDayChanges();
        });
      applyAverageHoursChanges();
     });
     });
  });
});
});
*/

Latest revision as of 05:16, 23 February 2025

mw.loader.using(["jquery"], function () {
  $(document).ready(function () {
    // Create the Gatherers Upgrade Checkbox
    var gatherersCheckbox = $('<input type="checkbox" id="gatherers-upgrade">');
    var gatherersLabel = $(
      '<label for="gatherers-upgrade"> Gatherers Upgrade</label><br>'
    );

    // Create the slider
    var slider = $(
      '<input type="range" min="0" max="80" value="0" id="time-slider">'
    );
    var sliderLabel = $(
      '<p>Adjust skilling speed: <span id="slider-value">0</span>%</p>'
    );

    // Ticket chancing formula calculation
    function calculateChancePerAction(levelRequirement) {
      return 1.2 * 0.000005 * ((levelRequirement / 10) * 1.033);
    }

    // Function to determine if the skill qualifies for the Gatherers boost
    function isGatherersSkill(skill) {
      return ["Fishing", "Mining", "Woodcutting", "Foraging"].includes(skill);
    }

    // Task time with boost column
    function getTaskTimeWithBoost() {
        var lastSkill = ""; // Store the last seen skill

        $("tr").each(function () {
            var skillCell = $(this).find("td:first"); // First column might contain the skill

            // If this row has a skill name, update lastSkill
            if (skillCell.text().trim() !== "") {
                lastSkill = skillCell.text().trim();
            }

            // Apply task time adjustments to all rows
            $(this).find(".modified-time").each(function () {
                var time = parseFloat($(this).attr("data-time")) / 100; // Convert ms to seconds
                var sliderValue = parseFloat($("#time-slider").val()) / 100;
                var actionTimeWithSkillSpeed = time * (1 - sliderValue);

                // Apply 5% faster time if Gatherers is checked and the skill is a gathering skill
                if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(lastSkill)) {
                    actionTimeWithSkillSpeed *= 0.95;
                }

                $(this).text(actionTimeWithSkillSpeed.toFixed(2));
            });
        });
    }

    // Average hours Column
    function applyAverageHoursChanges() {
      $(".average-hours").each(function () {
        var levelRequirement = $(this).data("level");
        var time = $(this).data("time") / 100;
        var decimalChance = calculateChancePerAction(levelRequirement);
        var sliderValue = slider.val() / 100;
        var actionTimeWithSkillSpeed = time * (1 - sliderValue);

        // Apply 5% faster time if Gatherers is checked and skill qualifies
        var skill = $(this).closest("tr").find("td:first").text().trim();
        if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(skill)) {
          actionTimeWithSkillSpeed *= 0.95;
        }
        var averageActionsPerTicket = 1 / decimalChance;
        var averageTimeSpentPerTicket =
          averageActionsPerTicket * actionTimeWithSkillSpeed;
        var averageHours = averageTimeSpentPerTicket / 3600;
        $(this).text(averageHours.toFixed(2));
      });
    }

    // Chance per action Column
    function applyChancePerActionChanges() {
      $(".chance-per-action").each(function () {
        var levelRequirement = $(this).data("level");
        var decimalChance = calculateChancePerAction(levelRequirement);
        var averageActionsPerTicket = 1 / decimalChance;
        var textChance =
          "1 in " + Math.ceil(averageActionsPerTicket).toLocaleString();
        $(this).text(textChance);
      });
    }

    // Chance for at least 1 ticket per day Column
    function applyChancePerDayChanges() {
      $(".chance-per-day").each(function () {
        var levelRequirement = $(this).data("level");
        var time = $(this).data("time") / 100;
        var decimalChance = calculateChancePerAction(levelRequirement);
        var sliderValue = slider.val() / 100;
        var actionTimeWithSkillSpeed = time * (1 - sliderValue);

        // Apply 5% faster time if Gatherers is checked and skill qualifies
        var skill = $(this).closest("tr").find("td:first").text().trim();
        if ($("#gatherers-upgrade").is(":checked") && isGatherersSkill(skill)) {
          actionTimeWithSkillSpeed *= 0.95;
        }
        var actionsPerDay = (24 * 3600) / actionTimeWithSkillSpeed;
        var failureChance = 1 - decimalChance;
        var consecutiveFailureChance = Math.pow(failureChance, actionsPerDay);
        var successChance = 1 - consecutiveFailureChance;
        var successPercentage = (successChance * 100).toFixed(2);
        $(this).text(successPercentage + "%");
      });
    }

    // Append slider to the page
    $(".mw-slider-md").append(sliderLabel).append(slider);

    // Append checkbox below slider
    $(".mw-slider-md").append("<br>").append($('<label>').append(gatherersCheckbox).append(" Gatherers Upgrade"));

    // Initial calculation after load
    getTaskTimeWithBoost();
    applyChancePerActionChanges();
    applyChancePerDayChanges();
    applyAverageHoursChanges();

    // Update the table values when the slider or checkbox changes
    $(document).on("change", "#gatherers-upgrade", function () {
      getTaskTimeWithBoost();
      applyChancePerDayChanges();
      applyAverageHoursChanges();
    });

    // Reapply updates after sorting happens
    $(document).on("sortEnd", function () {
        getTaskTimeWithBoost();
        applyChancePerDayChanges();
        applyAverageHoursChanges();
    });

    // Update the table values when the slider is moved
    slider.on("input", function () {
      var sliderValue = $(this).val();
      $("#slider-value").text(sliderValue);

      getTaskTimeWithBoost();
      applyChancePerDayChanges();
      applyAverageHoursChanges();
    });
  });
});