User:Electricsheep/common.js: Difference between revisions

From Blue Archive Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
No edit summary
Line 43: Line 43:
}
}
function generateId(prefix = '') {
function generateId(prefix) {
return prefix+Math.round((Math.random() * 100000));
return prefix+Math.round((Math.random() * 100000));
}
}

Revision as of 07:53, 11 September 2021

var stats = {};
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").attr('id',generateId('statTable-'));
	
	$(".character-stattable").each(function(){
		console.log('iterating tables');
		stats[$(this).attr('id')] = JSON.parse($(this).attr('stat-data'));
		
		statTableRecalc($(this).attr('id'));
		$(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 generateId(prefix) {
  return prefix+Math.round((Math.random() * 100000));
}