Source of /kol/kolfamiliars.php


<?
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__)
    
$allowviewsource=1;
include (
"../common.php");

page_header('KoL Familiar Tool');

#$proxy = "http://127.0.0.1:8080/";
$proxy = "";

function
gethousefams()
{
    global
$proxy;
    
$a = file_get_contents("${proxy}http://noblesse-oblige.org/calendar/calendar_day.js");
    if (!
$a)
        return
FALSE;
    if (!
preg_match("/nowday\\s*=\\s*(\\d+)/", $a, $x))
        return
FALSE;
    
$day = $x[1];
    if (
$day 10) $day = "0$day";
    if (!
preg_match("/nowmonth\\s*=\\s*(\\d+)/", $a, $x))
        return
FALSE;
    
$month = $x[1];
    if (
$month 10) $month = "0$month";
    if (!
preg_match("/nowyear\\s*=\\s*(\\d+)/", $a, $x))
        return
FALSE;
    
$year = $x[1];
    
    
$fp = fopen("cache.txt", "r");
    if (
$fp && ($line = fgets($fp)) && trim($line) == "$year$month$day")
    {
        
$fams = array();
        while (
$line = fgets($fp))
        {
            if (
preg_match("/(\\d+):(.*)/", $line, $x))
                
$fams[] = array('name' => $x[2], 'weight' => $x[1]);
        }
        if (
$fp) fclose($fp);
        return
$fams;
    }
    else
    {
        if (
$fp) fclose($fp);
        
$a = file_get_contents("${proxy}http://noblesse-oblige.org/calendar/daily_$year$month$day.html");
        if (!
preg_match("{<h3>Arena</h3>(.*?)<h3>}s", $a, $x))
            return
FALSE;
        
$lines = split("<br>", $x[1]);
        
$fams = array();
        foreach (
$lines as $line)
            if (
preg_match("/(\\d+)-pound (.*)/", $line, $x))
                
$fams[] = array('name' => $x[2], 'weight' => $x[1]);
        
$fp = fopen("cache.txt","w");
        if (
$fp)
        {
            
fwrite($fp, "$year$month$day\n");
            foreach (
$fams as $i)
                
fwrite($fp, "$i[weight]:$i[name]\n");
            
fclose($fp);
        }
        return
$fams;
    }
}

//[0] = Ultimate Cage Match
//[1] = Scavenger Hunt
//[2] = Obstacle Course
//[3] = Hide and Seek

