Facebook Mafia Wars Exp Remaining

By ThatOneGuy Last update Apr 24, 2010 — Installed 57,542 times.

enhancement suggestion - calculate total price of missing inventory to start a job

in
Subscribe to enhancement suggestion - calculate total price of missing inventory to start a job 13 posts, 5 voices



owiec User
OperaWindows

I always have to click each missing item and calculate in mind the needed cash in Moscow to find out how much cash i need to start a new job. So here's what I did. Maybe you could add such a feature in official version :)

I use couple of my modifications, so it would be hard to post a patch here, so I'll try to describe it.
In function GM_MW_DoCalcExp(searchNode) in the loop where the cells of a single job are iterated :

var elCells = elRows[r].getElementsByTagName("td");
               for(var c=0; c<elCells.length; c++) ...

After the block if(elCells[c].className == "job_reward" && ElementCheck(elCells[c],'job reward'))I've added one more condition:
//calculating a total price of missing items to finish job
else if (elCells[c].className == "job_required_items" && ElementCheck(elCells[c],"job_required_items")) 
{
	//the price and number of needed stuff can be found in onclick event handler in function create_buy_item_lbox
	var icons = elCells[c].getElementsByTagName("a"); 
	var suma =0;
	var price = 0, number = 0;
	var regexp = /.*create_buy_item_lbox\(\".*\", *\".*\", *(\d+), *\d+, *(\d+)\).*/
	for(var i=0; i<icons.length; i++)
	{
		if (icons[i].getAttribute("onclick").match(regexp) == null)
			continue;
		price = parseInt(RegExp.$1);
		number = parseInt(RegExp.$2);
		if (!isNaN(price) && !isNaN(number)) {
			suma += price * number;
		}
	}
	if (suma != 0 ){ //adding commas
		suma = suma.toString();
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(suma)) {
			suma = suma.replace(rgx, '$1' + ',' + '$2');
		}
		elCells[c].innerHTML += '<br /><div>'+suma+'</div>'
	}
}

It was only tested in Moscow and probably will need some fine-tuning

 
epicenter69 User
FirefoxWindows

Good idea owiec!

 
ThatOneGuy Script's Author
FirefoxWindows

Added.

It took me so long because the first time I tried it I couldn't get it to work but I figured out what I was missing.

Thanks for your contribution. :)
-T1G

 
epicenter69 User
FirefoxWindows

I like that it shows the cost of the items that are still red, but what does the smaller number under the experience ratio mean?

 
ThatOneGuy Script's Author
FirefoxWindows

That was from another thread, that's the money/energy ratio for the job by Erinol

http://userscripts.org/topics/39796

 
owiec User
OperaWindows

First of all, great job with all this, respect T1G :)
And the second, I find another thing pretty useful - making ratios colorful :) Helps to make a decision which job is more valuable at the moment. Also exp ratio precision could be widen a bit. In Moscow, most of the jobs' exp ratios are ~1.8 but they're not always the same.
The snip below paints ratios form red, which is lowest ratio to green which is the highest.

In function: function GM_MW_DoCalcExp(searchNode) ,
in the block: if (moneyGain != -1 && expGain != -1 && energyNeed != -1 && editContainer != null && foundRequiredItems)
replace it with:

if (moneyGain != -1 && expGain != -1 && energyNeed != -1 && editContainer != null && foundRequiredItems)

{
	var cashRatio = cashGain / energyNeed;
	var ratio = expGain / energyNeed;
	var hrElement = document.createElement('br');
	var ratioElement = document.createElement('span');
	var cashRatioElement = document.createElement('span');
	ratioElement.textContent = ratio.toFixed(3);
	ratioElement.style.color = "black";
	ratioElement.style.align = "center";
	cashRatioElement.textContent = "$"+cashRatio.toFixed(0);
	//configurables:
	var colorMin = 1.7; // lowest exp ratio painted in red
	var colorMax = 2.1; //higest exp ratio - painted in green
	var cashColorMin = 2000; // see exp ratio
	var cashColorMax = 5000; // see exp ratio
	if (ratio < colorMin) {
		ratioElement.style.backgroundColor = "red";
	} else if ( ratio >= colorMin && ratio <= colorMax ) {
		var color = ((ratio - colorMin)/(colorMax-colorMin))*255;
		colorRGB = "rgb(" + (255 - color).toFixed(0) + ',' + color.toFixed(0) + ",0)";		
		ratioElement.style.backgroundColor = colorRGB;
	} else {
		ratioElement.style.backgroundColor = "green";
	}
	if (cashRatio < cashColorMin) {
		cashRatioElement.style.backgroundColor = "red";
	} else if ( cashRatio >= cashColorMin && cashRatio <= cashColorMax ) {
		var color = ((cashRatio - cashColorMin)/(cashColorMax-cashColorMin))*255;
		colorRGB = "rgb(" + (255 - color).toFixed(0) + ',' + color.toFixed(0) + ",0)";		
		cashRatioElement.style.backgroundColor = colorRGB;
	} else {
		cashRatioElement.style.backgroundColor = "green";
	}
	editContainer.appendChild(hrElement);
	editContainer.appendChild(ratioElement);
	editContainer.appendChild(hrElement);
	editContainer.appendChild(cashRatioElement);
	editContainer = null; //not to add ratios any more
}

