User:Kiokurashi/common.js

From IdleOn MMO Wiki
Revision as of 00:21, 6 October 2021 by imported>Kiokurashi

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.
function coindisplay(coins) {
    var n = coins;
    var ret = "";
    var imgs = ["4/43/Copper", "4/4e/Silver", "1/1f/Gold", "2/2c/Platinum", "5/53/Dementia", 
    "d/d5/Void_Coin.png/22px-Void", "1/11/Lustre_Coin.png/22px-Lustre", 
    "8/83/Starfire_Coin.png/22px-Starfire", "8/8b/Dreadlo_Coin.png/22px-Dreadlo", 
    "e/e6/Godshard_Coin.png/22px-Godshard"];
    var i = 18;

    do {
        var len = n.length;
        if (len > i) {
            var num = parseInt(n.substring(0, len - i));
            if (num > 0) {
                ret += "<img src=https://static.miraheze.org/idleonwiki/" + imgs[(i/2)] + 
                "_Coin.png>" + num + " ";
            }
            n = n.substring(len - i);
        }
        i -= 2;
    }
    while(i > 0);

    return ret;
}

$(document).ready(function(){
	console.log("UPDATED22");
    $.each($('.skillDiv'), function(){
    	var container = $(this);
    	var x1 = parseFloat($(this).data('x1'));
    	var x2 = parseFloat($(this).data('x2'));
    	var max = parseFloat($(this).data('max'));
    	var func1 = $(this).data('func1');
    	var y1 = parseFloat($(this).data('y1'));
    	var y2 = parseFloat($(this).data('y2'));
    	var func2 = $(this).data('func2');
    	$('.result1', container).text(0);
    	$('.result2', container).text(0);
    	$('.valInput', this).html('(<input id="inField" type="number" min="0" max="'+max+'" placeholder=" Level "/>) ');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		$('.result1', container).text(lavaFunc(func1,inVal,x1,x2));
    		$('.result2', container).text(lavaFunc(func2,inVal,y1,y2));
    	});
    });
    $.each($('.guildBonusDiv'), function(){
    	var container = $(this);
    	var x1 = parseFloat($(this).data('x1'));
    	var x2 = parseFloat($(this).data('x2'));
    	var max = parseFloat($(this).data('max'));
    	var func1 = $(this).data('func');
    	var baseC = parseFloat($(this).data('basec'));
    	var incC = parseFloat($(this).data('incc'));
    	$('.result1', container).text(0);
    	$('.result2', container).text(0);
    	$('.cost', container).text(baseC);
    	$('.valInput', this).html('(<input id="inField" type="number" min="0" max="'+max+'" placeholder=" Level "/>) ');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		$('.result1', container).text(lavaFunc(func1,inVal,x1,x2));
    		$('.result2', container).text(10+inVal);
    		$('.cost', container).text(baseC + inVal*incC);
    		$('.tcost', container).text(getCostTotal(baseC,inVal,incC));
    	});
    });
    $.each($('.boxDiv'), function(){
        var container = $(this);
        var func1 = $(this).data('func1');
        var x1 = $(this).data('x1');
        var x2 = $(this).data('x2');
        var func2 = $(this).data('func2');
        var y1 = $(this).data('y1');
        var y2 = $(this).data('y2');
        var func3 = $(this).data('func3');
        var z1 = $(this).data('z1');
        var z2 = $(this).data('z2');
        $('.result1', container).text(0);
        $('.result2', container).text(0);
        $('.result3', container).text(0);
        $('.valInput', this).html('<input id="inField" type="number" min="0" placeholder=" Level " style="max-width: 100px;"/>');
        $("#inField", this).change(function(){
            var inVal = parseInt($(this).val());
            $('.result1', container).text(Math.max(0,lavaFunc(func1,inVal,x1,x2)));
            $('.result2', container).text(Math.max(0,lavaFunc(func2,inVal-25,y1,y2)));
            $('.result3', container).text(Math.max(0,lavaFunc(func3,inVal-100,z1,z2)));
        });
	});
    $.each($('.stampDiv'), function(){
    	var container = $(this);
    	var x1 = parseFloat($(this).data('x1'));
    	var x2 = parseFloat($(this).data('x2'));
    	var func = $(this).data('func');
    	var i4 = parseFloat($(this).data('i4'));
    	var i6 = parseFloat($(this).data('i6'));
    	var i7 = parseFloat($(this).data('i7'));
    	var i8 = parseFloat($(this).data('i8'));
    	var i9 = parseFloat($(this).data('i9'));
    	$('.resultB', container).text(0);
    	$('.resultC', container).text(0);
    	$('.resultM', container).text(0);
    	$('.valInput', this).html('<input id="inField" type="number" min="0" placeholder=" Level " style="max-width: 100px;"/>');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		var goldCost = i8 * Math.pow(i9 - (inVal / (inVal + 5 * i4)) * 0.25, inVal * (10 / i4));
			var materialCost = i6 * Math.pow(i7, Math.pow(Math.round(inVal / i4) - 1, 0.8));
    		$('.resultB', container).text(lavaFunc(func,inVal,x1,x2));
    		$('.resultC', container).html(coindisplay(Math.floor(goldCost)));
    		if (inVal % i4 == 0){
    			$('.resultM', container).text(Math.floor(materialCost).toLocaleString());
    		} else {
    			$('.resultM', container).text(i4 - (inVal % i4) + " Upgrades left before you need to increase max level.");
    		}
    	});
    });
	$.each($('.prayerDiv'), function(){
    	var container = $(this);
    	var bonus = parseInt($(this).data('bonus'));
    	var curse = parseInt($(this).data('curse'));
    	var multiplier = parseInt($(this).data('mult'));
    	var id = parseInt($(this).data('id'));
    	$('.result1', container).text(bonus);
    	$('.result2', container).text(curse);
    	$('.result3', container).text(0);
    	$('.valInput', this).html('<input id="inField" type="number" min="1" placeholder=" Level " style="max-width: 100px;"/>');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		$('.result1', container).text(bonus + (bonus *(inVal - 1))/10);
    		$('.result2', container).text(curse + (curse *(inVal - 1))/10);
    		$('.result3', container).text(
    			Math.round(multiplier * (1 + (4 + (id/25)) * inVal)).toLocaleString()
    			);
    	});
    });
    $.each($('.gfoodDiv'), function(){
    	var container = $(this);
    	var amount = parseFloat($(this).data('amount'));
    	$('.result', container).text(0);
    	$('.valInput', this).html('<input id="inField" type="number" min="0" placeholder=" Quantity " style="max-width: 100px;"/>');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		$('.result', container).text(goldFoodBonus(amount,inVal));
    	});
    });
    $.each($('.statueDiv'), function(){
    	var container = $(this);
    	var perLv = parseFloat($(this).data('amount'));
    	$('.result1', container).text(0);
    	$('.result2', container).text(0);
    	$('.valInput', this).html('<input id="inField" type="number" min="0" placeholder=" Level " style="max-width: 100px;"/>');
    	$("#inField", this).change(function(){
    		var inVal = parseInt($(this).val());
    		$('.result1', container).text(round(inVal*perLv));
    		$('.result2', container).text(Math.round(Math.pow(inVal,1.17)*Math.pow(1.35,inVal/10)+1) + " Required statues to level this bonus.");
    	});
    });
    $.each($('.cauldDiv'), function(){
    	var cauldCostReduxLvl = 0
    	var bubbleCostBubbleLvl = 0
    	var bubbleCostVialLvl = 0
    	var bubbleBargainLvl = 0
    	var bubbleMultClassLvl = 0
    	var shopBargainBought = 0
    	$('.cauldCostReduxLvlInput', this).html('<input id="inCauldCostReduxLvl" type="number" min="0" placeholder=" Level "/>');
    	$('.bubbleCostBubbleInput', this).html('<input id="inBubbleCostBubbleLvl" type="number" min="0" placeholder=" Level "/>');
    	$('.bubbleCostVialInput', this).html('<input id="inBubbleCostVialLvl" type="number" min="0" placeholder=" Level "/>');
    	$('.bubbleMultClassInput', this).html('<input id="inBubbleMultClassLvl" type="number" min="0" placeholder=" Level "/>');
    	$('.bubbleBargainInput', this).html('<input id="inBubbleBargainLvl" type="number" min="0" placeholder=" Level "/>');
    	$('.shopBargainInput', this).html('<input id="inShopBargainBought" type="number" min="0" placeholder=" Level "/>');
    	$("#inCauldCostReduxLvl", this).change(function(){
    		cauldCostReduxLvl = parseInt($(this).val());
    	});
    	$("#inBubbleCostBubbleLvl", this).change(function(){
    		bubbleCostBubbleLvl = parseInt($(this).val());
    	});
    	$("#inBubbleCostVialLvl", this).change(function(){
    		bubbleCostVialLvl = parseInt($(this).val());
    	});
    	$("#inBubbleBargainLvl", this).change(function(){
    		bubbleBargainLvl = parseInt($(this).val());
    	});
    	$("#inBubbleMultClassLvl", this).change(function(){
    		bubbleMultClassLvl = parseInt($(this).val());
    	});
    	$("#inShopBargainBought", this).change(function(){
    		shopBargainBought = parseInt($(this).val());
    	});
    	$.each($('.bubbleDiv'), function(){
    		var container = $(this);
    		var baseCost = $(this).data('basecost').split(',')
    		var isLiquid = $(this).data('isliquid').split(',')
    		var x1 = parseFloat($(this).data('x1'));
    		var x2 = parseFloat($(this).data('x2'));
    		var func = $(this).data('func');
    		$('.valInput', this).html('<input id="inField" type="number" min="0" placeholder=" Level "/>');
    		for(i=0;i<baseCost.length;i++){
				var div = '.material' +(i+1);
				$(div, container).text(0);
			}
			$(".bonusOut", container).text(0);
    		$("#inField", this).change(function(){
    			var inVal = parseInt($(this).val());
				for(i=0;i<baseCost.length;i++){
					var div = '.material' +(i+1);
					var cost = calcBubbleMatCost(
						inVal, 
						parseInt(baseCost[i]),
						isLiquid[i], 
						cauldCostReduxLvl, 
						bubbleCostBubbleLvl, 
						bubbleCostVialLvl, 
						bubbleBargainLvl, 
						bubbleMultClassLvl, 
						shopBargainBought
						);
						
					$(div, container).html('<div class="tooltip"> ' + nFormatter(cost,2) + '<span>' + cost + '</span></div>')
				}
				$(".bonusOut", container).text(round(lavaFunc(func,inVal,x1,x2)))
    		});	
    	});
    });
});