$allfamiliars = array(
    array(
3,3,3,3, 'name' => 'Unknown', 'weight' => 1000),
    array(
3,0,2,1, 'name' => 'Angry Goat'),
    array(
3,0,2,3, 'name' => 'Astral Badger'),
    array(
1,1,3,2, 'name' => 'Attention-Deficit Demon'),
    array(
0,3,1,2, 'name' => 'Baby Gravy Fairy'),
    array(
3,1,1,2, 'name' => 'Baby Yeti'),
    array(
0,2,1,3, 'name' => 'Barrrnacle'),
    array(
0,1,3,2, 'name' => 'Blood-Faced Volleyball'),
    array(
1,2,3,1, 'name' => 'Cheshire Bat'),
    array(
3,2,0,1, 'name' => 'Clockwork Grapefruit'),
    array(
2,3,0,1, 'name' => 'Cocoabo'),
    array(
1,1,3,2, 'name' => 'Coffee Pixie'),
    array(
0,0,0,2, 'name' => 'Comma Chameleon'),
    array(
1,2,1,3, 'name' => 'Crimbo Elf'),
    array(
1,2,3,1, 'name' => 'Cymbal-Playing Monkey'),
    array(
3,3,3,3, 'name' => 'Doppelshifter'),
    array(
1,3,1,2, 'name' => 'Emo Squid'),
    array(
2,3,1,1, 'name' => 'Feather Boa Constrictor'),
    array(
2,3,1,2, 'name' => 'Flaming Gravy Fairy'),
    array(
2,3,1,2, 'name' => 'Frozen Gravy Fairy'),
    array(
2,2,2,2, 'name' => 'Fuzzy Dice'),
    array(
3,1,0,2, 'name' => 'Ghost Pickle on a Stick'),
    array(
1,2,0,3, 'name' => 'Ghuol Whelp'),
    array(
2,0,1,3, 'name' => 'Grue'),
    array(
3,2,1,1, 'name' => 'Hand Turkey'),
    array(
2,1,3,1, 'name' => 'Hanukkimbo Dreidl'),
    array(
0,3,2,1, 'name' => 'Hovering Sombrero'),
    array(
1,3,2,0, 'name' => 'Howling Balloon Monkey'),
    array(
3,2,2,1, 'name' => 'Inflatable Dodecapede'),
    array(
3,1,2,1, 'name' => 'Jill-O-Lantern'),
    array(
3,1,2,0, 'name' => 'Killer Bee'),
    array(
1,3,0,2, 'name' => 'Leprechaun'),
    array(
0,1,2,3, 'name' => 'Levitating Potato'),
    array(
3,0,1,2, 'name' => 'MagiMechTech MicroMechaMech'),
    array(
3,2,1,2, 'name' => 'Misshapen Animal Skeleton'),
    array(
2,1,3,0, 'name' => 'Mosquito'),
    array(
2,1,3,1, 'name' => 'Personal Raincloud'),
    array(
1,3,1,2, 'name' => 'Pygmy Bugbear Shaman'),
    array(
3,0,2,1, 'name' => 'Sabre-Toothed Lime'),
    array(
2,1,3,0, 'name' => 'Spirit Hobo'),
    array(
2,3,1,0, 'name' => 'Spooky Pirate Skeleton'),
    array(
3,2,1,0, 'name' => 'Stab Bat'),
    array(
2,1,3,0, 'name' => 'Star Starfish'),
    array(
2,3,1,2, 'name' => 'Stinky Gravy Fairy'),
    array(
2,3,1,2, 'name' => 'Sweet Nutcracker'),
    array(
1,3,1,2, 'name' => 'Temporal Riftlet'),
    array(
3,1,2,0, 'name' => 'Whirling Maple Leaf'),
    array(
1,3,2,0, 'name' => 'Wild Hare'),
    array(
3,0,2,1, 'name' => 'Wind-Up Chattering Teeth'),
);

function
printfamops($select = "Unknown")
{
    global
$allfamiliars;
    foreach (
$allfamiliars as $k=>$v)
    {
        echo
"<option value=\"$k\"";
        if (
$v['name'] == $select)
            echo
" selected=\"selected\"";
        echo
">{$v['name']}</option>\n";
    }
}

function
printresults ($self, $opp1, $opp2, $opp3, $opp4, $opp5)
{
    echo
"<p>You are using a {$self['name']}.</p>\n";
    
    
$combat = array('Ultimate Cage Match','Scavenger Hunt','Obstacle Course','Hide and Seek');
    
    for (
$i = 1$i <= 5$i++)
    {
        for(
$j = 0$j 4$j++)
        {
            if(${
"opp" . $i}[$j] == 0)
            {
                
$x = 1;
                
$power = 5;
                if(${
"opp" . $i}['weight'] == 1000)
                    
$power = 1000;
            }
            else
            {
                
$x = 0;
                
$power = ${"opp" . $i}['weight'] + ${"opp" . $i}[$j]*3;
            }
            
$beat = ($power + 3) - 3*$self[$j];
            if(
$self[$j] != 0)
                
$weights[$beat] = "{$combat[$j]} versus {${'opp' . $i}['name']} ({${'opp' . $i}['weight']} pound)";
        }
    }
    
ksort($weights);
    echo
"<ul>\n";
    foreach (
$weights as $w=>$v)
        if (
$w 0)
            echo
"<li>At weight $w, do $v.</li>\n";
        else
            echo
"<li>At earlier weights, do $v.</li>\n";
    echo
"</ul>\n";
    
    echo
"<p><a href=\"$_SERVER[PHP_SELF]\">Back</a></p>\n";
}



function
get_familiar ($var, $weight)
{
    global
$allfamiliars;
    if (isset(
$allfamiliars[$var]))
    {
        
$tmp = array('weight' => $weight);
        foreach (
$allfamiliars[$var] as $k=>$v) $tmp[$k] = $v;
        return
$tmp;
    }
    else
        return
$allfamiliars[0];
}

