MediaWiki:Gadget-calc-skillingparty.js
From Idle Clans wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
mw.loader.using(['jquery'], function() { $(document).ready(function() { // 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); } // Task time with boost column function getTaskTimeWithBoost() { $(".modified-time").each(function() { var time = $(this).data("time") / 100; var actionTimeWithSkillSpeed = time * (1 - slider.val() / 100) $(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 actionTimeWithSkillSpeed = time * (1 - slider.val() / 100) 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 actionTimeWithSkillSpeed = time * (1 - slider.val() / 100) 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); // Initial calculation after load applyChancePerActionChanges(); 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(); }); }); });