function rail_peddler_run()
{
    global $session, $inventory;
    $op = httpget("op");
    $loc = rail_peddler_getloc();
    $hid = $loc["peddlerhid"];
    $rid = $loc["peddlerrid"];
    $price = get_module_setting("peddlerprice");
    if ($op == "buy") {
        $headertext = "Why sure, I'll take one of those!";
    } else {
        $headertext = "Go away, I'm busy.";
    }
    page_header($headertext);
    switch ($op) {
        case "buy":
            output("The scruffy vendor's eyes gleam. Was that a fla`gs`0h of green, or no? \"`2Verra wise, %s. Ye willna be sorry!`0\"`n`n", translate_inline($session['user']['sex'] ? 'lass' : 'lad'));
            give_item("cardcase");
            //			if (!$success){
            //				output("Then -- a frown. \"`2Wait, no, I canna sell t'ye. Ye'd better petition the Big Boss, tell 'im t'see what's gaen wrong wiv all dis.`0\"`n`n");
            //			} else {
            output("You have a fine leather card case. Pleased, you admire its soft texture. What an excellent purchase you have made!`n`n");
            //			}
            $session['user']['gems'] -= $price;
            break;
        case "pass":
            output("\"`2Bleedin' smart-arse.`0\" The scruffy vendor shrugs and goes off to pester someone else.`n`n");
            break;
    }
    addnav("Back to the Concourse", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
    page_footer();
}
function marriage_lovedrinks()
{
    $z = 2;
    $s = get_module_setting('loveDrinksAdd');
    if (is_module_installed('drinks') && $s < $z) {
        $sql = array();
        $ladd = array();
        if ($s < 1) {
            // We use 'lessthan' so more drinks can be packaged with this
            $sql[] = "INSERT INTO " . db_prefix("drinks") . " VALUES (0, 'Love Brew', 1, 25, 5, 0, 0, 0, 20, 0, 5, 15, 0.0, 0, 0, 'Cedrik reaches under the bar, pulling out a purple cupid shaped bottle... as he pours it into a crystalline glass, the glass shines and he puts a pineapple within the liquid... \"Here, have a Love Brew..\" says Cedrik.. and as you try it, you feel uplifted!', '`%Love Brew', 12, 'You remember love..', 'Despair sets in.', '1.1', '.9', '1.5', '0', '', '', '')";
            $ladd[] = "Love Brew";
        }
        if ($s < 2) {
            // We use 'lessthan' so more drinks can be packaged with this
            $sql[] = "INSERT INTO " . db_prefix("drinks") . " VALUES (0, 'Heart Mist', 1, 25, 5, 0, 0, 0, 20, 0, 5, 15, 0.0, 0, 0, 'Cedrik grabs for a rather garish looking bottle on the shelf behind him... as he pours it into a large yellow mug, the porcelain seems to dissolve.. ooh er.. he puts a tomato within the sweet smelling gunk... \"Here, have a Heart Mist..\" says Cedrik.. and as you try it, you see symbols of love!', '`\$Heart Mist', 18, '`%Misty hearts fly around you..', '`#The sky falls...', '1.1', '.9', '1.5', '0', '', '', '')";
            $ladd[] = "Heart Misy";
        }
        foreach ($sql as $val) {
            db_query($val);
        }
        foreach ($ladd as $val) {
            $sql = "SELECT * FROM " . db_prefix("drinks") . " WHERE name='{$val}' ORDER BY costperlevel";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            set_module_objpref('drinks', $row['drinkid'], 'loveOnly', 1, 'marriage');
        }
        set_module_setting('loveDrinksAdd', $z);
        output("`n`c`b`^Marriage Module - Drinks have been added to the Loveshack`0`b`c");
    } elseif (!is_module_active('drinks')) {
        set_module_setting('loveDrinksAdd', 0);
    }
}
function nooblube_dohook($hookname, $args)
{
    global $session, $badguy;
    switch ($hookname) {
        case "battle-defeat":
            //check to see if they're alive first, 'cause otherwise it'll add favour when they get wiped out on the FailBoat
            if ($session['user']['alive'] == false) {
                break;
            }
            //check to see if they've got any hitpoints, for stuff like the Tattoo Monster and defeating their masters
            if ($session['user']['hitpoints'] > 0) {
                break;
            }
            $maxlevel = get_module_setting("level");
            $currentlevel = $session['user']['level'];
            if ($currentlevel < $maxlevel) {
                if ($session['user']['dragonkills'] == 0) {
                    if ($session['user']['deathpower'] < 100) {
                        $session['user']['deathpower'] = get_module_setting("lube");
                    }
                    $tutormsg = translate_inline("`#What did I tell you about being careful?  Bloody newbies.  Okay, those nice gentlemen coming towards you will pick you up and drag you to my FailBoat, but don't worry about it too much.  Just come and see me below decks and I'll get you put on the next boat back to the Island.  Don't get used to it though, matey - once you hit level ten, you'll have to fight for your freedom like everyone else.");
                    if ($tutormsg) {
                        tutor_talk("%s", $tutormsg);
                    }
                }
            }
            break;
    }
    return $args;
}
function drunkard_runevent($type)
{
    global $session;
    require_once "lib/partner.php";
    $partner = get_partner();
    $chance = get_module_setting("spillchance");
    $roll = e_rand(1, 100);
    $seen = get_module_pref("seen");
    set_module_pref("seen", $seen + 1);
    output("`5A very drunk patron stumbles into you as you make your way across the crowded room.`n`n");
    if ($roll < $chance) {
        // He spills on you
        output("`5He is carrying a nearly full glass of ale.");
        output("As he collides with you, it spills all over your nearly clean clothes!");
        output("As you look up, you notice %s`5 watching you and become acutely embarrassed.", $partner);
        output("You notice %s`5 is trying to keep from laughing out loud at your mishap.", $partner);
        output("`n`n`&You `\$lose 1`& charm point.");
        if ($session['user']['charm'] > 0) {
            $session['user']['charm']--;
        }
    } else {
        // You're safe
        output("`5Fortunately his glass was already empty.");
        output("You escort him over to a chair where he can sit without running into everyone else.");
        output("As you stand up, you catch %s's`5 eye and receive a big smile for your kindness.", $partner);
        output("`n`n`&You gain `^1`& charm.");
        $session['user']['charm']++;
    }
}
function wcgpoints_supporterpoints_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "wcgpoints_increased":
            if (get_module_pref("gotfirst")) {
                $session['user']['donation'] += 5;
                output("`5`bYou have five extra Supporter Points!`b  Thank you for contributing to humanitarian research.`0`n`n");
            } else {
                if (get_module_pref("runtime", "wcgpoints") > get_module_setting("initialrequirement")) {
                    $session['user']['donation'] += get_module_setting("initialreward");
                    require_once "lib/systemmail.php";
                    $subj = "You've got Supporter Points!";
                    $body = "As a thank-you for helping us to support humanitarian research via grid computing, we've given you 500 Supporter Points completely free of charge.  Thank you so much!  Remember that you'll get five extra Supporter Points every time your World Community Grid points increase (which is usually every 24 hours, if you let the client run regularly).  Have fun!";
                    systemmail($session['user']['acctid'], $subj, $body);
                    set_module_pref("gotfirst", true);
                }
            }
            break;
        case "wcg-features-desc":
            output("`bFree Supporter Points`b: After you've run the World Community Grid client for at least 24 hours (it doesn't have to be all at once - an hour here and an hour there will soon add up), you'll get 500 Supporter Points completely free of charge.  After that, you'll get 5 Supporter Points every time World Community Grid reports that your Cobblestones have increased.`n`n");
            break;
    }
    return $args;
}
function addgems_dohook($hook, $args)
{
    global $session;
    $session['user']['gems'] += get_module_setting('how_many');
    output("`^%s`n`0", get_module_setting('message'));
    return $args;
}
function cakeordeath_run()
{
    global $session;
    page_header("Cake Or Death");
    switch (httpget("op")) {
        case "examine":
            // Tell the player what the deal with Cake Or Death is
            $counter = number_format(get_module_setting("counter"));
            output("`0A shiny wooden table sits back from the main street.  Behind it, a man sits idly reading the Improbable Island Enquirer.  Before him, sat on the table, is a large sponge cake.  Above him is a banner, displaying the name of his game:`b'`5Cake`0 or `4Death!`0'`b`n`nHe sees you pondering the sign, and calls over to you.  `b'`5Cake`0 or `4Death!`0  `b`5Cake`0 or `4Death!`0' he cries.  'Ninety-nine per cent chance of `b`5Cake`0`b!'`n`nIt's not often that an immaculately-dressed gentleman with glowing green eyes offers you a 99% chance of cake.  What would you like to do?");
            //add navs
            addnav("CAKE!", "runmodule.php?module=cakeordeath&op=play");
            addnav("Back away slowly", "village.php");
            break;
        case "play":
            $counter = get_module_setting("counter");
            addnav("Back to the Outpost", "village.php");
            if ($counter > 0) {
                output("The green-eyed gentleman hands you a slice of cake, on a paper plate.  You thank him, and walk away merrily wolfing down your prize.`n`nYou feel `5Full Of Cake!`0");
                set_module_setting("counter", get_module_setting("counter") - 1);
                apply_buff('tastycake', array("name" => "`5Full Of Cake`0", "rounds" => 10, "atkmod" => 1.1, "defmod" => 1.1, "roundmsg" => "`5The cake you ate earlier has boosted your energy!`n", "schema" => "module-cakeordeath"));
            }
            if ($counter <= 0) {
                output("The green-eyed gentleman hands you a slice of cake, on a paper plate.  You thank him, and walk away merrily wolfing down your prize.`n`nYou feel `5Full Of Cake!`0`n`nMoments later, the slow-acting poison starts to take effect.  The world begins to melt in front of you.  Grey spots dance on the edges of your vision.  Behind you, a green-eyed monster offers you another slice of cake, laughing and pointing.`n`nYou curse your luck as the hallucinations begin to kick in.");
                set_module_setting("counter", 100);
                apply_buff('failcake', array("name" => "`5Full Of FailCake`0", "rounds" => -1, "regen" => -10, "startmsg" => "`5You are walking on pink icing.  The sky is made of jam.  Your eyes are two cherries.  That cake was awesome.`0`n", "roundmsg" => "`5The poisoned cake saps your strength, and you lose ten hitpoints!`0`n", "schema" => "module-cakeordeath"));
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("failcake", "Failcake Fancier", "This player was unfortunate at the Cake or Death stand...", "medal_failcake.png");
                }
            }
            break;
    }
    page_footer();
}
function dwshacks_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-list-type":
            addnav("Show Only Types");
            addnav(array("%s", translate_inline(ucfirst(get_module_setting("dwnameplural", "dwshacks")))), "runmodule.php?module=dwellings&op=list&showonly=dwshacks&ref={$args['ref']}&sortby={$args['sortby']}&order={$args['order']}");
            break;
        case "dwellings-list-interact":
            if ($args['type'] == "dwshacks" && $args['status'] == 1 && get_module_setting("maxkeys") == 123456789) {
                addnav("", "runmodule.php?module=dwellings&op=enter&dwid={$args['dwid']}");
                $tress = translate_inline("Tresspass");
                rawoutput("<a href='runmodule.php?module=dwellings&op=enter&dwid={$args['dwid']}'>{$tress}</a>");
            }
            break;
        case "dwellings-manage":
            $dwid = $args['dwid'];
            if (get_module_setting("maxkeys") == 123456789 && $args['type'] == "dwshacks") {
                blocknav("runmodule.php?module=dwellings&op=keys&dwid={$dwid}");
            }
            break;
        case "dwellings":
            if (get_module_objpref("city", $args['cityid'], "showdwshacks")) {
                output("  Along the narrow pathway, precariously placed wood planks are nailed and leaning on each other in a fashion that only leaves you to assume they are supposed to be %s.`0", translate_inline(get_module_setting("dwnameplural")));
                if ($args['allowbuy'] == 1 && $session['user']['dragonkills'] >= get_module_setting("dkreq")) {
                    $cityid = $args['cityid'];
                    addnav("Options");
                    addnav(array("Establish a %s", translate_inline(ucfirst(get_module_setting("dwname", "dwshacks")))), "runmodule.php?module=dwellings&op=buy&type=dwshacks&subop=presetup&cityid={$cityid}");
                }
            }
            break;
    }
    return $args;
}
function monsterkills_run()
{
    page_header("Most Monster Kills");
    $acc = db_prefix("accounts");
    $mp = db_prefix("module_userprefs");
    $sql = "SELECT {$acc}.name AS name,\r\n\t\t{$acc}.acctid AS acctid,\r\n\t\t{$mp}.value AS kills,\r\n\t\t{$mp}.userid FROM {$mp} INNER JOIN {$acc}\r\n\t\tON {$acc}.acctid = {$mp}.userid \r\n\t\tWHERE {$mp}.modulename = 'monsterkills' \r\n\t\tAND {$mp}.setting = 'kills' \r\n\t\tAND {$mp}.value > 0 ORDER BY ({$mp}.value+0)\t\r\n\t\tDESC limit " . get_module_setting("list") . "";
    $result = db_query($sql);
    $rank = translate_inline("Kills");
    $name = translate_inline("Name");
    output("`n`b`c`@Most`\$ Monster `@Kills`n`n`c`b");
    rawoutput("<table border='0' cellpadding='2' cellspacing='1' align='center'>");
    rawoutput("<tr class='trhead'><td align=center>{$name}</td><td align=center>{$rank}</td></tr>");
    for ($i = 0; $i < db_num_rows($result); $i++) {
        $row = db_fetch_assoc($result);
        if ($row['name'] == $session['user']['name']) {
            rawoutput("<tr class='trhilight'><td>");
        } else {
            rawoutput("<tr class='" . ($i % 2 ? "trdark" : "trlight") . "'><td align=left>");
        }
        output_notl("%s", $row['name']);
        rawoutput("</td><td align=right>");
        output_notl("%s", $row['kills']);
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    addnav("Back to HoF", "hof.php");
    villagenav();
    page_footer();
}
function mapchat_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "worldnav":
            $chats = unserialize(get_module_setting("placedchats"));
            $ploc = get_module_pref("worldXYZ", "worldmapen");
            $chatarea = 0;
            if (!is_array($chats)) {
                $chats = array();
            }
            foreach ($chats as $key => $vals) {
                if ($ploc == $vals['loc']['x'] . "," . $vals['loc']['y'] . ",1") {
                    output("`0There's a little tent here.`n");
                    addnav("Investigate Tent", "runmodule.php?module=mapchat&xyz=" . $ploc);
                    $chatarea = 1;
                    break;
                }
            }
            if (!$chatarea) {
            }
            break;
    }
    return $args;
}
function iitems_crates_gypsy_run()
{
    global $session;
    page_header("Crate Locations");
    $cost = get_module_setting("cost", "iitems_crates_gypsy");
    if ($cost == 1) {
        $p = "Cigarette";
    } else {
        $p = "Cigarettes";
    }
    if ($session['user']['gems'] >= $cost) {
        $session['user']['gems'] -= $cost;
        output("`5You hand over the %s and the old man chuckles.  \"`!Aaah, thank ye kindly.  Now, here we are!  I'd recommend you write these down.  And be quick about it - these crates tend to disappear `ifast!`i`5\"`n`nHe reaches under his desk and brings up a chalkboard with all the locations of the Island's crates written upon it, corresponding to the squares on your crudely-drawn World Map and laid out as X and Y co-ordinates.  You spend a few minutes studying the board.`n`n", $p);
        $crates = unserialize(get_module_setting("crates", "iitemcrates"));
        foreach ($crates as $key => $vals) {
            output("%s,%s`n", $vals['loc']['x'], $vals['loc']['y']);
        }
    } else {
        output("`5You enthusiastically agree to the price, before realising that you don't actually have that many cigarettes.  Whoops.");
    }
    addnav("Leave");
    addnav("Return to the Outpost", "village.php");
    page_footer();
    return true;
}
function bioextension_dohook($hookname, $args)
{
    global $session;
    if ($hookname == "bioinfo") {
        $sql = "SELECT donation FROM " . db_prefix("accounts") . " WHERE acctid = '" . $args['acctid'] . "'";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        if ($row['donation'] >= get_module_setting("threshhold")) {
            $bio = get_module_pref("user_extendedbio", "bioextension", $args['acctid']);
            $link = get_module_pref("user_extlink", "bioextension", $args['acctid']);
            $bio = str_replace(chr(13), "`n", $bio);
            $bio = stripslashes($bio);
            output("`0%s`n`n", $bio);
            if (substr($link, 0, 5) == "http:") {
                rawoutput("<a href=\"" . $link . "\">Player's webpage</a><br /><br />");
            }
        }
    } else {
        if ($hookname == "footer-prefs") {
            $bio = get_module_pref("user_extendedbio");
            $limit = get_module_setting("charlimit");
            if (strlen($bio) > $limit) {
                output("`c`4`bWARNING`b`0`c`nYour Extended Bio is oversized by %s characters.  If you navigate away from this page, your Extended Bio will have %s characters indiscriminately cut from the end.  Please edit and re-save your Extended Bio to avoid cuts.", strlen($bio) - $limit, strlen($bio) - $limit);
                $bio = substr($bio, 0, $limit);
                set_module_pref("user_extendedbio", $bio);
            }
        }
    }
    return $args;
}
function iitems_cratelocator_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "iitems-use-item":
            if ($args['player']['itemid'] == "cratelocator") {
                $crates = unserialize(get_module_setting("crates"));
                output("`0You thumb the switch on your Crate Locator.  It buzzes and hisses for a moment, exhausting its primitive battery sending out a radio ping to nearby Crates.`n`n");
                $crates = unserialize(get_module_setting("crates", "iitemcrates"));
                debug($crates);
                $ploc = get_module_pref("worldXYZ", "worldmapen");
                list($px, $py, $pz) = explode(",", $ploc);
                $pxlow = $px - 5;
                $pxhigh = $px + 5;
                $pylow = $py - 5;
                $pyhigh = $py + 5;
                if (!is_array($crates)) {
                    $crates = array();
                }
                $count = 0;
                foreach ($crates as $key => $vals) {
                    if ($vals['loc']['x'] >= $pxlow && $vals['loc']['x'] <= $pxhigh && $vals['loc']['y'] >= $pylow && $vals['loc']['y'] <= $pyhigh) {
                        $count++;
                    }
                }
                output("It displays, weakly, the number `\$`b%s`b`0 in dull red LED's before its radio module catches fire.`n`n", $count);
            }
            break;
    }
    return $args;
}
function forestturn_runevent($type)
{
    global $session;
    // The only type of event we care about are the forest.
    $chance = get_module_setting("percentgain");
    $roll = e_rand(1, 100);
    if ($roll <= $chance) {
        output("`^You discover a skin of liquid hanging over the limb of a tree.");
        output("Since the sigils inscribed on the skin are those of someone you recognize as a very powerful warrior from the village, you decide that it would be safe to take a sip.`n`n`n");
        output("Man is that stuff potent!");
        output("You feel `!hyper`^.`n`n");
        output("You `%receive one`^ extra turn!`0");
        $session['user']['turns']++;
    } else {
        output("`^Walking along a path in the forest, you come upon a field of flowers.");
        output("Stopping to pick one, you inhale its scent.`n`n");
        output("`\$Yawn!");
        output("`^Man, that flower scent made you really sleepy.");
        output("You stumble off the path to take a nap.`n`n");
        if ($session['user']['turns'] > 0) {
            output("You `%lose one `^turn!`0");
            $session['user']['turns']--;
        }
    }
}
function pinata_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "newday":
            set_module_pref("hittoday", 0);
            break;
        case "gardens":
            if (is_module_active("gardenparty") && get_module_setting("party") == 1 || get_module_setting("active") == 1) {
                if (is_module_active("gardenparty")) {
                    $start = strtotime(get_module_setting("partystart", "gardenparty"));
                    $end = strtotime(get_module_setting("partyduration", "gardenparty"), $start);
                    $now = time();
                } else {
                    $start = 0;
                    $now = 2;
                    $end = 1;
                }
                if (get_module_setting("active") == 1 || $start <= $now && $end >= $now) {
                    if (get_module_pref("hittoday") < get_module_setting("maxhit")) {
                        output("`n`#You notice a crowd of partiers gathered around a `@Green Dragon shaped pinata`#, swinging awkwardly at it with a long pole. ");
                        output("They gesture you over for a turn, offering you the stick and a challenge to do better.`n`n");
                        if ($start <= $now && $end >= $now) {
                            addnav("Party Treats!");
                        }
                        addnav("Swat the Pinata", "runmodule.php?module=pinata");
                    } else {
                        output("You notice the remnants of the broken pinata, and a child sorting through looking for a missed prize.");
                    }
                }
            }
            break;
    }
    return $args;
}
function specificmaplocation_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "worldnav":
            if (get_module_setting("finder1") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "14,37,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder1", $session['user']['name']);
            }
            if (get_module_setting("finder2") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "6,33,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder2", $session['user']['name']);
            }
            if (get_module_setting("finder3") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "17,31,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder3", $session['user']['name']);
            }
            if (get_module_setting("finder4") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "25,26,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder4", $session['user']['name']);
            }
            if (get_module_setting("finder5") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "7,21,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder5", $session['user']['name']);
            }
            if (get_module_setting("finder6") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "22,20,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder6", $session['user']['name']);
            }
            if (get_module_setting("finder7") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "14,17,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder7", $session['user']['name']);
            }
            if (get_module_setting("finder8") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "3,9,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder8", $session['user']['name']);
            }
            if (get_module_setting("finder9") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "22,6,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder9", $session['user']['name']);
            }
            if (get_module_setting("finder10") == "Nobody" && get_module_pref("worldXYZ", "worldmapen") == "4,3,1") {
                output("You found one of the ten boxes of cigarettes!  You open it up to find a hundred of the damned things!  Woohoo!");
                $session['user']['gems'] += 100;
                set_module_setting("finder10", $session['user']['name']);
            }
            break;
    }
    return $args;
}
function avatar_dohook($hookname, $args)
{
    global $session;
    $cost = get_module_setting("cost");
    $changecost = get_module_setting("changecost");
    require_once "modules/avatar/func.php";
    require "modules/avatar/dohook/{$hookname}.php";
    return $args;
}
function findgold_runevent($type, $link)
{
    global $session;
    $min = $session['user']['level'] * get_module_setting("mingold");
    $max = $session['user']['level'] * get_module_setting("maxgold");
    $gold = e_rand($min, $max);
    output("`^Fortune smiles on you and you find %s gold!`0", $gold);
    $session['user']['gold'] += $gold;
    debuglog("found {$gold} gold in the dirt");
}
function get_default_action_list()
{
    $actions = unserialize(get_module_setting("actionsarray", "staminasystem"));
    if (!is_array($actions)) {
        $actions = array();
        set_module_setting("actionsarray", serialize($actions), "staminasystem");
    }
    $actions = unserialize(get_module_setting("actionsarray", "staminasystem"));
    return $actions;
}
function peerpressure_victimtest()
{
    global $session;
    if ($session['user']['level'] != 15) {
        return 0;
    }
    if (get_module_pref("dayspast", "peerpressure") < get_module_setting("daysfree", "peerpressure")) {
        return 0;
    }
    return 100;
}
function iitems_eboy_gypsy_run()
{
    global $session;
    page_header("eBoy's Price Chart");
    require_once "modules/iitems/lib/lib.php";
    $cost = get_module_setting("cost", "iitems_eboy_gypsy");
    if ($cost == 1) {
        $p = "Cigarette";
    } else {
        $p = "Cigarettes";
    }
    if ($session['user']['gems'] >= $cost) {
        $session['user']['gems'] -= $cost;
        output("`5You hand over the %s and the old man chuckles.  \"`!Aaah, thank ye kindly.  Now, here we are!  I'd recommend you write these down.  Now mark my words - these prices fluctuate by the `iminute`i!  That eBoy, he's a crafty bastard, y'see.  He sells things for whatever people are willing to buy them for, and not one penny less!  Even if that means putting his prices up the `isecond`i someone buys something!`5\"`n`nHe reaches under his desk and brings up a clattering rectangular machine made out of wood and brass, about the size of a fat telephone directory.  A radio antenna protrudes from one corner.`n`nTrue to his word, the spinning reels show the prices of every commodity in every outpost.  You spend a few minutes studying the readout.`n`n", $p);
        $sql = "select * from " . db_prefix("cityprefs");
        $result = db_query($sql);
        for ($i = 0; $i < db_num_rows($result); $i++) {
            $row = db_fetch_assoc($result);
            $cid = $row['cityid'];
            $name = $row['cityname'];
            $eboy = unserialize(get_module_objpref("city", $cid, "eboytrades-intelligent", "iitems_eboy_intelligent"));
            output("`b`0%s`b`n", $name);
            rawoutput("<table border=0 cellpadding=3 cellspacing=2><tr class=\"trdark\"><td>Item</td><td>Buying at</td><td>Selling at</td><td>Stock</td></tr>");
            $classcount = 1;
            foreach ($eboy as $key => $details) {
                $itemdetails = iitems_get_item_details($key);
                if ($details['price'] < 10) {
                    $details['price'] = 10;
                }
                $eboy[$key]['price'] = $details['price'];
                if ($details['stock'] < 3) {
                    $buy = round($details['price'] * 0.5);
                } else {
                    $buy = round($details['price'] * 0.7);
                }
                $classcount++;
                $class = $classcount % 2 ? "trdark" : "trlight";
                $dname = $itemdetails['verbosename'];
                $dsell = number_format($details['price']);
                $dbuy = number_format($buy);
                $dstock = number_format($details['stock']);
                rawoutput("<tr class='{$class}'><td>{$dname}</td><td align=\"center\">{$dbuy}</td><td align=\"center\">{$dsell}</td><td align=\"center\">{$dstock}</td></tr>");
            }
            rawoutput("</table>");
            output("`n`n");
        }
    } else {
        output("`5You enthusiastically agree to the price, before realising that you don't actually have that many cigarettes.  Whoops.");
    }
    addnav("Leave");
    addnav("Return to the Outpost", "village.php");
    page_footer();
    return true;
}
function finetune_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "healmultiply":
            debug($args);
            $args['alterpct'] = get_module_setting("healermultiplier");
            break;
    }
    return $args;
}
function dragonattack_victimtest()
{
    global $session;
    if ($session['user']['level'] < 15) {
        return 0;
    }
    if (get_module_pref("dayspast", "dragonattack") < get_module_setting("daysfree", "dragonattack")) {
        return 0;
    }
    return 100;
}
function dwellingscostsp_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "dwellings-buy-valuecheck":
            $typeid = get_module_setting("typeid", $args['type']);
            $paidsp = abs((int) httppost('paidsp'));
            if ($paidsp < 0) {
                $paidsp = 0;
            }
            $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
            if ($pointsavailable < $paidsp) {
                $args['allowpay'] = 0;
                blocknav("runmodule.php?module=dwellings&op=build&type=" . $args['type'] . "&dwid=" . $args['dwid'] . "");
                output("`nYou do not have that many site points.");
            } elseif ($paidsp > get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent")) {
                $args['allowpay'] = 0;
                blocknav("runmodule.php?module=dwellings&op=build&type=" . $args['type'] . "&dwid=" . $args['dwid'] . "");
                output("`nYou have tried to spend more site points than you need to.");
            }
            break;
        case "dwellings-buy-setup":
            $typeid = get_module_setting("typeid", $args['type']);
            $paidsp = abs((int) httppost('paidsp'));
            if ($paidsp < 0) {
                $paidsp = 0;
            }
            $spent = get_module_objpref("dwellings", $args['dwid'], "spspent") + $paidsp;
            set_module_objpref("dwellings", $args['dwid'], "spspent", $spent);
            $session['user']['donationspent'] += $paidsp;
            if ($spent != get_module_objpref("dwellingtypes", $typeid, "spcost")) {
                $args['finished'] = 0;
            }
            break;
        case "dwellings-pay-costs":
            $typeid = get_module_setting("typeid", $args['type']);
            $costsp = get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent");
            if ($costsp) {
                output("`#%s Site Points`0`n", $costsp);
            }
            break;
        case "dwellings-pay-input":
            $typeid = get_module_setting("typeid", $args['type']);
            $costsp = get_module_objpref("dwellingtypes", $typeid, "spcost") - get_module_objpref("dwellings", $args['dwid'], "spspent");
            $sp = translate_inline("Site Points");
            if ($costsp) {
                rawoutput("{$sp}: <input id='input' name='paidsp' width=5><br>");
            }
            break;
    }
    return $args;
}
function dpresurrect_run()
{
    global $session;
    page_header("Returning to Improbable Island");
    $op = httpget('op');
    if ($op == "resurrect") {
        $session['user']['donationspent'] += get_module_setting("pointsrequired");
        output("`\$The Watcher`0 nods.  \"`7I'm not above taking the occasional bribe.  That's what makes the world go round, right?`0\"  You nod sadly.  \"`7Prepare a rowboat, we have a restoration coming through!`0\"`n`nWelcome back to Improbable Island...");
        addnav("Return to Improbable Island", "newday.php?resurrection=true");
        set_module_setting("timestaken", get_module_setting("timestaken") + 1);
    }
    page_footer();
}
function abandoncastle_runevent($type)
{
    global $session;
    if (!get_module_pref("wasfound") and get_module_setting("forestvil") == 1) {
        output("`n`2While walking in the Forest, you have found a path that leads to an `bAbandoned Castle`b, which is very old.`n`nA sign near the castle says:`n\"`#Beware, only the bravest warrior should enter the Castle. If you decide to enter, your chance to die is pretty high.");
        addnews("%s has found a path to the Abandoned Castle.", $session['user']['name']);
        debuglog("found the Abandoned Castle");
        addnav("Enter the Castle", "runmodule.php?module=abandoncastle");
        addnav("Back to the Forest", "forest.php");
    } else {
        redirect("forest.php?op=search");
    }
}
function mountrarity_dohook($hookname, $args)
{
    switch ($hookname) {
        case "newday-runonce":
            $sql = "SELECT mountid FROM " . db_prefix("mounts") . " WHERE mountactive=1";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $id = $row['mountid'];
                $rarity = get_module_objpref("mounts", $id, "rarity");
                if (e_rand(1, 100) > $rarity) {
                    set_module_objpref("mounts", $id, "unavailable", 1);
                } else {
                    // You need to reset the availability if it's not unavailable
                    // otherwise, it never becomes available again!
                    set_module_objpref("mounts", $id, "unavailable", 0);
                }
            }
            break;
        case "mountfeatures":
            $rarity = get_module_objpref("mounts", $args['id'], "rarity");
            $args['features']['Rarity'] = $rarity;
            break;
        case "stables-desc":
            if (get_module_setting("showout")) {
                $sql = "SELECT mountid, mountname FROM " . db_prefix("mounts") . " WHERE mountactive=1";
                $result = db_query($sql);
                output("`nA sign by the door proclaims that the following mounts are out of stock for today:");
                while ($row = db_fetch_assoc($result)) {
                    $out = get_module_objpref("mounts", $row['mountid'], "unavailable");
                    if ($out) {
                        output("`n%s", $row['mountname']);
                    }
                }
            } else {
                output("`nIf you don't see something you like today, perhaps you should check again tomorrow.");
            }
            break;
        case "stables-nav":
            $sql = "SELECT mountid FROM " . db_prefix("mounts") . " WHERE mountactive=1";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $id = $row['mountid'];
                $out = get_module_objpref("mounts", $id, "unavailable");
                if ($out) {
                    blocknav("stables.php?op=examine&id={$id}");
                }
            }
            break;
    }
    return $args;
}
function inncoupons_run()
{
    require_once "lib/sanitize.php";
    global $session;
    $op = httpget("op");
    $iname = getsetting("innname", LOCATION_INN);
    $cost = get_module_setting("cost");
    $config = unserialize($session['user']['donationconfig']);
    if (!is_array($config)) {
        $config = array();
    }
    if (isset($config['innstays']) && $config['innstays']) {
        set_module_pref("availablestays", $config['innstays']);
        unset($config['innstays']);
        $session['user']['donationconfig'] = serialize($config);
    }
    if ($op == "room") {
        $num = get_module_pref("availablestays");
        $num--;
        set_module_pref("availablestays", $num);
        $session['user']['loggedin'] = 0;
        $session['user']['location'] = $iname;
        $session['user']['boughtroomtoday'] = 1;
        $session['user']['restorepage'] = "inn.php?op=strolldown";
        saveuser();
        $session = array();
        redirect("index.php");
    } elseif ($op == "innstays") {
        page_header("Hunter's Lodge");
        output("`7J. C. Petersen turns to you. \"`&Ten free nights in %s will cost %s points,`7\" he says.", $iname, $cost);
        output("\"`&Will this suit you?`7\"`n`n");
        addnav("Confirm Inn Stays");
        addnav("Yes", "runmodule.php?module=inncoupons&op=innconfirm");
        addnav("No", "lodge.php");
    } elseif ($op == "innconfirm") {
        page_header("Hunter's Lodge");
        addnav("L?Return to the Lodge", "lodge.php");
        $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
        if ($pointsavailable >= $cost) {
            output("`7J. C. Petersen gives you a card that reads \"Coupon: Good for ten free stays at %s\"", $iname);
            $num = get_module_pref("availablestays");
            $num += 10;
            set_module_pref("availablestays", $num);
            $session['user']['donationspent'] += $cost;
        } else {
            output("`7J. C. Petersen looks down his nose at you.");
            output("\"`&I'm sorry, but you do not have the %s points required to purchase the coupons. Please return when you do and I'll be happy to sell them to you.`7\"", $cost);
        }
    }
    page_footer();
}
function translationwizard_run()
{
    global $session, $logd_version, $coding;
    check_su_access(SU_IS_TRANSLATOR);
    //check again Superuser Access
    $op = httpget('op');
    page_header("Translation Wizard");
    //get some standards
    $languageschema = get_module_pref("language", "translationwizard");
    //these lines grabbed the local scheme, in 1.1.0 there is a setting for it
    $coding = getsetting("charset", "ISO-8859-1");
    $viewsimple = get_module_pref("view", "translationwizard");
    $mode = httpget('mode');
    $namespace = httppost('ns');
    $from = httpget('from');
    $page = get_module_setting(page);
    if (httpget('ns') != "" && $namespace == "") {
        $namespace = httpget('ns');
    }
    //if there is no post then there is maybe something to get
    $trans = httppost("transtext");
    if (is_array($trans)) {
        $transintext = $trans;
    } else {
        if ($trans) {
            $transintext = array($trans);
        } else {
            $transintext = array();
        }
    }
    $trans = httppost("transtextout");
    if (is_array($trans)) {
        $transouttext = $trans;
    } else {
        if ($trans) {
            $transouttext = array($trans);
        } else {
            $transouttext = array();
        }
    }
    //end of the header
    if ($op == "") {
        $op = "default";
    }
    require "./modules/translationwizard/errorhandler.php";
    require "./modules/translationwizard/{$op}.php";
    require_once "lib/superusernav.php";
    superusernav();
    require "./modules/translationwizard/build_nav.php";
    page_footer();
}
function clancommentaryoverview_run()
{
    page_header("Clan Commentary Overview");
    $numcomments = get_module_setting("numcomments");
    require_once "lib/superusernav.php";
    superusernav();
    addnav("C?Commentary Overview", "moderate.php");
    addnav("Clan Halls");
    $sql = "SELECT clanid, clanname, clanshort FROM " . db_prefix("clans") . " ORDER BY clanid";
    $res = db_query($sql);
    // since these are proper names, they shouldn't be translated
    tlschema("notranslate");
    while ($row = db_fetch_assoc($res)) {
        addnav(array("<%s> %s", $row['clanshort'], $row['clanname']), "moderate.php?area=clan-{$row['clanid']}");
    }
    tlschema();
    $sql = "SELECT clanid, clanname FROM " . db_prefix("clans") . " ORDER BY clanid";
    $res = db_query($sql);
    $firstclan = 1;
    while ($clan = db_fetch_assoc($res)) {
        $cid = $clan['clanid'];
        $csql = "SELECT * FROM " . db_prefix("commentary") . " WHERE section='clan-" . $cid . "' ORDER BY postdate DESC LIMIT " . $numcomments;
        $cres = db_query($csql);
        if (db_num_rows($cres) > 0) {
            if ($firstclan == 1) {
                $firstclan = 0;
                addnav("", "runmodule.php?module=clancommentaryoverview");
                $buttonrefresh = translate_inline("Refresh");
                rawoutput("<form action='runmodule.php?module=clancommentaryoverview' method='post'>");
                rawoutput("<input type='submit' class='button' value='{$buttonrefresh}'>");
                rawoutput("</form>");
            }
            rawoutput("<hr>");
            $cname = $clan['clanname'];
            addnav("", "moderate.php?area=clan-" . $cid);
            rawoutput("<a href='moderate.php?area=clan-" . $cid . "'>");
            output_notl("`b`^%s`b`0", $cname);
            rawoutput("</a>");
            output_notl("`n");
            $carray = array();
            while ($ccomment = db_fetch_assoc($cres)) {
                array_push($carray, $ccomment);
            }
            while ($ccomment = array_pop($carray)) {
                clancommentaryoverview_displaycomment($ccomment);
            }
        }
    }
    page_footer();
}