User:Electricsheep/common.js

From Blue Archive Wiki
Jump to navigation Jump to search

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.
var stats = {};
var tableCounter = 0;
var rarity_bonus = {
	"attack"	: [0, 0, 1000,	2200, 3600, 5300 ],
	"defense"	: [0, 0, 0,		0,    0, 	0 	 ],
	"healing"	: [0, 0, 750, 	1750, 2950, 4450 ],
	"hp"		: [0, 0, 500, 	1200, 2100, 3500 ]
};

	
$( document ).ready(function() {
    console.log( "ready!" );
	statTableInit();
	
	$(".stattable-controls input").on("change, mouseup, keyup", function(){statTableRecalc($(this).closest("table").attr('id'));});
});
	
function statTableInit(){
	
	$(".character-stattable").each(function(){
		$(this).attr('id','statTable-'+(++tableCounter));
		var id = $(this).attr('id');
		console.log('iterating table id ' + id);
		
		var attack_data = $(this).find(".stat-attack").html().split('/');
		var defense_data = $(this).find(".stat-defense").html().split('/');
		var hp_data = $(this).find(".stat-hp").html().split('/');
		var healing_data = $(this).find(".stat-healing").html().split('/');
		
		stats[id] = {};
		stats[id].attack_min	= parseInt(attack_data[0]) > 0 ? parseInt(attack_data[0]) : null;
		stats[id].attack_max	= parseInt(attack_data[1]) > 0 ? parseInt(attack_data[1]) : null;
		stats[id].defense_min	= parseInt(defense_data[0]) > 0 ? parseInt(defense_data[0]) : null;
		stats[id].defense_max	= parseInt(defense_data[1]) > 0 ? parseInt(defense_data[1]) : null;
		stats[id].hp_min		= parseInt(hp_data[0]) > 0 ? parseInt(hp_data[0]) : null;
		stats[id].hp_max		= parseInt(hp_data[1]) > 0 ? parseInt(hp_data[1]) : null;
		stats[id].healing_min	= parseInt(healing_data[0]) > 0 ? parseInt(healing_data[0]) : null;
		stats[id].healing_max	= parseInt(healing_data[1]) > 0 ? parseInt(healing_data[1]) : null;
		
		//stats[$(this).attr('id')] = JSON.parse($(this).attr('stat-data'));
		if (!hasNull(stats[id])) 
		{
			statTableRecalc(id);
			
			$(this).find(".stattable-controls td").append('Rarity <input class="stattable-rarity" type="number" value="3" step="1" min="1" max="5" />;Level <input class="stattable-level" type="number" value="73" step="1" min="1" max="100" />'); 
			
			$(this).find(".stattable-controls").css( "display", "" );	
		}

	});
}
	

	
function statTableRecalc(id){
	console.log(id+' recalc called');
	var statTable = $('#'+id);
	var level = statTable.find(".stattable-level").val();
	var rarity = statTable.find(".stattable-rarity").val();
	
	statTable.find(".stat-attack").html(calcStat(	level, rarity, 'attack', 	stats[id].attack_min, stats[id].attack_max));
	statTable.find(".stat-defense").html(calcStat(	level, rarity, 'defense', 	stats[id].defense_min, stats[id].defense_max));
	statTable.find(".stat-hp").html(calcStat(		level, rarity, 'hp', 		stats[id].hp_min, stats[id].hp_max));
	statTable.find(".stat-healing").html(calcStat(	level, rarity, 'healing', 	stats[id].healing_min, stats[id].healing_max));
}
	
function calcStat(level,rarity,statName,val1,val100){
	return Math.ceil( (val1 + (val100 - val1) * (level - 1) / 99) * (10000 + rarity_bonus[statName][rarity]) / 10000 );
}
	
function hasNull(target) {
    for (var member in target) {
        if (target[member] == null)
            return true;
    }
    return false;
}