Blizzard to Wowhead Converter – Pets

I dont know if you remember but a while back i wote a php function that will turn blizzards talent builds into wowhead links (link). Well since then blizzard has added hunter pets to the armory, and along with them come their build. So we now need a way to convert that to a wowhead link. Well iv got another function for you.

Enjoy it after the break :)

Again let me know what you think and if there are any problems.

function b2wpet($family, $build, $return_as_url = true)
{
	// the encryption code
	$encrypt = '0zMcmVokRsaqbdrfwihuGINALpTjnyxtgevElBCDFHJKOPQSUWXYZ123456789';
 
	// familyId => name
	$families = array(1=>'wolf',2=>'cat',3=>'spider',4=>'bear',5=>'boar',6=>'crocolisk',7=>'carrionbird',8=>'crab',9=>'gorilla',11=>'raptor',12=>'tallstrider',20=>'scorpid',21=>'turtle',24=>'bat',25=>'hyena',26=>'birdofprey',27=>'windserpent',30=>'dragonhawk',31=>'ravager',32=>'warpstalker',33=>'sporebat',34=>'netherray',35=>'serpent',37=>'moth',38=>'chimaera',39=>'devilsaur',41=>'silithid',42=>'worm',43=>'rhino',44=>'wasp',45=>'corehound',46=>'spiritbeast');
 
	// convert family name to a id
	for ($i = 0; $i < count($families); $i++)
		if (strtolower($family) == $families[$i])
			$family = $i;
 
	// check if its a BM build - should this be put in the function call?
	$bm = (array_sum(str_split($build, '1')) > 16)? true: false;
 
	// start the return with the
	$return = $encrypt[floor($family / 10)].$encrypt[(2*($family % 10)) + ($bm ? 1 : 0) ];
 
	// encode the tree
	for ($i=0; $i<strlen ($build); $i++)
	{
		$tens = intval($build[$i]);
		$ones = (++$i == strlen($build))? 0: intval($build[$i]);
		$return .= $encrypt[$tens*6 + $ones];
	}
 
	if ($return_as_url == true)
		return 'http://wowhead.com/?petcalc#'.$return;
	else
		return $return;
}

This entry was posted in Scripting and tagged , , , . Bookmark the permalink.

3 Responses to Blizzard to Wowhead Converter – Pets

  1. Zardoz says:

    Oh well done!

  2. Zardoz says:

    BTW, any idea where they got this algorithm from? Why wouldn’t they just do base64 or some, like y’know, *standard* thing?

  3. Gizzmo says:

    Well i found a old topic on Wowhead forums, that helped me create/convert the code. (cant remember the url) I also took the compressed JS code from the page, uncompreessed it and did my best to decipher the code to help out a bit.
    I dont know why they created their own algorithm

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">