function
get_opponent($var) {
    global
$allfamiliars;
    
$index = 1;
    
    for(
$i = 1$i <= count($allfamiliars); $i++)
        {
        
$temp = $_REQUEST["w$i"];
        if(
$temp != '')
            {
            if(
$index == $var)
                return
get_familiar($i, $temp);
            else
                
$index = $index + 1;
            }
        }
    
    return
$allfamiliars[0];
}

if (!isset(
$_REQUEST['class']) || $_REQUEST['class'] == 0)
{
?>
<p>Kingdom of Loathing Familiar Tool by Xylpher (#540421), originally at <a href="http://www.few.vu.nl/~rminne/kol/kolfamiliars.php">http://www.few.vu.nl/~rminne/kol/kolfamiliars.php</a>.</p>
<p>Choose your own familiar from the list, make sure the other boxes match what you see in the Arena.</p>
<p>Thanks to <a href="http://www.the-rye.dreamhosters.com/familiars/">http://www.the-rye.dreamhosters.com/familiars/</a>
for the already excellent familiar tool available there, which I used to get my info from.</p>
<p>I can not be held responsible for any loss or personal injury incurred by use of this tool.</p>
<p>For all the people who are nagging me for the source: Fine. <a href="kolfamiliars.php?viewsource=yep">Here it is</a>. I suppose it's okay if you wish to put it up on your site or use the source to put into your own tool, just don't forget to credit me.</p>
<p>Note that this tool will not yield 100% perfect results. I thought every battle would have a weight at which you would get 5 XP when I started building this, but it seems they don't. So there might be occurences of losing or getting 4 or even 3 XP. They should be sporadic though.</p>
<p>Modified by Phlip (#509981) to pull the information on the current house familiars from Noblesse Oblige's <a href="http://noblesse-oblige.org/calendar/">Kingdom Calendar</a> of awesomeness.</p>

<?
    
if (isset($_REQUEST['class']))
        echo
"<p class=\"error\">Please, choose a familiar...</p>\n";
    echo
"<form method=\"GET\" action=\"$_SERVER[PHP_SELF]\"><p>\n";
    echo
"You are using a: <select name=\"class\">\n";
    
printfamops();
    echo
"</select><br>\n";
    
$housefams = gethousefams();
    for(
$i = 1$i <= 5$i++)
    {
        echo
"Opponent {$i}: ";
        echo
"<select name=\"opp{$i}\">";
        if (
$housefams && $housefams[$i - 1])
            
printfamops($housefams[$i - 1]['name']);
        else
            
printfamops();
        echo
'</select>';
        echo
"<input type=\"text\" maxlength=2 size=1 name=\"w{$i}\"";
        if (
$housefams && $housefams[$i - 1])
            echo
' value="' . $housefams[$i - 1]['weight'] . '"';
        echo
"><br>\n";
    }
    echo
"<input type=\"submit\" value=\"Go\">\n";
    echo
"</p></form>\n";
}
else
{
    
$array0 = get_familiar($_REQUEST['class'], 0);
    
    for(
$i = 1$i <= 5$i++)
    {
        if(
$_REQUEST["w{$i}"] != '')
            ${
"array" . $i} = get_familiar($_REQUEST["opp{$i}"], $_REQUEST["w{$i}"]);
        else
            ${
"array" . $i} = array(0,0,0,0, 'name' => 'Unknown', 'weight' => 1000);
    }
    
printresults($array0, $array1, $array2, $array3, $array4, $array5);
}

page_footer();
?>


Valid HTML 4.01 StrictValid CSSLevel Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0
Retrieved from http:// www.mrphlip.com/ kol/ kolfamiliars.php? viewsource=yep.
Copyright © 2006–8 Phillip Bradbury. Some rights reserved.
This page is best viewed in a web browser at a screen resolution. Attempts to do otherwise may fail miserably.
John Gabriel – maths crackpot and Internet crazy person.
No Oz net censorship - nocleenfeed.com
Contact me