function scrapbots_get_armies($defenderid, $attackerid)
{
    global $session;
    //get attackers
    $sql = "SELECT id,owner,name,activated,hitpoints,brains,brawn,briskness,junglefighter,retreathp FROM " . db_prefix("scrapbots") . " WHERE owner = {$attackerid}";
    $result = db_query($sql);
    $attacker = array();
    for ($i = 0; $i < db_num_rows($result); $i++) {
        $attacker[$i] = db_fetch_assoc($result);
    }
    $sql = "SELECT id,owner,name,activated,hitpoints,brains,brawn,briskness,junglefighter,retreathp FROM " . db_prefix("scrapbots") . " WHERE owner = {$defenderid}";
    $result = db_query($sql);
    $defender = array();
    for ($i = 0; $i < db_num_rows($result); $i++) {
        $defender[$i] = db_fetch_assoc($result);
    }
    debug("Debugging Attacker");
    debug($attacker);
    debug("Debugging Defender");
    debug($defender);
    $armies = array("attacker" => $attacker, "defender" => $defender);
    //Set starting vals
    $armies['attacker']['retreatpct'] = get_module_pref("retreatpct", "scrapbots", $attackerid);
    $armies['defender']['retreat'] = get_module_pref("retreatpct", "scrapbots", $defenderid);
    debug("Debugging Armies");
    debug($armies);
    return $armies;
}
function rationpack_use($args)
{
    $full = get_module_pref("fullness", "staminafood");
    if ($full >= 100) {
        output("You pick up the ration pack, and eye it for a moment.  Then, you put it right back where it was.  You're `ifar`i too full to eat anything more for now.`n`n");
        unset($args['destroyafteruse']);
        unset($args['usetext']);
        return $args;
    }
    //debug($args);
    require_once "modules/staminasystem/lib/lib.php";
    addstamina(100000);
    increment_module_pref("fullness", 40, "staminafood");
    increment_module_pref("fat", 40, "staminafood");
    increment_module_pref("nutrition", 30, "staminafood");
    if ($full < 0) {
        output("You still feel as though you haven't eaten in days.`n`n");
    }
    if ($full >= 0 && $full < 50) {
        output("You feel a little less hungry.`n`n");
    }
    if ($full >= 50 && $full < 100) {
        output("You still feel as though you've got room for more!`n`n");
    }
    if ($full >= 100) {
        output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
    }
    return $args;
}
function hepzibah_runevent($type)
{
    global $session;
    $from = "village.php?";
    // Since there is no interaction here, don't even set this
    //$session['user']['specialinc'] = "module:Hepzibah";
    $voucher = get_module_pref("voucher", "marquee");
    $city = $session['user']['location'];
    $op = httpget('op');
    // Since the text in both cases is mostly the same, make it common
    output("`7As you're walking around, admiring the sights, a wizened old woman approaches.`n`n");
    output("Her greying hair stands out in shock, and her nose is hooked and gnarled.");
    output("It takes all your willpower not to run away from this ghastly sight.`n`n");
    output("She smiles the most evil looking smile you have ever encountered.`n`n");
    output("`&\"Hello, warrior!");
    if (!is_module_installed("marquee") || $voucher) {
        output("Enjoying your visit?\"`n`n");
        output("`7Before you can answer, she has wandered off towards another tourist.`n`n");
        output("`7You shudder and head away quickly.`n`n");
    } elseif ($op == "" && !$voucher) {
        output("For you, a gift!\"`n`n");
        output("`7Before you can protest, she has grabbed your wrist, and placed a small voucher into your hand.");
        output("It reads, `Q\"One Free Pizza at the Marquee\".`n`n");
        output("`&\"Enjoy your stay in {$city}, warrior!\" `7she says, before wandering off towards another tourist.`n`n");
        set_module_pref("voucher", 1, "marquee");
    }
    // Since we never set the special inc, we don't need to unset it.
    //if ($op != "") {
    //    $session['user']['specialinc'] = "";
    //}
}
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 faqmute_dohook($hookname, $args)
{
    global $session;
    $seen = get_module_pref("seenfaq");
    switch ($hookname) {
        case "insertcomment":
            if (!$seen && !$session['user']['dragonkills']) {
                $args['mute'] = 1;
                $mutemsg = "`n`\$You have to read the FAQ before you can post comments. You can find it in any town.`0`n`n";
                $mutemsg = translate_inline($mutemsg);
                $args['mutemsg'] = $mutemsg;
            }
            break;
        case "faq-posttoc":
            if (!$seen) {
                set_module_pref("seenfaq", true);
            }
            break;
        case "bioinfo":
            $id = $args['acctid'];
            $seen = get_module_pref("seenfaq", false, $id);
            if (httpget("op") == "faqmute") {
                set_module_pref("seenfaq", false, false, $id);
                output("`nPlayer's FAQ seen status reset.`n");
            } elseif ($session['user']['superuser'] & SU_EDIT_COMMENTS && $seen && !$args['dragonkills']) {
                addnav("Mute Player Options");
                addnav("FAQmute player", "bio.php?char=" . $id . "&ret=" . rawurlencode(httpget("ret")) . "&op=faqmute");
            }
            break;
    }
    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 energydrink_use($args)
{
    require_once "modules/staminasystem/lib/lib.php";
    $full = get_module_pref("fullness", "staminafood");
    if ($full >= 100) {
        output("You eye the bottle critically.  Then, you put it right back where it was.  You're `ifar`i too full to imbibe anything more for now.`n`n");
        unset($args['destroyafteruse']);
        unset($args['usetext']);
        return $args;
    }
    addstamina(50000);
    increment_module_pref("fullness", 5, "staminafood");
    $full = get_module_pref("fullness", "staminafood");
    if ($full < 0) {
        output("You still feel as though you haven't eaten in days.`n`n");
    }
    if ($full >= 0 && $full < 50) {
        output("You feel a little less hungry.`n`n");
    }
    if ($full >= 50 && $full < 100) {
        output("You still feel as though you've got room for more!`n`n");
    }
    if ($full >= 100) {
        output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
    }
    return $args;
}
function tents_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "worldnav":
            $ploc = get_module_pref("worldXYZ", "worldmapen");
            $sql = "SELECT owner,type,data FROM " . db_prefix("structures") . " WHERE location = {$ploc}";
            $result = db_query($sql);
            for ($i = 0; $i < db_num_rows($result); $i++) {
                //send structure through module hooks
            }
            // $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=tents&xyz=".$ploc);
            // $chatarea = 1;
            // break;
            // }
            // }
            // if (!$chatarea){
            // }
            break;
    }
    return $args;
}
function es_bridge_gp_dohook($hook, $args)
{
    global $session, $baseaccount;
    $item = httpget('item');
    $action = httpget('action');
    if ($session['user']['armor'] != $baseaccount['armor'] && ($action == 'weararmor' || $action == 'buyarmor') && $session['user']['armor'] == $item) {
        $category = 'armor';
        $defense = $session['user']['defense'];
    } elseif ($session['user']['weapon'] != $baseaccount['weapon'] && ($action == 'wearweapon' || $action == 'buyweapon') && $session['user']['weapon'] == $item) {
        $category = 'weapon';
        $attack = $session['user']['attack'];
    } else {
        $category = false;
    }
    if ($category && get_module_pref($category, 'mysticalshop')) {
        $current_id = get_module_pref($category . 'id', 'mysticalshop');
        debug("Current ID is {$current_id}");
        require_once './modules/mysticalshop/lib.php';
        mysticalshop_destroyitem($category);
        mysticalshop_resetbuffs($current_id);
        require_once './modules/mysticalshop_buffs/stripbuff.php';
        mysticalshop_buffs_stripbuff();
        if ($category == 'armor') {
            $session['user']['defense'] = $defense;
        } else {
            $session['user']['attack'] = $attack;
        }
        debuglog('es_bridge_gp: ' . $category . ' (ID: ' . $current_id . ') item removed on action "' . $action . '".');
    }
    return $args;
}
function friendlist_unignore()
{
    global $session;
    $ac = httpget('ac');
    $ignored = rexplode(get_module_pref('ignored', 'friendlist', $ac));
    $iveignored = rexplode(get_module_pref('iveignored'));
    if (in_array($ac, $iveignored)) {
        $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            $info = sprintf_translate("%s`Q has been removed from your list.", $row['name']);
            require_once "lib/systemmail.php";
            $t = array("`\$Ignore List Removal");
            $mailmessage = array("%s`0`@ has removed you from %s ignore list.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
            systemmail($ac, $t, $mailmessage);
        } else {
            $info = translate_inline("That user no longer exists...");
        }
    }
    $ignored = array_diff($ignored, array($session['user']['acctid']));
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored, 'friendlist', $ac);
    if (in_array($ac, $iveignored)) {
        $iveignored = array_diff($iveignored, array($ac));
        $iveignored = rimplode($iveignored);
        set_module_pref('iveignored', $iveignored);
    }
    output_notl($info);
}
function dwellings_run()
{
    checkday();
    page_header("Dwellings");
    global $session;
    $op = httpget("op");
    $dwid = httpget('dwid');
    $type = httpget('type');
    debug(get_module_pref("location_saver"));
    if ($type == "" && $dwid > 0) {
        $sql = "SELECT type FROM " . db_prefix("dwellings") . " WHERE dwid={$dwid}";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $type = $row['type'];
    }
    $cityid = httpget('cityid');
    require_once "modules/dwellings/run/case_{$op}.php";
    if ($op != "list" && $op != "") {
        addnav("Leave");
        addnav("Return to Hamlet", "runmodule.php?module=dwellings");
    } else {
        addnav("Navigation");
        villagenav();
    }
    page_footer();
}
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 friendlist_search()
{
    global $session;
    $n = httppost("n");
    rawoutput("<form action='runmodule.php?module=friendlist&op=search' method='POST'>");
    addnav("", "runmodule.php?module=friendlist&op=search");
    if ($n != "") {
        $string = "%";
        for ($x = 0; $x < strlen($n); $x++) {
            $string .= substr($n, $x, 1) . "%";
        }
        $sql = "SELECT name,dragonkills,acctid FROM " . db_prefix("accounts") . " WHERE name LIKE '%{$string}%' AND acctid<>" . $session['user']['acctid'] . " AND locked=0 ORDER BY level,dragonkills";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $ignored = rexplode(get_module_pref('ignored'));
            $friends = rexplode(get_module_pref('friends'));
            $request = rexplode(get_module_pref('request'));
            $iveignored = rexplode(get_module_pref('iveignored'));
            output("`@These users were found:`n");
            rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
            rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                rawoutput("<tr class='" . ($i % 2 ? "trlight" : "trdark") . "'><td>");
                output_notl($row['name']);
                rawoutput("</td><td>");
                if (in_array($row['acctid'], $ignored)) {
                    $info = translate_inline("This user has ignored you.");
                    $info .= " [<a href='runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
                    addnav("", "runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid']);
                } elseif (in_array($row['acctid'], $friends)) {
                    $info = translate_inline("This user is already in your list.");
                } elseif (in_array($row['acctid'], $request)) {
                    $info = translate_inline("This user has already requested to you.");
                } else {
                    if (in_array($row['acctid'], $iveignored)) {
                        $info = "[<a href='runmodule.php?module=friendlist&op=unignore&ac=" . $row['acctid'] . "' class='colLtRed'>" . translate_inline("Unignore") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=unignore&ac=" . $row['acctid']);
                    } else {
                        $info = "[<a href='runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid']);
                        $info .= " - [<a href='runmodule.php?module=friendlist&op=request&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Request") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=request&ac=" . $row['acctid']);
                    }
                }
                rawoutput("{$info}</td></tr>");
            }
            rawoutput("</table>");
        } else {
            output("`c`@`bA user was not found with that name.`b`c");
        }
        output_notl("`n");
    }
    output("`^`b`cFriend Search...`c`b");
    output("`n`nWho do you want to search for?");
    output("`n`nName of user: "******"<input name='n' maxlength='50' value=\"" . htmlentities(stripslashes(httppost('n'))) . "\">");
    $apply = translate_inline("Search");
    rawoutput("<input type='submit' class='button' value='{$apply}'></form>");
}
function ekd_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "biostat":
            $acctid = $args['acctid'];
            $sql = "SELECT dragonkills FROM " . db_prefix("accounts") . " WHERE acctid = {$acctid}";
            $result = db_fetch_assoc(db_query($sql));
            $tdk = $result['dragonkills'];
            $edk = get_module_pref("edks", "edk", $acctid);
            $cdk = $tdk - $edk;
            if ($edk > 1 && $tdk > 1) {
                output("Out of %s total Drive Kills, %s were Economic Drive Kills.`n", $tdk, $edk);
            } else {
                if ($edk == 1) {
                    output("This player has completed an Economic Drive Kill.`n");
                }
            }
            break;
        case "counciloffices":
            addnav("Ask about the Gun", "runmodule.php?module=edk&op=start");
            break;
    }
    return $args;
}
function maikopan_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if (get_module_pref("plotpoint3a", "watcher_quests") && !get_module_pref("plotpoint1") && $session['user']['location'] == "Kittania") {
                output("`0You hear quite a commotion coming from Maiko's cookery school.  A clattering of pots and pans, and a hoarse, screeching voice: \"`i`%Where is it?  WHERE IS IT?!`i`0\"`n`nYou might want to check that out.`n`n");
                addnav($args['fightnav']);
                tlschema();
                blocknav("runmodule.php?module=meatschool&op=start");
                addnav("Maiko's Cookery Academy", "runmodule.php?module=maikopan&step=1");
            } else {
                if (get_module_pref("plotpoint1") && !get_module_pref("plotpoint2")) {
                    blocknav("runmodule.php?module=meatschool&op=start");
                }
            }
            break;
        case "pub_kittania":
            if (get_module_pref("plotpoint1") && !get_module_pref("plotpoint2")) {
                redirect("runmodule.php?module=maikopan&step=2");
            }
            break;
    }
    return $args;
}
function hunterslodge_namedmount_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "stable-mount":
            global $playermount;
            $name = get_module_pref("mountname");
            if (isset($playermount['mountname'])) {
                $playermount['basename'] = $playermount['mountname'];
                if ($name > "") {
                    $playermount['mountname'] = $name . " `0the " . $playermount['basename'] . "`0";
                    $playermount['newname'] = "{$name}`0";
                }
            }
            break;
        case "bio-mount":
            $name = get_module_pref("mountname", "hunterslodge_namedmount", $args['acctid']);
            if ($name != "") {
                //debug($name);
                if (isset($args['mountname'])) {
                    $args['basename'] = $args['mountname'];
                    if ($name > "") {
                        $args['mountname'] = $name . " `0the " . $args['basename'] . "`0";
                        $args['newname'] = "{$name}`0";
                    }
                }
            }
            break;
    }
    return $args;
}
function asides_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "viewcommentary":
            $tloc = get_module_pref("loc", "commentaryinfo");
            $sloc = get_module_pref("loc", "commentaryinfo", $args['acctid']);
            break;
        case "commentaryoptions":
            if (!strpos($_SERVER['REQUEST_URI'], "char=" . $session['user']['acctid'] . "&")) {
                $link = "bio.php?char=" . $session['user']['acctid'] . "&ret=" . URLEncode($_SERVER['REQUEST_URI']);
                $total = get_module_pref("total");
                $seen = get_module_pref("seen");
                output("`n`n<a href=\"{$link}\">View my Bio</a>", true);
                if ($seen != $total) {
                    $new = $total - $seen;
                    if ($new == 1) {
                        output("(1 unread Natter)");
                    } else {
                        output("(%s unread Natters)", $new);
                    }
                }
                addnav("", $link);
            }
            break;
    }
    return $args;
}
function commentaryicons_donation_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "postcomment":
            $donation = $session['user']['donation'];
            if (get_module_pref("user_showmydonation")) {
                if ($donation >= 2000) {
                    $args['info']['icons']['donator'] = array('icon' => "images/icons/donator/donator3.png", 'mouseover' => "Extra-Awesome Site Supporter");
                } else {
                    if ($donation >= 1000) {
                        $args['info']['icons']['donator'] = array('icon' => "images/icons/donator/donator2.png", 'mouseover' => "Special Site Supporter");
                    } else {
                        if ($donation >= 100) {
                            $args['info']['icons']['donator'] = array('icon' => "images/icons/donator/donator1.png", 'mouseover' => "Site Supporter");
                        }
                    }
                }
            }
            break;
        case "commentbuffer":
            if (!get_module_pref("user_showdonations")) {
                foreach ($args as $line => $details) {
                    if (isset($details['info']['icons']['donator'])) {
                        unset($args[$line]['info']['icons']['donator']);
                    }
                }
            }
            break;
    }
    return $args;
}
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 commentaryicons_armour_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "postcomment":
            if (get_module_pref("user_showmyarmour")) {
                $armourfilename = strtolower($session['user']['armor']);
                $armourfilename = strtr($armourfilename, " '-_.!+1234567890,", "                  ");
                $armourfilename = str_replace(" ", "", $armourfilename);
                $armourfilename = "images/icons/armour/" . $armourfilename . ".png";
                if (file_exists($armourfilename)) {
                    $armour = "<img src=\"" . $armourfilename . "\" alt=\"armour: " . $session['user']['armor'] . "\" title=\"armour: " . $session['user']['armor'] . "\">";
                    $args['info']['mouseover']['armour'] = "`n<img src=\"" . $armourfilename . "\">`n" . $session['user']['armor'] . "`n";
                } else {
                    $armour = "Armour: " . $session['user']['armor'];
                    $args['info']['mouseover']['armour'] = "`nArmour: " . $session['user']['armor'];
                }
                // $args['info']['icons']['armour']=array(
                // 'icon' => $armourfilename,
                // 'mouseover' => "armour: ".$session['user']['armor'],
                // );
            }
            break;
        case "commentbuffer":
            if (!get_module_pref("user_showarmour")) {
                foreach ($args as $line => $details) {
                    if (isset($details['info']['mouseover']['armour'])) {
                        unset($args[$line]['info']['mouseover']['armour']);
                    }
                }
            }
            break;
    }
    return $args;
}
function commentaryicons_race_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "postcomment":
            if (get_module_pref("user_showmyrace")) {
                $racefilename = strtolower($session['user']['race']);
                $racefilename = strtr($racefilename, " '-_.!,", "");
                $racefilename = str_replace(" ", "", $racefilename);
                if ($session['user']['sex'] == 0) {
                    $gender = "m";
                    $gendertitle = "Male";
                } else {
                    $gender = "f";
                    $gendertitle = "Female";
                }
                $racefilename .= $gender;
                $args['info']['icons']['race'] = array('icon' => "images/icons/races/" . $racefilename . ".png", 'mouseover' => $gendertitle . " " . $session['user']['race']);
            }
            break;
        case "commentbuffer":
            if (!get_module_pref("user_showraces")) {
                foreach ($args as $line => $details) {
                    if (isset($details['info']['icons']['race'])) {
                        unset($args[$line]['info']['icons']['race']);
                    }
                }
            }
            break;
    }
    return $args;
}
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 offering_runevent($type)
{
    global $session;
    $session['user']['specialinc'] = "module:offering";
    $seen = get_module_pref("seen");
    $amt = round(max(1, $session['user']['dragonkills'] * 10) * $session['user']['level'] * max(1, 5000 - $session['user']['maxhitpoints']) / 20000);
    $op = httpget('op');
    if ($op == "") {
        output("`7While you are listening to others chatting, a bizarrely-dressed woman approaches with an outstretched hand. `n`n");
        output("\"`&For the offering!!! `^%s `&gold!`7\"", $amt);
        $seen++;
        set_module_pref("seen", $seen);
        addnav(array("Give her %s gold", $amt), "village.php?op=shop");
        addnav("Walk away", "village.php?op=nope");
    } elseif ($op == "nope") {
        output("`7You decide not to give any gold to this strange woman.`n");
        $session['user']['specialinc'] = "";
    } elseif ($session['user']['gold'] < $amt) {
        output("`7The woman stares at your hand.`n`n");
        output("\"`&No no no no no!!! He would not be pleased!!!`7\"`n`n");
        output("`7Without another word, she walks away.`n");
        $session['user']['specialinc'] = "";
    } else {
        output("`7You hand her `^%s`7 gold, and she lifts her head up, looks intently at something above her that only she can see, and whispers, `&\"%s!`&\" `7with apparent urgency.`n`n", $amt, getsetting("deathoverlord", '`$Ramius'));
        output("`7Without another word she scurries off, a determined look on her face, and a purpose in her stride.`n`n");
        if ($session['user']['dragonkills'] > 30) {
            $session['user']['deathpower'] += 10;
        } else {
            $session['user']['deathpower'] += 15;
        }
        $session['user']['gold'] -= $amt;
    }
}
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 aitest_dohook($hookname, $args)
{
    global $session;
    if (get_module_pref("access") || $session['user']['superuser'] & SU_MEGAUSER) {
        addnav("Creature Testing", "runmodule.php?module=aitest&opz=select");
    }
    return $args;
}
function hunterslodge_specialcomments_small_use($args)
{
    global $session;
    increment_module_pref("commentsleft", 4, "specialcomments");
    $left = get_module_pref("commentsleft", "specialcomments");
    output("`0You now have `b%s`b Special Comments left to use.`n`n", $left);
    return $args;
}
function nicotinegum_use($args)
{
    $addiction = get_module_pref("addiction", "smoking");
    $betweensmokes = 250 - $addiction;
    set_module_pref("betweensmokes", $betweensmokes, "smoking");
    apply_buff("smoking", array("allowinpvp" => 1, "allowintrain" => 1, "rounds" => -1, "schema" => "module-smoking"));
    return $args;
}
function hunterslodge_customarmour_run()
{
    require_once "lib/sanitize.php";
    require_once "lib/names.php";
    global $session;
    $op = httpget("op");
    $free = httpget("free");
    page_header("Choose your Custom Armour");
    switch ($op) {
        case "change":
            output("Want to change your Custom Armour?  No problem.  Enter your desired armour in the box below.  You've got 25 characters to play around with.`n(leave this blank to disable custom armour naming and return to default, game-supplied armour names)`n`n");
            rawoutput("<form action='runmodule.php?module=hunterslodge_customarmour&op=confirm&free=" . $free . "' method='POST'>");
            $armour = get_module_pref("customarmour");
            rawoutput("<input id='input' name='newarmour' width='25' maxlength='25' value='" . htmlentities($armour, ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "'>");
            rawoutput("<input type='submit' class='button' value='Preview'>");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=hunterslodge_customarmour&op=confirm&free=" . $free);
            addnav("Cancel");
            addnav("Don't set custom armour, just go back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "confirm":
            $newarmour = httppost("newarmour");
            $sub = httpget("sub");
            $newarmour = str_replace("`", "", $newarmour);
            $newarmour = comment_sanitize($newarmour);
            $newarmour = substr($newarmour, 0, 25);
            if ($newarmour) {
                output("Your new custom armour is:`n%s`nWould you like to set your new armour now?`n`n", $newarmour);
            } else {
                output("You've chosen to go back to the default, game-supplied armours.  Are you sure that's what you want?`n`n");
            }
            addnav("Confirm");
            addnav("Set custom armour", "runmodule.php?module=hunterslodge_customarmour&op=set&free={$free}&newarmour=" . rawurlencode($newarmour));
            addnav("Cancel");
            addnav("Don't set custom armour, just go back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "set":
            $newarmour = rawurldecode(httpget("newarmour"));
            if ($newarmour == "") {
                output("Your custom armour name has been removed.  The next time you change your armour, you'll return to game-supplied armour names.`n`n");
            } else {
                output("Your custom armour has been set to %s!`n`n", $newarmour);
                $session['user']['armor'] = $newarmour;
            }
            set_module_pref("customarmour", $newarmour);
            if (!$free) {
                require_once "modules/iitems/lib/lib.php";
                $id = has_item("hunterslodge_customarmour");
                delete_item($id);
            }
            addnav("Return");
            addnav("Return to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
    }
    page_footer();
}
function achievements_award_medal($sname, $vname, $desc, $icon, $acctid = false)
{
    global $session;
    if (!$acctid) {
        $acctid = $session['user']['acctid'];
    }
    $ach = array("name" => $name, "desc" => $desc, "icon" => $icon);
    $info = unserialize(get_module_pref("achievements", "achievements"));
    $info[$sname] = array($ach);
    set_module_pref("achievements", serialize($info), "achievements", $acctid);
}
function reqmultiplier_change($new)
{
    global $session;
    $old = get_module_pref("multiplier", "reqmultiplier");
    if ($new >= $old) {
        set_module_pref("multiplier", $new, "reqmultiplier");
        return true;
    } else {
        return false;
    }
}