Like in previous case, it's kind of POC (although, works for me). Try it, it and if you like, feel free to make use of it.
Cheers

 
ThatOneGuy Script's Author
FirefoxWindows

owiec,

Tell you what: pick different colors (10% of the male population is colorblind, most of which are red/green, including yours truly) and I'll add it to the code :)

Thanks,
-T1G

 
michmela44 Scriptwright
FirefoxWindows
I agree with the Ratio change. After every update, I go into my script and change all of the 100s to 10000s.

elExp[h].innerHTML = "Exp (" + ((neededExp - curExp) * -1) + ") [" + Math.round(10000 * (neededExp - curExp) / userEnergy) / 10000 + "]
+Full [" + Math.round(10000 * (neededExp - curExp) / (userEnergy + userMaxEnergy)) / 10000 + "] +E-Pack [" + Math.round(10000 * (neededExp - curExp) / (userEnergy + (userMaxEnergy * 1.25))) / 10000 + "]";


After level 300 or so, it takes forever for the Ratio to change. Sometimes my ratio would show 2.11, but the Settle a Beef job would not level me up.

It was nice to find out that my ratio was actually 2.1157 and the Settle a Beef job is only 2.1143.

Doesn't sound like much, but at 3000 energy, .007 is 21 energy points, which could leave you waiting up to 2 hours to level up.



Also, I take the 100s off of the Money calculation since I'm not worried about fractions of a dollar and it makes it look cleaner.

var moneyResult = "" + Math.round(moneyGain / energyNeed);
 
ThatOneGuy Script's Author
FirefoxWindows

You will now find the following options to make updating a bit easier for you guys:

var showHealInNYOnly = false;
var EnergyDecimalPlaces = 3;
var PropertyROIDecimalPlaces = 1;
var JobMoneyDecimalPlaces = 1;

-T1G

 
ThatOneGuy Script's Author
FirefoxWindows

Ok, color has been implemented, with an option to turn it off. In the future I'll try to remember to turn it back on, but I may forget.

Somewhere on the "todo" list is to create an options screen and save the options off, not sure when I'll have time to get to that though.

Enjoy guys, thanks again for everybody's help.
-T1G

 
owiec User
FirefoxWindows

T1G,
I've learned a lesson from you :)
I did a couple tries with different colors, but they didn't do the magic :) or maybe I already got used to old colors.
So, probably the best option is to leave a possibility to use colors or not.

 
owiec User
FirefoxWindows

Hi,
I've updated the part which counts money for required items, as well as ratios for Triad/Yakuza jobs in Bangkok:
line 462:

if((elCells[c].className == "job_reward" || elCells[c].className == "job_reward job_no_border")  && ElementCheck(elCells[c],'job reward'))

else if block at line 488:
else if ((elCells[c].className == "job_required_items" || elCells[c].className =="job_required_items job_no_border") && ElementCheck(elCells[c],'job required items'))
{
  //calculating a total price of missing items to finish job -- By owiec
  foundRequiredItems = true;
  // the total price taken from div with id "popup_inner_text". There are multiple divs with this id, so it's necessary to iterate over the set of divs inside the table cell
  var icons = elCells[c].getElementsByTagName("div"); 
  var suma =0;
  var price = 0, number = 0;
  //var regexp = /.*create_buy_item_lbox\(\".*\", *\".*\", *(\d+), *\d+, *(\d+)\).*/
  var regexp = /.*Buy.*for.*\$([0-9,]+).*/
  for (var i = 0; i<icons.length; i++)
  {
    if ("popup_inner_text"==icons[i].getAttribute("id"))
    {
      GM_log(icons[i].innerHTML);
      if (icons[i].innerHTML.match(regexp) == null)
        continue;
      price = parseInt(RegExp.$1.replace(",", ""));
      GM_log(RegExp.$1);
      if (!isNaN(price))
      suma += price;
    }
  }
  GM_log(suma);
  if (suma != 0 ){ //adding commas
    suma = suma.toString();
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(suma)) {
      suma = suma.replace(rgx, '$1' + ',' + '$2');
    }
    elCells[c].innerHTML += '<br /><div>['+suma+']</div>'
  }
}		

line 522:
else if ((elCells[c].className == "job_energy" || elCells[c].className == "job_energy job_no_border") && ElementCheck(elCells[c],'job energy'))

 
Buzzthebuzzsaw User
FirefoxWindows

Can I request a small addition to the quick links.
I've put the following line in at 348 to make a quick link to the Robbing page.

     elLinksDivs[p].innerHTML += ' ' + getLinkCode('R', null, myMafiaStyle, 'robbing', 'view');

It can be put anywhere in that section but it's handy to go straight to the Robbing page.

Cool script, can't even begin to estimate the amount of time it's saved me!
Keep up the good work!

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel