MediaWiki:Common.js/StatusEffects.js

/*

Status Effect buttons for Statistics section tables
by King Dragonhoff

Maintenance This file should only need to be updated if the amount that an effect modifies a stat by is changed or an effect applies to new attributes of cards. The names of the attributes in the tables must remain the same. // *********** Functions *********** // Rage Effect Math Function for increases in the stat (non-time) function rageEffectUp(originalValue) { // Factor is 135 since Rage boosts by 35% return String(Math.floor(roundNum(1,Number(originalValue) * (135/100)))); } // Rage Effect Math Function for decreases in the stat (time) /*  Value is converted to milliseconds for calculation then back to seconds for output */ function rageEffectDown(originalValue) { // Factor is 65 since Rage decreases by 35% return String(Math.floor(roundNum(1,(Number(originalValue) * 1000) * (65/100))) / 1000); } // Slow Effect Math Function for decreases in the stat (non-time) function slowEffectDown(originalValue) { // Factor is 65 since Slow decreases by 35% return String(Math.floor(roundNum(1,Number(originalValue) * (65/100)))); } // Slow Effect Math Function for increases in the stat (time) /*  Value is converted to milliseconds for calculation then back to seconds for output */ function slowEffectUp(originalValue) { // Factor is 135 since Slow increases by 35% return String(Math.floor(roundNum(1,(Number(originalValue) * 1000) * (135/100))) / 1000); } // ********** Get Started ********** $(document).ready(function {   var movementSpeedName, unitAttributeValues = [], unitDPSValues = [];    $("#slowEffectButton").click(function { $(this).toggleClass("slowEffectButtonActive"); });   $("#rageEffectButton").click(function { $(this).toggleClass("rageEffectButtonActive"); });   // When a button is clicked...    $("#rageEffectButton, #slowEffectButton").click(function { // Toggle the effects on the statistics var unitAttributesTableR1 = $("#unit-attributes-table tr:eq(1)"); var attributeName, statName, b, c, d;       if ($("#rageEffectButton").hasClass("rageEffectButtonActive") && $("#slowEffectButton").hasClass("slowEffectButtonActive") === false) { // Apply rage effect and color the text affected after saving initial values $('#unit-attributes-table tr:eq(0) th').each(function(b) {               attributeName = $(this).clone.children.remove.end.text.trim.toLowerCase;                if (attributeName === "speed") {                    movementSpeedName = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[0-9]/g, "").trim; // Save movement speed name ("Slow", "Medium", etc.) so that it can be put back when the rage button is inactivated                    unitAttributeValues[0] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim;                    $('td:eq(' + b + ')', unitAttributesTableR1).text(rageEffectUp(unitAttributeValues[0])).addClass("EnragedStat").removeClass("SlowedStat");                } else if (attributeName === "hit speed") {                    unitAttributeValues[1] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(rageEffectDown(unitAttributeValues[1]) + " sec").addClass("EnragedStat").removeClass("SlowedStat"); } else if (attributeName === "spawn speed") { unitAttributeValues[2] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(rageEffectDown(unitAttributeValues[2]) + " sec").addClass("EnragedStat").removeClass("SlowedStat"); } else if (attributeName === "production speed") { unitAttributeValues[3] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(rageEffectDown(unitAttributeValues[3]) + " sec").addClass("EnragedStat").removeClass("SlowedStat"); }           });            // Damage per second            $('#unit-statistics-table tr:eq(0) th').each(function(c) { statName = $(this).clone.children.remove.end.text.trim.toLowerCase; if (statName === "damage per second") { $('#unit-statistics-table tr').each(function(d) {                       // Save                        unitDPSValues.push($('td:eq(' + c + ')', this).text.replace(/[^0-9.,]/g, "").trim);                        // Enrage                        $('td:eq(' + c + ')', this).text(rageEffectUp(unitDPSValues[d])).addClass("EnragedStat").removeClass("SlowedStat");                    }); return false; // End loop since DPS is the only stat that we need }           });        } else if ($("#rageEffectButton").hasClass("rageEffectButtonActive") === false && $("#slowEffectButton").hasClass("slowEffectButtonActive")) {            // Apply slow effect and color the text affected after saving initial values            $('#unit-attributes-table tr:eq(0) th').each(function(b) { attributeName = $(this).clone.children.remove.end.text.trim.toLowerCase; if (attributeName === "speed") { movementSpeedName = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[0-9]/g, "").trim; // Save movement speed name ("Slow", "Medium", etc.) so that it can be put back when the slow button is inactivated unitAttributeValues[0] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(slowEffectDown(unitAttributeValues[0])).removeClass("EnragedStat").addClass("SlowedStat"); } else if (attributeName === "hit speed") { unitAttributeValues[1] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(slowEffectUp(unitAttributeValues[1]) + " sec").removeClass("EnragedStat").addClass("SlowedStat"); } else if (attributeName === "spawn speed") { unitAttributeValues[2] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(slowEffectUp(unitAttributeValues[2]) + " sec").removeClass("EnragedStat").addClass("SlowedStat"); } else if (attributeName === "production speed") { unitAttributeValues[3] = $('td:eq(' + b + ')', unitAttributesTableR1).text.replace(/[^0-9.,]/g, "").trim; $('td:eq(' + b + ')', unitAttributesTableR1).text(slowEffectUp(unitAttributeValues[3]) + " sec").removeClass("EnragedStat").addClass("SlowedStat"); }           });            // Damage per second            $('#unit-statistics-table tr:eq(0) th').each(function(c) { statName = $(this).clone.children.remove.end.text.trim.toLowerCase; if (statName === "damage per second") { $('#unit-statistics-table tr').each(function(d) {                       // Save                        unitDPSValues.push($('td:eq(' + c + ')', this).text.replace(/[^0-9.,]/g, "").trim);                        // Slow                        $('td:eq(' + c + ')', this).text(slowEffectDown(unitDPSValues[d])).removeClass("EnragedStat").addClass("SlowedStat");                    }); return false; // End loop since DPS is the only stat that we need }           });        } else { // Both buttons on or both buttons off since they cancel out            // Remove effects and remove the color from the text affected            $('#unit-attributes-table tr:eq(0) th').each(function(b) { attributeName = $(this).clone.children.remove.end.text.trim.toLowerCase; if (attributeName === "speed") { $('td:eq(' + b + ')', unitAttributesTableR1).text(movementSpeedName + " (" + unitAttributeValues[0] + ")").removeClass("EnragedStat").removeClass("SlowedStat"); } else if (attributeName === "hit speed") { $('td:eq(' + b + ')', unitAttributesTableR1).text(unitAttributeValues[1] + " sec").removeClass("EnragedStat").removeClass("SlowedStat"); } else if (attributeName === "spawn speed") { $('td:eq(' + b + ')', unitAttributesTableR1).text(unitAttributeValues[2] + " sec").removeClass("EnragedStat").removeClass("SlowedStat"); } else if (attributeName === "production speed") { $('td:eq(' + b + ')', unitAttributesTableR1).text(unitAttributeValues[3] + " sec").removeClass("EnragedStat").removeClass("SlowedStat"); }           });            // Damage per second            $('#unit-statistics-table tr:eq(0) th').each(function(c) { statName = $(this).clone.children.remove.end.text.trim.toLowerCase; if (statName === "damage per second") { $('#unit-statistics-table tr').each(function(d) {                       $('td:eq(' + c + ')', this).text(unitDPSValues[d]).removeClass("EnragedStat").removeClass("SlowedStat");                    }); return false; // End loop since DPS is the only stat that we need }           });        }    }); });