Monster Level Calculator

By Brian Ballsun-Stanton Last update Jul 22, 2009 — Installed 1,308 times. Daily Installs: 6, 7, 4, 6, 6, 15, 9, 9, 2, 1, 13, 5, 2, 11, 6, 3, 11, 2, 11, 5, 18, 5, 1, 5, 6, 5, 1, 1, 17, 8, 4, 4

There are 10 previous versions of this script.

// ==UserScript==
// @name           Monster Level Calculator
// @namespace      http://userscripts.org/scripts/show/51945
// @description    Calculates average speed and moster HP for Maze Defense
// @include        http://apps.new.facebook.com/mazedefense/mymaze.aspx*
// @include        http://apps.facebook.com/mazedefense/mymaze.aspx*
// @require	   http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js
// ==/UserScript==

/* By Brian Ballsun-Stanton. 
	GPL v3 license. See the GPL website for details. 
	Version 0.1
		Initial program made
	Version 0.2
		Added debugging stuff in GM_log for requests:
		http://www.facebook.com/apps/application.php?id=14618023107#/topic.php?uid=14618023107&topic=13432
	Version 0.3 
		Added difficulty warning if present wave is more than 10% above weighted average.
	Version 0.4
		Cleaned up the UI a bit.
	Version 0.4.1
		Adjusted moving average. Now it won't drop on easier mazes. 
	Version 0.5
		Added record of difficulty of last 5 levels played.
*/




$("#app14618023107_attackBorder").bind("mousedown",function (){
	theta = 2/(10+1);
	Yt    = Math.round(calculateDiff()*10000);
	Yt   /= 10000;
	OSt   = GM_getValue("St",Yt);
	St    = Math.round(theta * Yt + (1-theta) * OSt);
	if (St > OSt)
		GM_setValue("St",St);
	
	//0.5 stuff
	diffRec = GM_getValue("diffRec","");
	
	newRec = diffRec.split(", ");
	newDiffRec = ""
	//alert( Math.max(0,newRec.length-5) );
	for ( i = Math.max(0,newRec.length-4); i < newRec.length; i++) {
		//alert(newRec[i]+" "+i);
		newDiffRec += newRec[i]+", ";
	}
	newDiffRec += $("#app14618023107_difficulty").val();
	
	GM_setValue("diffRec",newDiffRec);
		
});

outContainer = "<tr><th class='detached_label'><label style='vertical-align:top;line-height:13.1pt'>Total:<br>Icky:<br>MaxSpeed:<br>Mov Avg:<br>DiffRecord:</label></td><td id='calDet' style='vertical-align:baseline;line-height:13.1pt;padding-top:15px'>&nbsp</td></tr>";
$("#app14618023107_monstersDetails").parent().parent().before(outContainer);


function calculateDiff(){
	totalCount=0;
	icky=0;
	maxSpeed=0;
	hptotal=0;
	speedsum=0;
	speedcount=0;
	
	$(".md_monster_array").each(function(){	
		content = $(this).text();

		content = content.split("\n");
		count = content[0].replace(" × ",'')*1.0;
		hp=content[1]*1.0;
		speed=content[2]*1.0;

		//alert (count +" "+hp+" "+speed);
		totalCount += count;
		icky+=count*Math.pow(hp,1)*speed;
		speedsum += speed;
		hptotal += count*hp;
		speedcount++;
		
		if (speed > maxSpeed)
			maxSpeed = speed;

	});
	
	GM_log('Average Speed:' + (speedsum /  speedcount) + ' TotalHP: ' + hptotal);
	
	origIcky = icky;
	icky = addCommas(icky);
	
	
	ema = GM_getValue("St",origIcky);
	
	
	if (origIcky > ema*1.1) 
		$("#app14618023107_attackBorder > a > div").css("background-color","#ff0000");
	else 
		$("#app14618023107_attackBorder > a > div").css("background-color","#006600");
	
	diffRec = GM_getValue("diffRec","No Record");
	
	out = totalCount+"<br>"+icky	+"<br>"+maxSpeed+"<BR>"+addCommas(ema)+"<BR>"+diffRec;
	
	
	$("#calDet").html(out);


	
	return origIcky;
}

calculateDiff();
$("#app14618023107_difficulty").bind("change", calculateDiff);


function addCommas(number){
	txt = ""+Math.round(number);
	needComma = /([0-9]{3,3})(?:,[0-9]{1,3})*$/gm
	foo = 0;
	isOK = /^([0-9]{1,3},)*([0-9]{1,3})$/gm
	while (!isOK.test(txt)) {
		foo = txt.search(needComma)
		txt = txt.slice(0,foo)+","+txt.slice(foo);
		
	}
	return txt;
}
function avgArray(a){
	y=0;
	for (x in a){
		y += a[x];		
	}
	y/=a.length;
	return y;
}