function smoking_dohook($hookname, $args)
{
    global $session;
    $addiction = get_module_pref("addiction");
    $coldturkey = get_module_pref("coldturkey");
    $betweensmokes = get_module_pref("betweensmokes");
    switch ($hookname) {
        case "newday":
            if ($addiction > 0) {
                $addiction = $addiction - $coldturkey;
            }
            if ($addiction > 18) {
                output("`bYou really, really want a cigarette.`b`n`n");
                apply_buff("smoking", array("name" => "`7Nicotine Withdrawal`0", "defmod" => (100 - $addiction) / 100, "atkmod" => (100 - $addiction) / 100, "rounds" => $addiction * 2, "roundmsg" => "You're so distracted by your nicotine cravings that you can't concentrate on the fight!", "schema" => "module-smoking"));
            }
            $coldturkey += 1;
            set_module_pref("addiction", $addiction);
            set_module_pref("coldturkey", $coldturkey);
            set_module_pref("betweensmokes", $betweensmokes);
            break;
        case "forest":
            addnav("!?Have a Smoke", "runmodule.php?module=smoking&from=jungle");
            if (has_buff("smoking")) {
                break;
            }
            $betweensmokes--;
            if ($addiction > 18) {
                if ($betweensmokes < 0) {
                    $betweensmokes = 250 - $addiction;
                    output("`n`bYou really, really want a cigarette.`b`n`n");
                    apply_buff("smoking", array("name" => "`7Nicotine Withdrawal`0", "defmod" => (100 - $addiction) / 100, "atkmod" => (100 - $addiction) / 100, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => $addiction, "roundmsg" => "You're so distracted by your nicotine cravings that you can't concentrate on the fight!", "schema" => "module-smoking"));
                }
            }
            if ($addiction > 0) {
                set_module_pref("betweensmokes", $betweensmokes);
            }
            break;
        case "village":
            addnav($args["gatenav"]);
            addnav("!?Have a Smoke", "runmodule.php?module=smoking&from=outpost");
            if (has_buff("smoking")) {
                break;
            }
            $betweensmokes--;
            if ($addiction > 18) {
                if ($betweensmokes < 0) {
                    $betweensmokes = 250 - $addiction;
                    output("`n`bYou really, really want a cigarette.`b`n`n");
                    apply_buff("smoking", array("name" => "`7Nicotine Withdrawal`0", "defmod" => (100 - $addiction) / 100, "atkmod" => (100 - $addiction) / 100, "allowinpvp" => 1, "allowintrain" => 1, "rounds" => $addiction, "roundmsg" => "You're so distracted by your nicotine cravings that you can't concentrate on the fight!", "schema" => "module-smoking"));
                }
            }
            if ($addiction > 0) {
                set_module_pref("betweensmokes", $betweensmokes);
            }
            break;
    }
    return $args;
}
function improbabilitybomb_use($args)
{
    global $session;
    $effect = e_rand(1, 8);
    if (has_buff("ibomb7a") && $effect == 7) {
        $effect = 3;
    }
    if (has_buff("ibomb8") && $effect == 8) {
        $effect = 3;
    }
    apply_buff('startmsg', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0You light the fuse on the Improbability Bomb and toss it towards your opponent.", "schema" => "improbabilitybomb"));
    switch ($effect) {
        case 1:
            apply_buff('ibomb1', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The bomb bursts into a shower of Requisition tokens!  Blimey, there must be about a thousand of them!  What's more, all these tokens are swirling into the air and nose-diving straight into your pocket.  Result!", "schema" => "improbabilitybomb"));
            $gold = e_rand(900, 1100);
            $session['user']['gold'] += $gold;
            break;
        case 2:
            apply_buff('ibomb2', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The fuse fizzes and sparks, until eventually... it goes out.  The bomb is gone.  However, there's a tasty, tasty cigarette in its place!  You grab it before your enemy gets the chance.", "schema" => "improbabilitybomb"));
            $session['user']['gems']++;
            break;
        case 3:
        case 4:
            apply_buff('ibomb3', array("rounds" => 1, "minioncount" => 1, "minbadguydamage" => "5+round(<attack>*1.0,0);", "maxbadguydamage" => "5+round(<attack>*3.0,0);", "effectmsg" => "`4The bomb explodes close enough to {badguy}`4 to do `^{damage}`4 damage!", "schema" => "improbabilitybomb"));
            break;
        case 5:
            apply_buff('ibomb6', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The Improbability Bomb breaks open, bathing you in a cool white light.  When it fades, you feel calm, self-confident and somehow more attractive.  Pretty useless in a combat situation, but hey, it's nice to be feel good about yourself.  You gain some Charm.", "schema" => "improbabilitybomb"));
            $session['user']['charm'] += 1;
            break;
        case 6:
            apply_buff('ibomb7a', array("rounds" => 4, "minioncount" => 8, "minbadguydamage" => 0, "maxbadguydamage" => 5, "startmsg" => "The bomb begins to roll around the theater of combat, bouncing off rocks like a pinball - and firing out showers of white-hot sparks!", "effectmsg" => "`2A glowing spark leaps onto {badguy}, burning it for {damage} points!", "schema" => "improbabilitybomb", "expireafterfight" => 1));
            apply_buff('ibomb7b', array("rounds" => 4, "minioncount" => 8, "mingoodguydamage" => 0, "maxgoodguydamage" => 5, "effectmsg" => "`4A white-hot spark attaches to you, burning you for {damage} points!", "schema" => "improbabilitybomb", "wearoff" => "The bomb fizzles out and sends out one last dying volley of sparks.", "expireafterfight" => 1));
            break;
        case 7:
            apply_buff('ibomb8', array("startmsg" => "`0The bomb uncurls, revealing a little `5Purple Monster!`0", "rounds" => -1, "name" => "`5Purple Monster`0", "minioncount" => 1, "minbadguydamage" => 5, "maxbadguydamage" => 50, "effectmsg" => "`5The Purple Monster leaps towards {badguy} and bites down hard for {damage} damage!`0", "schema" => "improbabilitybomb", "wearoff" => "`5The Purple Monster, seeing its business here concluded, disappears with a faint 'pop.'`0", "expireafterfight" => 1));
            break;
        case 8:
            $maxdmg = $session['user']['maxhitpoints'] * 2;
            if ($maxdmg < 500) {
                $maxdmg = 500;
            }
            $mindmg = $session['user']['hitpoints'] * 0.5;
            if ($maxdmg < 200) {
                $maxdmg = 200;
            }
            apply_buff('ibomb9', array("rounds" => 1, "minioncount" => 1, "mingoodguydamage" => $mindmg, "maxgoodguydamage" => $maxdmg, "effectmsg" => "`4Before the bomb even leaves your hand, it blows up in your face!  The explosion causes {damage} points!", "schema" => "improbabilitybomb", "expireafterfight" => 1));
            break;
    }
    return $args;
}
function iitems_catcher_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "iitems-use-item":
            if ($args['player']['itemid'] == "zapgrenade") {
                apply_buff('zapgrenade', array("startmsg" => "`#You pull the pin on your grenade and toss it at {badguy}`#, shielding your eyes.  After a blinding flash, your foe is left dazed and confused!", "name" => "`^ZAP Grenade", "rounds" => e_rand(3, 7), "badguyatkmod" => 0.1, "badguydefmod" => 0.1, "roundmsg" => "{badguy} is blinded, deafened and thoroughly confused, and flails wildly while you pummel it!", "wearoff" => "{badguy}`# feels some coherence return, and lunges at you!", "expireafterfight" => 1, "schema" => "iitems-catcher"));
            }
            if ($args['player']['itemid'] == "nicotinegum") {
                $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"));
            }
            if ($args['player']['itemid'] == "oneshotteleporter") {
                require_once "modules/iitems/lib/lib.php";
                iitems_discard_item($args['player']['inv_key']);
                redirect("runmodule.php?module=iitems_catcher&item=oneshotteleporter");
            }
            if ($args['player']['itemid'] == "energydrink") {
                //handle Nutrition adding without invoking extra Edibles functionality
                increment_module_pref("nutrition", 5, "staminafood");
            }
            if ($args['player']['itemid'] == "monsterrepellentspray") {
                if (httpget('skill') == "iitems") {
                    //handle using the item in a fight
                    apply_buff('rspray_fight', array("startmsg" => "`#You pull out a can of Monster Repellent Spray, and spray it liberally on the enemy!`n", "name" => "`^Repellent Spray Attack", "rounds" => 10, "badguyatkmod" => 0.4, "badguydefmod" => 0.4, "roundmsg" => "{badguy} is coughing, choking and all runny-nosed, and cannot attack or defend as effectively!", "wearoff" => "The effects of your Monster Repellent Spray seem to have worn off...`n", "expireafterfight" => 1, "schema" => "iitems-catcher"));
                } else {
                    //handle using the item outside of a fight
                    apply_buff('rspray_normal', array("name" => "`^Repellent Spray", "rounds" => -1, "badguyatkmod" => 0.8, "badguydefmod" => 0.8, "roundmsg" => "{badguy} can't stand the smell of your Monster Repellent Spray, and doesn't want to get too close!", "schema" => "iitems-catcher"));
                    set_module_pref("encounterchance", 50, "worldmapen");
                    output("You liberally douse yourself with an entire can of Monster Repellent Spray.  For the rest of this game day, your chances of encountering a monster on the Island Map have been halved, and monsters you do encounter will be reluctant to attack you as hard.`n`n");
                }
            }
            if ($args['player']['itemid'] == "improbabilitybomb") {
                $effect = e_rand(1, 8);
                if (has_buff("ibomb7a") && $effect == 7) {
                    $effect = 3;
                }
                if (has_buff("ibomb8") && $effect == 8) {
                    $effect = 3;
                }
                apply_buff('startmsg', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0You light the fuse on the Improbability Bomb and toss it towards your opponent.", "schema" => "iitems-catcher"));
                switch ($effect) {
                    case 1:
                        apply_buff('ibomb1', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The bomb bursts into a shower of Requisition tokens!  Blimey, there must be about a thousand of them!  What's more, all these tokens are swirling into the air and nose-diving straight into your pocket.  Result!", "schema" => "iitems-catcher"));
                        $gold = e_rand(900, 1100);
                        $session['user']['gold'] += $gold;
                        break;
                    case 2:
                        apply_buff('ibomb2', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The fuse fizzes and sparks, until eventually... it goes out.  The bomb is gone.  However, there's a tasty, tasty cigarette in its place!  You grab it before your enemy gets the chance.", "schema" => "iitems-catcher"));
                        $session['user']['gems']++;
                        break;
                    case 3:
                        apply_buff('ibomb3', array("rounds" => 1, "minioncount" => 1, "minbadguydamage" => "5+round(<attack>*1.0,0);", "maxbadguydamage" => "5+round(<attack>*3.0,0);", "effectmsg" => "`4The bomb explodes close enough to {badguy}`4 to do `^{damage}`4 damage!", "schema" => "iitems-catcher"));
                        break;
                    case 4:
                    case 5:
                        apply_buff('ibomb6', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The Improbability Bomb breaks open, bathing you in a cool white light.  When it fades, you feel calm, self-confident and somehow more attractive.  Pretty useless in a combat situation, but hey, it's nice to be feel good about yourself.  You gain some Charm.", "schema" => "iitems-catcher"));
                        $session['user']['charm'] += 1;
                        break;
                    case 6:
                        apply_buff('ibomb7a', array("rounds" => 4, "minioncount" => 8, "minbadguydamage" => 0, "maxbadguydamage" => 5, "startmsg" => "The bomb begins to roll around the theater of combat, bouncing off rocks like a pinball - and firing out showers of white-hot sparks!", "effectmsg" => "`2A glowing spark leaps onto {badguy}, burning it for {damage} points!", "schema" => "iitems-catcher", "expireafterfight" => 1));
                        apply_buff('ibomb7b', array("rounds" => 4, "minioncount" => 8, "mingoodguydamage" => 0, "maxgoodguydamage" => 5, "effectmsg" => "`4A white-hot spark attaches to you, burning you for {damage} points!", "schema" => "iitems-catcher", "wearoff" => "The bomb fizzles out and sends out one last dying volley of sparks.", "expireafterfight" => 1));
                        break;
                    case 7:
                        apply_buff('ibomb8', array("startmsg" => "`0The bomb uncurls, revealing a little `5Purple Monster!`0", "rounds" => -1, "name" => "`5Purple Monster`0", "minioncount" => 1, "minbadguydamage" => 5, "maxbadguydamage" => 50, "effectmsg" => "`5The Purple Monster leaps towards {badguy} and bites down hard for {damage} damage!`0", "schema" => "iitems-catcher", "wearoff" => "`5The Purple Monster, seeing its business here concluded, disappears with a faint 'pop.'", "expireafterfight" => 1));
                        break;
                    case 8:
                        $maxdmg = $session['user']['maxhitpoints'] * 2;
                        if ($maxdmg < 500) {
                            $maxdmg = 500;
                        }
                        $mindmg = $session['user']['hitpoints'] * 0.5;
                        if ($maxdmg < 200) {
                            $maxdmg = 200;
                        }
                        apply_buff('ibomb9', array("rounds" => 1, "minioncount" => 1, "mingoodguydamage" => $mindmg, "maxgoodguydamage" => $maxdmg, "effectmsg" => "`4Before the bomb even leaves your hand, it blows up in your face!  The explosion causes {damage} points!", "schema" => "iitems-catcher", "expireafterfight" => 1));
                        break;
                }
            }
            if ($args['player']['itemid'] == "cratesniffer") {
                output("`0You thumb the switch on your Crate Sniffer.  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 - 3;
                $pxhigh = $px + 3;
                $pylow = $py - 3;
                $pyhigh = $py + 3;
                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;
        case "newday":
            set_module_pref("encounterchance", 100, "worldmapen");
            break;
    }
    return $args;
}
function implantservoarms_dohook($hookname, $args)
{
    global $session, $resline;
    $spec = "SR";
    $name = "Servo Arms";
    $ccode = "`&";
    switch ($hookname) {
        case "dragonkill":
            set_module_pref("battery", 0);
            set_module_pref("status", 0);
            break;
        case "choose-specialty":
            if ($session['user']['dragonkills'] < 2) {
                break;
            }
            if ($session['user']['specialty'] == "" || $session['user']['specialty'] == '0') {
                addnav("{$ccode}{$name}`0", "newday.php?setspecialty={$spec}{$resline}");
                output("`5\"The `&Servo Arms`5 implant doesn't go in your brain, but in your spinal column instead.  As you can see, you get two lovely shiny metal arms, to supplement your existing ones.  You can set them to offensive or defensive stances, and can change their settings even in the middle of a fight if you like.  They're battery powered, so they have a finite life, but your master at the Dojo will give you a new battery in exchange for defeating him.\"`n`n");
            }
            set_module_pref("battery", 100);
            set_module_pref("status", 0);
            break;
        case "set-specialty":
            if ($session['user']['specialty'] == $spec) {
                page_header($name);
                output("`&Wow, you've really done it this time.  Other contestants opted for the tiny little chips in their brains but not you, oh no.  You had to go for the enormous servo arms jutting out of your back, didn't you?  Well, don't blame me when you get propositioned by people with rather curious fetishes.`n`nYou can activate or deactivate your Servo Arms, or change their stance, at any time.  But remember, your battery has to last you for a whole level, so don't overdo it.");
            }
            break;
        case "specialtycolor":
            $args[$spec] = $ccode;
            break;
        case "specialtynames":
            $args[$spec] = translate_inline($name);
            break;
        case "specialtymodules":
            $args[$spec] = "implantservoarms";
            break;
        case "incrementspecialty":
            if ($session['user']['specialty'] == $spec) {
                set_module_pref("battery", 100 + $session['user']['level'] * 5);
                output("`&`nYour defeated master hands you a new battery for your Servo Arms!`n");
            }
            break;
        case "fightnav-specialties":
            if ($session['user']['specialty'] == $spec) {
                // Evaluate the number of rounds that the battle has lasted thus far.  Because this is only called once per click, and the user can choose to play five rounds, ten rounds or to the end of the fight, we've got to get the number of rounds by looking at the remaining rounds left in the buff we set up the last time the user clicked to fight.
                if (has_buff("servoarms")) {
                    $roundsplayed = 1000 - $session['bufflist']['battery']['rounds'];
                    set_module_pref("battery", get_module_pref("battery") - $roundsplayed);
                    if (get_module_pref("battery") < 0) {
                        set_module_pref("battery", 0);
                        set_module_pref("status", 0);
                        strip_buff('servoarms');
                    }
                } else {
                    $roundsplayed = 0;
                }
                apply_buff('battery', array("rounds" => 1000, "dmgmod" => 1));
                $script = $args['script'];
                $battery = get_module_pref("battery");
                $status = get_module_pref("status");
                addnav(array("{$ccode} `bServo Arms`b", ""));
                addnav(array("{$ccode} Battery: %s", $battery), "");
                if ($status == 0 && $battery > 0) {
                    addnav("{$ccode} Stance: Off", "");
                    addnav(array("{$ccode} Set to Offensive stance`0"), $script . "op=fight&skill={$spec}&l=1", true);
                    addnav(array("{$ccode} Set to Defensive stance`0"), $script . "op=fight&skill={$spec}&l=2", true);
                }
                if ($status == 1 && $battery > 0) {
                    addnav("{$ccode} Stance: Offensive", "");
                    addnav(array("{$ccode} Set to Defensive stance`0"), $script . "op=fight&skill={$spec}&l=2", true);
                    addnav(array("{$ccode} Turn Servos Off`0"), $script . "op=fight&skill={$spec}&l=0", true);
                }
                if ($status == 2 && $battery > 0) {
                    addnav("{$ccode} Stance: Defensive", "");
                    addnav(array("{$ccode} Set to Offensive stance`0"), $script . "op=fight&skill={$spec}&l=1", true);
                    addnav(array("{$ccode} Turn Servos Off`0"), $script . "op=fight&skill={$spec}&l=0", true);
                }
            }
            break;
        case "apply-specialties":
            if ($session['user']['specialty'] == $spec) {
                $skill = httpget('skill');
                $l = httpget('l');
                if ($skill == $spec) {
                    switch ($l) {
                        case "1":
                            if (get_module_pref("battery") > 0) {
                                apply_buff('servoarms', array("startmsg" => "`&Your Servo Arms swing around in front of you, ready to attack {badguy}!", "name" => "`&Servo Arms", "atkmod" => "1.25", "rounds" => -1, "schema" => "module-implantlaser"));
                                set_module_pref("status", 1);
                            } else {
                                output("`&Your Servo Arms batteries are DEAD!");
                            }
                            break;
                        case "2":
                            if (get_module_pref("battery") > 0) {
                                apply_buff('servoarms', array("startmsg" => "`&Your Servo Arms swing around in front of you, ready to defend against {badguy}!", "name" => "`&Servo Arms", "defmod" => "1.25", "rounds" => -1, "schema" => "module-implantlaser"));
                                set_module_pref("status", 2);
                            } else {
                                output("`&Your Servo Arms batteries are DEAD!");
                            }
                            break;
                        case "0":
                            set_module_pref("status", 0);
                            strip_buff('servoarms');
                            break;
                    }
                }
            }
            break;
        case "battle-defeat":
        case "battle-victory":
            if ($session['user']['specialty'] == $spec) {
                if (has_buff("servoarms")) {
                    $roundsplayed = 1000 - $session['bufflist']['battery']['rounds'];
                    set_module_pref("battery", get_module_pref("battery") - $roundsplayed);
                    if (get_module_pref("battery") < 0) {
                        set_module_pref("battery", 0);
                    }
                    set_module_pref("status", 0);
                    strip_buff('servoarms');
                    output("`&Your Servo Arms neatly turn themselves back behind your back, to save on battery power.`n");
                }
            }
            break;
        case "newday":
        case "village":
            set_module_pref("status", 0);
            strip_buff('servoarms');
            break;
    }
    return $args;
}
function improbablestuff_dohook($hookname, $args)
{
    global $session;
    $smallmedkit = get_module_pref("item1number");
    $largemedkit = get_module_pref("item2number");
    $energydrink = get_module_pref("item3number");
    $nicotinegum = get_module_pref("item4number");
    $potentpill = get_module_pref("item5number");
    $teleporter = get_module_pref("item6number");
    $banggrenade = get_module_pref("item7number");
    $whoomphgrenade = get_module_pref("item8number");
    $zapgrenade = get_module_pref("item9number");
    $repellantspray = get_module_pref("item10number");
    $rationpack = get_module_pref("item11number");
    $improbabilitybomb = get_module_pref("item12number");
    $kittencard = get_module_pref("item13number");
    $traveladd = get_module_pref("traveladd");
    $spec = "improbablestuff";
    switch ($hookname) {
        case "forest":
            if ($smallmedkit >= 1 || $largemedkit >= 1 || $energydrink >= 1 || $nicotinegum >= 1 || $potentpill >= 1 || $repellantspray >= 1 || $rationpack >= 1) {
                addnav("`0`bUse Equipment`b`0");
            }
            if ($smallmedkit > 0) {
                addnav(array("Use Small Medkit (%s remaining)", $smallmedkit), "runmodule.php?module=improbablestuff&use=smallmedkit&from=forest");
            }
            if ($largemedkit > 0) {
                addnav(array("Use Large Medkit (%s remaining)", $largemedkit), "runmodule.php?module=improbablestuff&use=largemedkit&from=forest");
            }
            if ($energydrink > 0) {
                addnav(array("Use Energy Drink (%s remaining)", $energydrink), "runmodule.php?module=improbablestuff&use=energydrink&from=forest");
            }
            if ($nicotinegum > 0) {
                addnav(array("Use Nicotine Gum (%s remaining)", $nicotinegum), "runmodule.php?module=improbablestuff&use=nicotinegum&from=forest");
            }
            if ($potentpill > 0) {
                addnav(array("Use Power Pill (%s remaining)", $potentpill), "runmodule.php?module=improbablestuff&use=potentpill&from=forest");
            }
            if ($teleporter > 0) {
                addnav(array("Use One-Shot Teleporter (%s remaining)", $teleporter), "runmodule.php?module=improbablestuff&use=teleporter", true);
            }
            if ($session['user']['race'] != "Robot" && $session['user']['race'] != "Gobot" && $session['user']['race'] != "Foebot" && $session['user']['race'] != "Joker" && $session['user']['race'] != "Stranger" && $rationpack > 0 && get_module_pref("fullness", "staminafood") < 100) {
                addnav(array("Use Ration Pack (%s remaining)", $rationpack), "runmodule.php?module=improbablestuff&use=rationpack&from=forest", true);
            }
            if ($repellantspray > 0) {
                addnav(array("Use Monster Repellant Spray (%s remaining)", $repellantspray), "runmodule.php?module=improbablestuff&use=repellantspray&from=forest");
            }
            break;
        case "village":
            if ($smallmedkit >= 1 || $largemedkit >= 1 || $energydrink >= 1 || $nicotinegum >= 1 || $potentpill >= 1 || $repellantspray >= 1 || $rationpack >= 1) {
                addnav("`0`bUse Equipment`b`0");
            }
            if ($smallmedkit > 0) {
                addnav(array("Use Small Medkit (%s remaining)", $smallmedkit), "runmodule.php?module=improbablestuff&use=smallmedkit&from=village");
            }
            if ($largemedkit > 0) {
                addnav(array("Use Large Medkit (%s remaining)", $largemedkit), "runmodule.php?module=improbablestuff&use=largemedkit&from=village");
            }
            if ($energydrink > 0) {
                addnav(array("Use Energy Drink (%s remaining)", $energydrink), "runmodule.php?module=improbablestuff&use=energydrink&from=village");
            }
            if ($nicotinegum > 0) {
                addnav(array("Use Nicotine Gum (%s remaining)", $nicotinegum), "runmodule.php?module=improbablestuff&use=nicotinegum&from=village");
            }
            if ($potentpill > 0) {
                addnav(array("Use Power Pill (%s remaining)", $potentpill), "runmodule.php?module=improbablestuff&use=potentpill&from=village");
            }
            if ($teleporter > 0) {
                addnav(array("Use One-Shot Teleporter (%s remaining)", $teleporter), "runmodule.php?module=improbablestuff&use=teleporter", true);
            }
            if ($session['user']['race'] != "Robot" && $session['user']['race'] != "Gobot" && $session['user']['race'] != "Foebot" && $session['user']['race'] != "Joker" && $session['user']['race'] != "Stranger" && $rationpack > 0 && get_module_pref("fullness", "staminafood") < 100) {
                addnav(array("Use Ration Pack (%s remaining)", $rationpack), "runmodule.php?module=improbablestuff&use=rationpack&from=village", true);
            }
            if ($repellantspray > 0) {
                addnav(array("Use Monster Repellant Spray (%s remaining)", $repellantspray), "runmodule.php?module=improbablestuff&use=repellantspray&from=village");
            }
            strip_buff('ibomb7a');
            strip_buff('ibomb7b');
            strip_buff('ibomb8');
            break;
        case "worldnav":
            if ($smallmedkit >= 1 || $largemedkit >= 1 || $energydrink >= 1 || $nicotinegum >= 1 || $potentpill >= 1 || $repellantspray >= 1 || $rationpack >= 1) {
                addnav("`0`bUse Equipment`b`0");
            }
            if ($smallmedkit > 0) {
                addnav(array("Use Small Medkit (%s remaining)", $smallmedkit), "runmodule.php?module=improbablestuff&use=smallmedkit&from=worldnav");
            }
            if ($largemedkit > 0) {
                addnav(array("Use Large Medkit (%s remaining)", $largemedkit), "runmodule.php?module=improbablestuff&use=largemedkit&from=worldnav");
            }
            if ($energydrink > 0) {
                addnav(array("Use Energy Drink (%s remaining)", $energydrink), "runmodule.php?module=improbablestuff&use=energydrink&from=worldnav");
            }
            if ($nicotinegum > 0) {
                addnav(array("Use Nicotine Gum (%s remaining)", $nicotinegum), "runmodule.php?module=improbablestuff&use=nicotinegum&from=worldnav");
            }
            if ($potentpill > 0) {
                addnav(array("Use Power Pill (%s remaining)", $potentpill), "runmodule.php?module=improbablestuff&use=potentpill&from=worldnav");
            }
            if ($teleporter > 0) {
                addnav(array("Use One-Shot Teleporter (%s remaining)", $teleporter), "runmodule.php?module=improbablestuff&use=teleporter", true);
            }
            if ($session['user']['race'] != "Robot" && $session['user']['race'] != "Gobot" && $session['user']['race'] != "Foebot" && $session['user']['race'] != "Joker" && $session['user']['race'] != "Stranger" && $rationpack > 0 && get_module_pref("fullness", "staminafood") < 100) {
                addnav(array("Use Ration Pack (%s remaining)", $rationpack), "runmodule.php?module=improbablestuff&use=rationpack&from=worldnav", true);
            }
            if ($repellantspray > 0) {
                addnav(array("Use Monster Repellant Spray (%s remaining)", $repellantspray), "runmodule.php?module=improbablestuff&use=repellantspray&from=worldnav");
            }
            break;
        case "fightnav-specialties":
            $script = $args['script'];
            if ($banggrenade >= 1 || $whoomphgrenade >= 1 || $zapgrenade >= 1 || $teleporter >= 1 || $potentpill >= 1 || $repellantspray >= 1) {
                addnav("`0`bUse Equipment`b`0");
            }
            if ($banggrenade >= 1) {
                addnav(array("`4BANG Grenade`7 (%s left)`0", $banggrenade), $script . "op=fight&skill={$spec}&l=1", true);
            }
            if ($whoomphgrenade >= 1) {
                addnav(array("`^WHOOMPH Grenade`7 (%s left)`0", $whoomphgrenade), $script . "op=fight&skill={$spec}&l=2", true);
            }
            if ($zapgrenade >= 1) {
                addnav(array("`#ZAP Grenade`7 (%s left)`0", $zapgrenade), $script . "op=fight&skill={$spec}&l=3", true);
            }
            if ($potentpill >= 1) {
                addnav(array("Use Power Pill (%s remaining)", $potentpill), $script . "op=fight&skill={$spec}&l=4", true);
            }
            if ($teleporter >= 1) {
                addnav(array("`7One-Shot Teleporter`7 (%s left)`0", $teleporter), "runmodule.php?module=improbablestuff&use=teleporter", true);
            }
            if ($repellantspray >= 1) {
                addnav(array("Use Monster Repellant Spray (%s remaining)", $repellantspray), $script . "op=fight&skill={$spec}&l=5", true);
            }
            if ($improbabilitybomb >= 1) {
                addnav(array("Use Improbability Bomb (%s remaining)", $improbabilitybomb), $script . "op=fight&skill={$spec}&l=6", true);
            }
            break;
        case "ramiusfavors":
            if ($kittencard >= 1) {
                addnav("Other");
                addnav(array("K?`0Give `\$The Watcher`0 a Kitten Card (%s left)`0", $kittencard), "runmodule.php?module=improbablestuff&use=kittencard", true);
            }
            break;
        case "newday":
            set_module_pref("traveladd", 0);
            set_module_pref("encounterchance", 100, "worldmapen");
            set_module_pref("repellantbuff", 100);
            break;
        case "dragonkill":
            set_module_pref("item1number", 0);
            set_module_pref("item2number", 0);
            set_module_pref("item3number", 0);
            set_module_pref("item4number", 0);
            set_module_pref("item5number", 0);
            set_module_pref("item6number", 0);
            set_module_pref("item7number", 0);
            set_module_pref("item8number", 0);
            set_module_pref("item9number", 0);
            set_module_pref("item10number", 0);
            set_module_pref("item11number", 0);
            set_module_pref("item12number", 0);
            set_module_pref("item13number", 0);
            set_module_pref("traveladd", 0);
            set_module_pref("encounterchance", 100, "worldmapen");
            set_module_pref("repellantbuff", 100);
            break;
        case "apply-specialties":
            $skill = httpget('skill');
            $l = httpget('l');
            if ($skill == $spec) {
                if ($banggrenade >= 1) {
                    switch ($l) {
                        case 1:
                            apply_buff('is1', array("startmsg" => "`4You pull the pin on your grenade and toss it at {badguy}!", "rounds" => 1, "minioncount" => 1, "minbadguydamage" => "5+round(<attack>*1.0,0);", "maxbadguydamage" => "10+round(<attack>*2.0,0);", "effectmsg" => "`4The grenade explodes close enough to {badguy}`4 to do `^{damage}`4 damage!", "schema" => "module-improbablestuff"));
                            set_module_pref("item7number", get_module_pref("item7number") - 1);
                            break;
                    }
                }
                if ($whoomphgrenade >= 1) {
                    switch ($l) {
                        case 2:
                            apply_buff('is2', array("startmsg" => "`^You pull the pin on your grenade and toss it at {badguy}.  The grenade explodes with a satisfying WHOOMPH, close enough to set your foe aflame!", "name" => "`^WHOOMPH Grenade", "rounds" => -1, "minioncount" => 1, "minbadguydamage" => "1+round(<attack>*0.1,0);", "maxbadguydamage" => "2+round(<attack>*0.4,0);", "effectmsg" => "`^Your enemy beats at the flames, but it's still on fire!  `^{damage}`^ damage has been done in this round!", "expireafterfight" => 1, "schema" => "module-improbablestuff"));
                            set_module_pref("item8number", get_module_pref("item8number") - 1);
                            break;
                    }
                }
                if ($zapgrenade >= 1) {
                    switch ($l) {
                        case 3:
                            apply_buff('is3', array("startmsg" => "`#You pull the pin on your grenade and toss it at {badguy}`#, shielding your eyes.  After a blinding flash, your foe is left dazed and confused!", "name" => "`^ZAP Grenade", "rounds" => e_rand(2, 7), "badguyatkmod" => 0, "badguydefmod" => 0, "roundmsg" => "{badguy} is blinded, deafened and thoroughly confused, and flails wildly while you pummel it!`n", "wearoff" => "{badguy}`# feels some coherence return, and lunges at you!`n", "expireafterfight" => 1, "schema" => "module-improbablestuff"));
                            set_module_pref("item9number", get_module_pref("item9number") - 1);
                            break;
                    }
                }
                if ($potentpill >= 1) {
                    switch ($l) {
                        case 4:
                            apply_buff('is4', array("startmsg" => "`#You hastily swallow a Power Pill.  You feel immediately revitalised!  You regain some Stamina, and you are now regenerating some hitpoints!`n", "name" => "`^Power Pill", "rounds" => 10, "regen" => "ceil(<maxhitpoints>/10)+1;", "effectmsg" => "The effects of the Power Pill heal you for {damage} points.", "wearoff" => "The Power Pill effects have worn off.`n", "schema" => "module-improbablestuff"));
                            set_module_pref("item5number", get_module_pref("item5number") - 1);
                            require_once "modules/staminasystem/lib/lib.php";
                            addstamina(250000);
                            break;
                    }
                }
                if ($repellantspray >= 1) {
                    switch ($l) {
                        case 5:
                            apply_buff('is5', array("startmsg" => "`#You pull out a can of Monster Repellant Spray, and spray it liberally on the enemy!`n", "name" => "`^Repellant Spray", "rounds" => 10, "badguyatkmod" => 0.5, "badguydefmod" => 0.5, "roundmsg" => "{badguy} is coughing, choking and all runny-nosed, and cannot attack or defend as effectively!", "wearoff" => "The effects of your Monster Repellant Spray seem to have worn off...`n", "expireafterfight" => 1, "schema" => "module-improbablestuff"));
                            set_module_pref("item10number", get_module_pref("item10number") - 1);
                            break;
                    }
                }
                if ($improbabilitybomb >= 1) {
                    switch ($l) {
                        case 6:
                            $effect = e_rand(1, 9);
                            if (has_buff("ibomb7a") && $effect == 7) {
                                $effect = 3;
                            }
                            if (has_buff("ibomb8") && $effect == 8) {
                                $effect = 3;
                            }
                            apply_buff('startmsg', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0You light the fuse on the Improbability Bomb and toss it towards your opponent.", "schema" => "module-improbablestuff"));
                            increment_module_pref("item12number", -1);
                            switch ($effect) {
                                case 1:
                                    apply_buff('ibomb1', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The bomb bursts into a shower of Requisition tokens!  Blimey, there must be about a thousand of them!  What's more, all these tokens are swirling into the air and nose-diving straight into your pocket.  Result!", "schema" => "module-improbablestuff"));
                                    $gold = e_rand(900, 1100);
                                    $session['user']['gold'] += $gold;
                                    break;
                                case 2:
                                    apply_buff('ibomb2', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The fuse fizzes and sparks, until eventually... it goes out.  The bomb is gone.  However, there's a tasty, tasty cigarette in its place!  You grab it before your enemy gets the chance.", "schema" => "module-improbablestuff"));
                                    $session['user']['gems']++;
                                    break;
                                case 3:
                                    apply_buff('ibomb3', array("rounds" => 1, "minioncount" => 1, "minbadguydamage" => "5+round(<attack>*1.0,0);", "maxbadguydamage" => "5+round(<attack>*3.0,0);", "effectmsg" => "`4The bomb explodes close enough to {badguy}`4 to do `^{damage}`4 damage!", "schema" => "module-improbablestuff"));
                                    break;
                                case 4:
                                    apply_buff('ibomb4', array("rounds" => 1, "minioncount" => 1, "minbadguydamage" => 1000000, "maxbadguydamage" => 1000000000, "effectmsg" => "`4The fuse fizzles down until the bomb ignites with an tiny, dense explosion.  The gravity well draws {badguy}`4 in!  Within moments, {badguy} fuses with the matter that made up the original bomb in an ultra-dense, ultra-high gravity ball of dark matter, which then pops with a faint \"crack,\" leaving behind only a smoking area of burned ground about the size of a penny.  The damage done to the enemy, as if it matters at this stage, was `^{damage}`4 points!", "schema" => "module-improbablestuff"));
                                    break;
                                case 5:
                                    redirect("runmodule.php?module=improbablestuff&use=teleporter&bomb=1");
                                    break;
                                case 6:
                                    apply_buff('ibomb6', array("rounds" => 1, "atkmod" => 1, "startmsg" => "`0The Improbability Bomb breaks open, bathing you in a cool white light.  When it fades, you feel calm, self-confident and somehow more attractive.  Pretty useless in a combat situation, but hey, it's nice to be feel good about yourself.  You gain some Charm.", "schema" => "module-improbablestuff"));
                                    $session['user']['charm'] += 2;
                                    break;
                                case 7:
                                    apply_buff('ibomb7a', array("rounds" => 4, "minioncount" => 8, "minbadguydamage" => 0, "maxbadguydamage" => 5, "startmsg" => "The bomb begins to roll around the theater of combat, bouncing off rocks like a pinball - and firing out showers of white-hot sparks!", "effectmsg" => "`2A glowing spark leaps onto {badguy}, burning it for {damage} points!", "schema" => "module-improbablestuff", "expireafterfight" => 1));
                                    apply_buff('ibomb7b', array("rounds" => 4, "minioncount" => 8, "mingoodguydamage" => 0, "maxgoodguydamage" => 5, "effectmsg" => "`4A white-hot spark attaches to you, burning you for {damage} points!", "schema" => "module-improbablestuff", "wearoff" => "The bomb fizzles out and sends out one last dying volley of sparks.", "expireafterfight" => 1));
                                    break;
                                case 8:
                                    apply_buff('ibomb8', array("startmsg" => "`0The bomb uncurls, revealing a little `5Purple Monster!`0", "rounds" => -1, "name" => "`5Purple Monster`0", "minioncount" => 1, "minbadguydamage" => 5, "maxbadguydamage" => 50, "effectmsg" => "`5The Purple Monster leaps towards {badguy} and bites down hard for {damage} damage!`0", "schema" => "module-improbablestuff", "wearoff" => "`5The Purple Monster, seeing its business here concluded, disappears with a faint 'pop.'", "expireafterfight" => 1));
                                    break;
                                case 9:
                                    apply_buff('ibomb9', array("rounds" => 1, "minioncount" => 1, "mingoodguydamage" => 100, "maxgoodguydamage" => 500, "effectmsg" => "`4Before the bomb even leaves your hand, it blows up in your face!  The explosion causes {damage} points!", "schema" => "module-improbablestuff", "expireafterfight" => 1));
                                    break;
                            }
                            break;
                    }
                }
            }
            break;
    }
    return $args;
}
function implantspatialawareness_dohook($hookname, $args)
{
    global $session, $resline;
    $spec = "SA";
    $name = "Spatial Awareness";
    $ccode = "`Q";
    switch ($hookname) {
        case "dragonkill":
            set_module_pref("uses", 0);
            set_module_pref("skill", 0);
            break;
        case "choose-specialty":
            if ($session['user']['specialty'] == "" || $session['user']['specialty'] == '0') {
                addnav("{$ccode}{$name}`0", "newday.php?setspecialty={$spec}{$resline}");
                output("`5\"This, here, is a `QSpatial Awareness`5 implant.  As you grow in strength and combat efficacy, you'll learn how to use it in combination with your own heightened senses.  This Implant works just like the old Season One implants, if that means anything to you.  It's a very simple Implant, good for beginners.  It's only good for combat use.\"`n`n");
            }
            break;
        case "set-specialty":
            if ($session['user']['specialty'] == $spec) {
                page_header($name);
                output("`QInside your head is a tiny microcontroller that heightens your perception in combat.  It has a limited battery charge, but will recharge itself overnight.  As you level up in your combat skills, you'll unlock new abilities.`n`nRemember, this Implant doesn't do anything on its own, but complements your existing combat skill, so levelling up is the only way to make it more effective.");
            }
            break;
        case "specialtycolor":
            $args[$spec] = $ccode;
            break;
        case "specialtynames":
            $args[$spec] = translate_inline($name);
            break;
        case "specialtymodules":
            $args[$spec] = "implantspatialawareness";
            break;
        case "incrementspecialty":
            if ($session['user']['specialty'] == $spec) {
                $new = get_module_pref("skill") + 1;
                set_module_pref("skill", $new);
                $c = $args['color'];
                $name = translate_inline($name);
                output("`n%sYou gain a level in `&%s%s to `#%s%s!", $c, $name, $c, $new, $c);
                $x = $new % 3;
                if ($x == 0) {
                    output("`n`^You gain an extra use point!`n");
                    set_module_pref("uses", get_module_pref("uses") + 1);
                } else {
                    if (3 - $x == 1) {
                        output("`n`^Only 1 more skill level until you gain an extra use point!`n");
                    } else {
                        output("`n`^Only %s more skill levels until you gain an extra use point!`n", 3 - $x);
                    }
                }
                output_notl("`0");
            }
            break;
        case "newday":
            $bonus = getsetting("specialtybonus", 1);
            if ($session['user']['specialty'] == $spec) {
                $name = translate_inline($name);
                if ($bonus == 1) {
                    output("`n`2For having the %s%s`2 implant, you receive `^1`2 extra %s%s`2 use for today.`n", $ccode, $name, $ccode, $name);
                } else {
                    output("`n`2For having the %s%s`2 implant, you receive `^%s`2 extra %s%s`2 uses for today.`n", $ccode, $name, $bonus, $ccode, $name);
                }
            }
            $amt = (int) (get_module_pref("skill") / 3);
            if ($session['user']['specialty'] == $spec) {
                $amt = $amt + $bonus;
            }
            set_module_pref("uses", $amt);
            break;
        case "fightnav-specialties":
            $uses = get_module_pref("uses");
            $script = $args['script'];
            if ($uses > 0) {
                addnav(array("{$ccode}{$name} (%s points)`0", $uses), "");
                addnav(array("{$ccode} &#149; Requisition Search`7 (%s)`0", 1), $script . "op=fight&skill={$spec}&l=1", true);
            }
            if ($uses > 1) {
                addnav(array("{$ccode} &#149; Pressure Points`7 (%s)`0", 2), $script . "op=fight&skill={$spec}&l=2", true);
            }
            if ($uses > 2) {
                addnav(array("{$ccode} &#149; Nimble`7 (%s)`0", 3), $script . "op=fight&skill={$spec}&l=3", true);
            }
            if ($uses > 4) {
                addnav(array("{$ccode} &#149; StandStill`7 (%s)`0", 5), $script . "op=fight&skill={$spec}&l=5", true);
            }
            break;
        case "battle-victory":
            $name = "SA1";
            if (has_buff($name)) {
                $x = 10;
                $y = 40;
                $amount = e_rand($x, $y);
                $amount = $amount * $session['user']['level'];
                output("`Q`nUsing your powers of Spatial Awareness, you find an additional `^%s Requisition`Q dropped by less perceptive players!`0`n", $amount);
                $session['user']['gold'] += $amount;
                strip_buff($name);
            }
            break;
        case "apply-specialties":
            $skill = httpget('skill');
            $l = httpget('l');
            if ($skill == $spec) {
                if (get_module_pref("uses") >= $l) {
                    switch ($l) {
                        case 1:
                            apply_buff('SA1', array("startmsg" => "`QYou ramp up your awareness of your surroundings.  You notice all the coins that other contestants have left lying beneath leaves, under logs, all over the area.  You resolve to pick them up, just as soon as you've dispatched this foe...", "name" => "Requisition Search", "rounds" => -1, "schema" => "module-implantspatialawareness"));
                            break;
                        case 2:
                            apply_buff('SA2', array("startmsg" => "`QYou step back, parrying your enemy's furious thrusts, and take a second or two to look it up and down, locating its weakest points...", "name" => "`QPressure Points", "rounds" => 10, "wearoff" => "`QYour concentration fades, and your knowledge of {badguy}'s pressure points seems to fade away.", "atkmod" => 1.2, "roundmsg" => "`QYou strike {badguy} directly on a vital pressure point, causing serious damage!", "schema" => "module-implantspatialawareness"));
                            break;
                        case 3:
                            apply_buff('SA3', array("startmsg" => "`QYou breathe deeply, concentrate, plan a course of action that will leave your foe bewildered and unable to strike, and begin to move your feet...", "name" => "`QNimble", "rounds" => 10, "defmod" => 1.4, "roundmsg" => "`QYou move so fast that {badguy} can only land glancing blows!", "wearoff" => "`QYour body can no longer keep up with your mind - you're exhausted, and your Nimbleness wears off.", "schema" => "module-implantspatialawareness"));
                            break;
                        case 5:
                            apply_buff('SA5', array("startmsg" => "`QYou stop, meditate for a moment, and open your eyes.  {badguy} is running towards you, so slowly that it's like your foe is running through oil.  You smile, and launch attack after attack while time is slowed down.", "name" => "`QStandStill", "rounds" => 1, "minioncount" => round(e_rand(5, 10)), "minbadguydamage" => "round(<attack>*0.5,0);", "maxbadguydamage" => "round(<attack>,0);", "effectmsg" => "`QYou take advantage of your speeded-up state to attack {badguy}`Q again, causing a further `^{damage} `Qdamage!", "wearoff" => "`QYour concentration fades; {badguy} seems to speed up again, and lunges at you.", "schema" => "module-implantspatialawareness"));
                            break;
                    }
                    set_module_pref("uses", get_module_pref("uses") - $l);
                } else {
                    apply_buff('SA0', array("startmsg" => "Exhausted, you try to bluff.  'I can kill you with my mind,' you call out in what you hope is a sinister voice.  {badguy} looks at you for a minute, thinking, then shrugs.  Laughing, it swings at you again.", "rounds" => 1, "schema" => "module-implantspatialawareness"));
                }
            }
            break;
    }
    return $args;
}
function implantchemicalpack_dohook($hookname, $args)
{
    global $session, $resline;
    $spec = "CP";
    $name = "Chemical Pack";
    $ccode = "`2";
    switch ($hookname) {
        case "choose-specialty":
            if ($session['user']['specialty'] == "" || $session['user']['specialty'] == '0') {
                addnav("Chemical Pack", "newday.php?setspecialty=CP{$resline}");
                output("`5\"This is your basic `2Chemical Pack`5 implant.  This one is a Combat-orientated Implant, and doesn't have any use outside of a combat situation.  It's basically a set of three little vials inside your head, with doses of morphine, adrenaline, and another little secret.  It's powered by endorphins and adrenaline, so the more you get hurt, and the longer you go without medical help, the more you'll be able to use the Implant.  The effects are quite weak, but it's at its most useful when you're in desperate need of it.\"`n`n");
            }
            break;
        case "set-specialty":
            if ($session['user']['specialty'] == "CP") {
                page_header("Chemical Pack");
                output("`2Inside your head is a rather curious little set of three different chemical vials.  One will increase your attack power, one will improve your defensive power, and one will allow you to regenerate some hitpoints.`n`nThe more you use this Implant, the more potent its effects will be.");
                set_module_pref("charge", 0);
                set_module_pref("maxcharge", 1000);
            }
            break;
        case "specialtycolor":
            $args[$spec] = $ccode;
            break;
        case "specialtynames":
            $args[$spec] = translate_inline($name);
            break;
        case "specialtymodules":
            $args[$spec] = "implantchemicalpack";
            break;
        case "endofround":
            $damage = $session['user']['maxhitpoints'] - $session['user']['hitpoints'];
            $charge = round($damage / $session['user']['maxhitpoints'] * 100);
            if ($charge > 0) {
                increment_module_pref("charge", $charge);
                if (get_module_pref("charge") > get_module_pref("maxcharge")) {
                    set_module_pref("charge", get_module_pref("maxcharge"));
                }
            }
            break;
        case "fightnav-specialties":
            if ($session['user']['specialty'] == $spec) {
                $charge = get_module_pref("charge");
                $maxcharge = get_module_pref("maxcharge");
                $script = $args['script'];
                $barnav = "<table cellpadding='0' cellspacing='0'><tr><td>";
                if ($charge < 800) {
                    $pct = $charge / 800 * 100;
                    $nonpct = 100 - $pct;
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                } else {
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                }
                if ($charge < 1000) {
                    $pct = $charge / 1000 * 100;
                    $nonpct = 100 - $pct;
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                } else {
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                }
                if ($charge < 2000) {
                    $pct = $charge / 2000 * 100;
                    $nonpct = 100 - $pct;
                    if ($maxcharge >= 2000) {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                    } else {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#555555' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#999999'></td><td width='{$nonpct}'></td></tr></table>";
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#555555' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#999999'></td><td width='{$nonpct}'></td></tr></table>";
                    }
                } else {
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                }
                if ($charge < 2500) {
                    $pct = $charge / 2500 * 100;
                    $nonpct = 100 - $pct;
                    if ($maxcharge >= 2500) {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                    } else {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#555555' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#999999'></td><td width='{$nonpct}'></td></tr></table>";
                    }
                } else {
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                }
                if ($charge < 6000) {
                    $pct = $charge / 6000 * 100;
                    $nonpct = 100 - $pct;
                    if ($maxcharge >= 6000) {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#cc0000' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#ffff00'></td><td width='{$nonpct}'></td></tr></table>";
                    } else {
                        $barnav .= "<table style='border: solid 1px #000000' bgcolor='#555555' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td width='{$pct}' bgcolor='#999999'></td><td width='{$nonpct}'></td></tr></table>";
                    }
                } else {
                    $barnav .= "<table style='border: solid 1px #000000' bgcolor='#00ff00' cellpadding='0' cellspacing='0' width='70' height='5'><tr><td></td></tr></table>";
                }
                $barnav .= "</tr></td></table>";
                addnav(array("Chemical Pack (%s/%s)", $charge, $maxcharge), "");
                addnav(array("%s", $barnav), "", true);
                if ($charge >= 800) {
                    if (!has_buff("CP1") && !has_buff("CP4")) {
                        addnav(array("Adrenaline Lv 1 (800)"), $script . "op=fight&skill={$spec}&l=1");
                    }
                    if (!has_buff("CP2") && !has_buff("CP5")) {
                        addnav(array("Painkillers Lv 1 (800)"), $script . "op=fight&skill={$spec}&l=2");
                    }
                }
                if ($charge >= 1000) {
                    if (!has_buff("CP3") && !has_buff("CP6")) {
                        addnav(array("StimPack Lv 1 (1000)"), $script . "op=fight&skill={$spec}&l=3");
                    }
                }
                if ($charge >= 2000) {
                    if (!has_buff("CP4") && !has_buff("CP1")) {
                        addnav(array("Adrenaline Lv 2 (2000)"), $script . "op=fight&skill={$spec}&l=4");
                    }
                    if (!has_buff("CP5") && !has_buff("CP2")) {
                        addnav(array("Painkillers Lv 2 (2000)"), $script . "op=fight&skill={$spec}&l=5");
                    }
                }
                if ($charge >= 2500) {
                    if (!has_buff("CP6") && !has_buff("CP3")) {
                        addnav(array("StimPack Lv 2 (2500)"), $script . "op=fight&skill={$spec}&l=6");
                    }
                }
                if ($charge >= 6000) {
                    if (!has_buff("CP7")) {
                        addnav(array("Chemical High (6000)"), $script . "op=fight&skill={$spec}&l=7");
                    }
                }
            }
            break;
            // case "fightnav-specialties":
            // if($session['user']['specialty'] == $spec) {
            // $charge = get_module_pref("charge");
            // $maxcharge = get_module_pref("maxcharge");
            // $script = $args['script'];
            // addnav(array("Chemical Pack (%s/%s)", $charge, $maxcharge));
            // }
            // break;
        // case "fightnav-specialties":
        // if($session['user']['specialty'] == $spec) {
        // $charge = get_module_pref("charge");
        // $maxcharge = get_module_pref("maxcharge");
        // $script = $args['script'];
        // addnav(array("Chemical Pack (%s/%s)", $charge, $maxcharge));
        // }
        // break;
        case "apply-specialties":
            $skill = httpget('skill');
            $l = httpget('l');
            if ($skill == $spec) {
                $incrementmaxcharge = round(get_module_pref("charge") / 50);
                set_module_pref("maxcharge", get_module_pref("maxcharge") + $incrementmaxcharge);
                switch ($l) {
                    case 1:
                        apply_buff('CP1', array("startmsg" => "`2You wriggle your eyebrows in the manner prescribed by the Implant Doctor, and feel a rush of adrenaline discharged from a vial inside your head.", "name" => "`2Adrenaline Rush", "rounds" => 5, "atkmod" => 1.1, "roundmsg" => "Thanks to your Adrenaline Rush, your attacks are more powerful!", "wearoff" => "You feel the effects of the Adrenaline fade away.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 800);
                        break;
                    case 2:
                        apply_buff('CP2', array("startmsg" => "`2You twitch your nose just as the Implant Doctor showed you, and suddenly everything goes a little bit numb.", "name" => "`2Painkillers", "rounds" => 5, "defmod" => 1.1, "roundmsg" => "{badguy}'s blows don't seem to hurt nearly as much...", "wearoff" => "The effects of the painkillers have worn off.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 800);
                        break;
                    case 3:
                        apply_buff('CP3', array("startmsg" => "`2You wriggle your ears just as the Implant Doctor showed you, and suddenly you feel a warm, healing tingle run through your body.", "name" => "`2Stimpack", "rounds" => 5, "regen" => "ceil(<maxhitpoints>/30);", "effectmsg" => "Your StimPack heals you for {damage} points.", "wearoff" => "The StimPack effects have worn off.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 1000);
                        break;
                    case 4:
                        apply_buff('CP4', array("startmsg" => "`2You wriggle your eyebrows in the manner prescribed by the Implant Doctor, and feel a rush of adrenaline discharged from a vial inside your head.", "name" => "`2Adrenaline Rush lv2", "rounds" => 7, "atkmod" => 1.2, "roundmsg" => "Thanks to your Adrenaline Rush, your attacks are more powerful!", "wearoff" => "You feel the effects of the Adrenaline fade away.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 2000);
                        break;
                    case 5:
                        apply_buff('CP5', array("startmsg" => "`2You twitch your nose just as the Implant Doctor showed you, and suddenly everything goes a little bit numb.", "name" => "`2Painkillers lv2", "rounds" => 7, "defmod" => 1.2, "roundmsg" => "{badguy}'s blows don't seem to hurt nearly as much...", "wearoff" => "The effects of the painkillers have worn off.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 2000);
                        break;
                    case 6:
                        apply_buff('CP6', array("startmsg" => "`2You wriggle your ears just as the Implant Doctor showed you, and suddenly you feel a warm, healing tingle run through your body.", "name" => "`2Stimpack lv2", "rounds" => 7, "regen" => "ceil(<maxhitpoints>/15)", "effectmsg" => "Your StimPack heals you for {damage} points.", "wearoff" => "The StimPack effects have worn off.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 2500);
                        break;
                    case 7:
                        apply_buff('CP7', array("startmsg" => "`@You release every vial inside your Chemical Pack, and an odd feeling of euphoria washes over you...", "name" => "`@Total Chemical Release", "rounds" => 10, "atkmod" => 1.4, "defmod" => 1.4, "regen" => "ceil(<maxhitpoints>/10)", "effectmsg" => "Your StimPack heals you for {damage} points.", "roundmsg" => "{badguy} cowers under your insane shower of blows, trying desperately to get a punch in!", "wearoff" => "The StimPack effects have worn off.", "schema" => "module-implantchemicalpack"));
                        set_module_pref("charge", get_module_pref("charge") - 6000);
                        break;
                }
            }
            break;
    }
    return $args;
}
function implantlaser_dohook($hookname, $args)
{
    global $session, $resline;
    $spec = "HL";
    $name = "Skull-Mounted Laser";
    $ccode = "`\$";
    switch ($hookname) {
        case "dragonkill":
            set_module_pref("primary", 0);
            set_module_pref("secondary", 0);
            set_module_pref("status", 0);
            break;
        case "choose-specialty":
            if ($session['user']['dragonkills'] < 5) {
                break;
            }
            if ($session['user']['specialty'] == "" || $session['user']['specialty'] == '0') {
                addnav("{$ccode}{$name}`0", "newday.php?setspecialty={$spec}{$resline}");
                output("\"`5This one - goodness, it's rather heavy - actually bolts on to the side of your head, rather than going in the brain.  It's a `\$Skull-Mounted Laser`5, you see.  Most of the weight is taken up by the batteries - you get one small battery which is recharged every day, and one large battery that has to last you for your whole adventure.  It's a very, very powerful combat-orientated Implant, but you've got to keep an eye on your battery levels, or you'll be in trouble later on.\"`n`n");
            }
            break;
        case "set-specialty":
            if ($session['user']['specialty'] == $spec) {
                page_header($name);
                output("`\$Not all implants are as subtle as a chip in the brain.  You learn this after examining the housebrick-sized box jutting out of the side of your head.`n`n");
                output("It's painted black, and features a small aperature on the front.  The warning symbols for Laser Radiation and Oxidizing Element are displayed in yellow triangles just above your ear.`n`n");
                output("The user manual states that the laser's output power is pretty well infinitely-adjustable - however, taking it up too high will deplete the primary battery pretty well straight away, prompting the laser to begin draining the secondary battery.`n`nThe medic's warnings about the secondary battery come back to haunt you; use it sparingly, because it has to last you for a long time.");
                clear_module_pref("primary");
                clear_module_pref("secondary");
            }
            break;
        case "specialtycolor":
            $args[$spec] = $ccode;
            break;
        case "specialtynames":
            $args[$spec] = translate_inline($name);
            break;
        case "specialtymodules":
            $args[$spec] = "implantlaser";
            break;
        case "newday":
            if ($session['user']['specialty'] == $spec) {
                output("`nThe primary battery on your Head-Mounted Laser has been charged overnight, and is now at full capacity.`n");
                $primary = $session['user']['level'] * 2 + 20;
                set_module_pref("primary", $primary);
                set_module_pref("status", 0);
            }
            set_module_pref("status", 0);
            strip_buff('headlaser');
            break;
        case "forest":
            if ($session['user']['specialty'] == $spec) {
                if (get_module_pref("primary") > 0 || get_module_pref("secondary") > 0) {
                    addnav(array("{$ccode} `bSkull-Mounted Laser`b`0", ""));
                    addnav(array("Battery: (%s/%s)`0", get_module_pref("primary"), get_module_pref("secondary")), "");
                    addnav(array("Power output: %sKw`0", get_module_pref("powerlevel")), "");
                    addnav("Increase laser power`0", "runmodule.php?module=implantlaser&op=inc&from=forest");
                    if (get_module_pref("powerlevel") > 1) {
                        addnav("Decrease laser power`0", "runmodule.php?module=implantlaser&op=dec&from=forest");
                    }
                }
            }
            break;
        case "village":
            if ($session['user']['specialty'] == $spec) {
                if (get_module_pref("primary") > 0 || get_module_pref("secondary") > 0) {
                    addnav(array("{$ccode} `bSkull-Mounted Laser`b`0", ""));
                    addnav(array("Battery: (%s/%s)`0", get_module_pref("primary"), get_module_pref("secondary")), "");
                    addnav(array("Power output: %sKw`0", get_module_pref("powerlevel")), "");
                    addnav("Increase laser power`0", "runmodule.php?module=implantlaser&op=inc&from=village");
                    if (get_module_pref("powerlevel") > 1) {
                        addnav("Decrease laser power`0", "runmodule.php?module=implantlaser&op=dec&from=village");
                    }
                }
                set_module_pref("status", 0);
                strip_buff('headlaser');
            }
            break;
        case "worldnav":
            if ($session['user']['specialty'] == $spec) {
                if (get_module_pref("primary") > 0 || get_module_pref("secondary") > 0) {
                    addnav(array("{$ccode} `bSkull-Mounted Laser`b`0", ""));
                    addnav(array("Battery: (%s/%s)`0", get_module_pref("primary"), get_module_pref("secondary")), "");
                    addnav(array("Power output: %sKw`0", get_module_pref("powerlevel")), "");
                    addnav("Increase laser power`0", "runmodule.php?module=implantlaser&op=inc&from=worldnav");
                    if (get_module_pref("powerlevel") > 1) {
                        addnav("Decrease laser power`0", "runmodule.php?module=implantlaser&op=dec&from=worldnav");
                    }
                }
                set_module_pref("status", 0);
                strip_buff('headlaser');
            }
            break;
        case "fightnav-specialties":
            if ($session['user']['specialty'] == $spec) {
                // Evaluate the number of rounds that the battle has lasted thus far.  Because this is only called once per click, and the user can choose to play five rounds, ten rounds or to the end of the fight, we've got to get the number of rounds by looking at the remaining rounds left in the buff we set up the last time the user clicked to fight.
                if (has_buff("headlaser")) {
                    $roundsplayed = 1000 - $session['bufflist']['headlaser-roundtrack']['rounds'];
                    set_module_pref("primary", get_module_pref("primary") - get_module_pref("powerlevel") * $roundsplayed);
                    if (get_module_pref("primary") < 0) {
                        $discrepancy = get_module_pref("primary");
                        $discrepancy = $discrepancy - $discrepancy - $discrepancy;
                        debug($discrepancy);
                        set_module_pref("secondary", get_module_pref("secondary") - $discrepancy);
                        set_module_pref("primary", 0);
                        if (get_module_pref("secondary") < 0) {
                            set_module_pref("secondary", 0);
                            set_module_pref("status", 0);
                            strip_buff('headlaser');
                            strip_buff('headlaser-roundtrack');
                        }
                    }
                } else {
                    $roundsplayed = 0;
                    set_module_pref("status", 0);
                }
                apply_buff('headlaser-roundtrack', array("rounds" => 1000, "dmgmod" => 1));
                $script = $args['script'];
                $primary = get_module_pref("primary");
                $secondary = get_module_pref("secondary");
                if ($primary > 0 || $secondary > 0) {
                    addnav(array("{$ccode} `bSkull-Mounted Laser`b`0", ""));
                    addnav(array("Battery: %s (%s)`0", $primary, $secondary), "");
                    addnav(array("Power output: %sKw`0", get_module_pref("powerlevel")), "");
                    if (get_module_pref("status") == 0) {
                        if ($primary + $secondary > get_module_pref("powerlevel")) {
                            addnav(array("{$ccode} &#149; Turn on laser`0"), $script . "op=fight&skill={$spec}&l=on", true);
                        } else {
                            addnav("Not enough battery power to fire laser", "");
                        }
                        addnav(array("{$ccode} &#149; Increase laser power`0"), $script . "op=fight&skill={$spec}&l=inc", true);
                        if (get_module_pref("powerlevel") > 1) {
                            addnav(array("{$ccode} &#149; Decrease laser power`0"), $script . "op=fight&skill={$spec}&l=dec", true);
                        }
                    }
                    if (get_module_pref("status") == 1) {
                        addnav(array("{$ccode} &#149; Turn off laser`0"), $script . "op=fight&skill={$spec}&l=off", true);
                    }
                }
            }
            break;
        case "apply-specialties":
            if ($session['user']['specialty'] == $spec) {
                $skill = httpget('skill');
                $l = httpget('l');
                if ($skill == $spec) {
                    switch ($l) {
                        case "inc":
                            set_module_pref("powerlevel", get_module_pref("powerlevel") + 1);
                            output("`\$You reach up and twiddle the knobs on your housebrick-sized cranial implant.  You have `bincreased`b your laser's output power by one kilowatt, taking it up to %s.`n", get_module_pref("powerlevel"));
                            break;
                        case "dec":
                            set_module_pref("powerlevel", get_module_pref("powerlevel") - 1);
                            output("`\$You reach up and twiddle the knobs on your housebrick-sized cranial implant.  You have `bdecreased`b your laser's output power by one kilowatt, taking it down to %s.`n", get_module_pref("powerlevel"));
                            break;
                        case "on":
                            if (get_module_pref("secondary") > 0 || get_module_pref("primary") > 0) {
                                apply_buff('headlaser', array("startmsg" => "`\$Your laser steams into life, sending a beam of burning light towards {badguy}!", "name" => "`\$Head-Mounted Laser", "effectmsg" => "`\${badguy} yelps in pain as the laser burns into its body, doing `^{damage}`\$ points' worth of damage!", "rounds" => -1, "minioncount" => 1, "minbadguydamage" => ceil(get_module_pref("powerlevel") / 2), "maxbadguydamage" => ceil(get_module_pref("powerlevel") * 2), "schema" => "module-implantlaser"));
                                set_module_pref("status", 1);
                            } else {
                                output("Your laser's batteries are DEAD!");
                            }
                            break;
                        case "off":
                            set_module_pref("status", 0);
                            strip_buff('headlaser');
                            break;
                    }
                }
            }
            break;
        case "battle-defeat":
        case "battle-victory":
            if ($session['user']['specialty'] == $spec) {
                if (get_module_pref("status") == 1) {
                    set_module_pref("status", 0);
                    if (has_buff("headlaser")) {
                        $roundsplayed = 1001 - $session['bufflist']['headlaser-roundtrack']['rounds'];
                        set_module_pref("primary", get_module_pref("primary") - get_module_pref("powerlevel") * $roundsplayed);
                        if (get_module_pref("primary") < 0) {
                            set_module_pref("secondary", get_module_pref("secondary") - get_module_pref("powerlevel") * $roundsplayed);
                            set_module_pref("primary", 0);
                            if (get_module_pref("secondary") < 0) {
                                set_module_pref("secondary", 0);
                                set_module_pref("status", 0);
                                strip_buff('headlaser');
                                strip_buff('headlaser-roundtrack');
                            }
                        }
                    }
                    output("`n`\$Your head-mounted laser, seeing its target suitably chastised, switches off automatically.`n");
                }
                strip_buff('headlaser');
            }
            break;
    }
    return $args;
}
function implantteslaframe_dohook($hookname, $args)
{
    global $session, $resline;
    $spec = "TF";
    $name = "Tesla Frame";
    $ccode = "`J";
    switch ($hookname) {
        case "dragonkill":
            set_module_pref("charge", 0);
            set_module_pref("maxcharge", 10);
            break;
        case "choose-specialty":
            if ($session['user']['dragonkills'] < 8) {
                break;
            }
            if ($session['user']['specialty'] == "" || $session['user']['specialty'] == '0') {
                addnav("{$ccode}{$name}`0", "newday.php?setspecialty={$spec}{$resline}");
                output("`5\"Now, this combat-orientated Implant is a little different, and I can't recommend it to beginners at all.  It's called a `JTesla Frame.`5  It's not terribly useful at first, and because it relies on your opponent striking, it's very hard to use effectively.  But, if you time it just right, you can do some pretty serious damage with this Implant.  Like I say, it takes an awful lot of practice and skill to get used to it.\"`n`n");
            }
            break;
        case "set-specialty":
            if ($session['user']['dragonkills'] < get_module_setting("mindk")) {
                break;
            }
            if ($session['user']['specialty'] == $spec) {
                page_header($name);
                output("`JMay as well throw away your razor - you're now covered from head to toe in stubble-length black spikes, about a fingernail's width apart.  Frankly, you look bloody scary.`n`n");
                output("The crackling electricity arcing between the spikes makes you look even more frightening.`n`nTesla Frames work by amplifying and reflecting the damage that an opponent does to you.  They charge up over several rounds, and can be discharged either halfway or completely at any point thereafter.  There's no limit on the number of times you can use this ability.`n`nThe higher the charge, the better the effect will be.  The effect only lasts a fraction of a second, and doesn't have any effect if your opponent doesn't hurt you, so watch out!");
                set_module_pref("charge", 0);
                set_module_pref("maxcharge", 10);
            }
            break;
        case "specialtycolor":
            $args[$spec] = $ccode;
            break;
        case "specialtynames":
            $args[$spec] = translate_inline($name);
            break;
        case "specialtymodules":
            $args[$spec] = "implantteslaframe";
            break;
        case "fightnav-specialties":
            if ($session['user']['specialty'] == $spec) {
                // Evaluate the number of rounds that the battle has lasted thus far.  Because this is only called once per click, and the user can choose to play five rounds, ten rounds or to the end of the fight, we've got to get the number of rounds by looking at the remaining rounds left in the buff we set up the last time the user clicked to fight.
                if (has_buff("charge")) {
                    $roundsplayed = 1000 - $session['bufflist']['charge']['rounds'];
                }
                apply_buff('charge', array("dmgmod" => 1, "rounds" => 1000));
                set_module_pref("charge", get_module_pref("charge") + $roundsplayed);
                if (get_module_pref("charge") > get_module_pref("maxcharge")) {
                    set_module_pref("charge", get_module_pref("maxcharge"));
                }
                $charge = get_module_pref("charge");
                $maxcharge = get_module_pref("maxcharge");
                $script = $args['script'];
                addnav(array("{$ccode}{$name} (%s/%s)`0", $charge, $maxcharge), "");
                if ($charge < 5) {
                    addnav("5 points needed", "");
                }
                if ($charge >= 5) {
                    addnav(array("{$ccode} &#149; Partial Discharge"), $script . "op=fight&skill={$spec}&l=1", true);
                }
                if ($charge >= 10) {
                    addnav(array("{$ccode} &#149; Full Discharge"), $script . "op=fight&skill={$spec}&l=2", true);
                }
                // if ($charge >= 5) {
                // addnav(array("$ccode &#149; Partial Discharge without guard"),
                // $script."op=fight&skill=$spec&l=3", true);
                // }
                // if ($charge >= 10) {
                // addnav(array("$ccode &#149; Full Discharge without guard"),
                // $script."op=fight&skill=$spec&l=4",true);
                // }
            }
            break;
            break;
        case "apply-specialties":
            $skill = httpget('skill');
            $l = httpget('l');
            $charge = get_module_pref("charge");
            if ($skill == $spec) {
                switch ($l) {
                    case 1:
                        $charge = floor($charge / 2);
                        apply_buff('TFPartial', array("startmsg" => "`JYou discharge half of your Tesla Frame's power!`0", "name" => "Tesla Frame", "rounds" => 1, "damageshield" => ceil($charge / 10), "roundmsg" => "`JWith a sound like a thousand people clapping once in perfect time, blue flashes of electricity arc all over your body!`0", "effectmsg" => "`JCrackling electricity surges into {badguy} causing {damage} points of damage!`0", "schema" => "module-implantteslaframe"));
                        break;
                    case 2:
                        apply_buff('TFFull', array("startmsg" => "`JYou discharge your Tesla Frame's full power!`0", "name" => "Tesla Frame", "rounds" => 1, "damageshield" => ceil($charge / 10), "roundmsg" => "`JWith a sound like a thousand people clapping once in perfect time, blue flashes of electricity arc all over your body!`0", "effectmsg" => "`JCrackling electricity surges into {badguy} causing {damage} points of damage!`0", "schema" => "module-implantteslaframe"));
                        $charge = 0;
                        break;
                    case 3:
                        $charge = floor($charge / 2);
                        apply_buff('TFPartial', array("startmsg" => "`JYou let down your guard completely, and discharge half of your Tesla Frame's power!`0", "name" => "Tesla Frame", "rounds" => 1, "defmod" => 0, "damageshield" => ceil($charge / 10), "roundmsg" => "`JWith a sound like a thousand people clapping once in perfect time, blue flashes of electricity arc all over your body!`0", "effectmsg" => "`JCrackling electricity surges into {badguy} causing {damage} points of damage!`0", "schema" => "module-implantteslaframe"));
                        break;
                    case 4:
                        apply_buff('TFFull', array("startmsg" => "`JYou let down your guard completely, and discharge your Tesla Frame's full power!`0", "name" => "Tesla Frame", "rounds" => 1, "defmod" => 0, "damageshield" => ceil($charge / 10), "roundmsg" => "`JWith a sound like a thousand people clapping once in perfect time, blue flashes of electricity arc all over your body!`0", "effectmsg" => "`JCrackling electricity surges into {badguy} causing {damage} points of damage!`0", "schema" => "module-implantteslaframe"));
                        $charge = 0;
                        break;
                }
                set_module_pref("charge", $charge);
                set_module_pref("maxcharge", get_module_pref("maxcharge") + 1);
            }
            break;
    }
    return $args;
}
function get_effect($item = false, $noeffecttext = "", $giveoutput = true)
{
    global $session;
    tlschema("inventory");
    $out = array();
    if ($item === false) {
        if ($noeffecttext == "") {
            $args = modulehook("item-noeffect", array("msg" => "`&Nothing happens.`n", "item" => $item));
            $out[] = sprintf_translate($args['msg']);
        } else {
            $out[] = sprintf_translate($noeffecttext);
        }
    } else {
        eval($item['execvalue']);
        if (isset($hitpoints) && $hitpoints != 0) {
            if (!isset($override_maxhitpoints)) {
                $override_maxhitpoints = false;
            }
            if ($hitpoints > 0) {
                if ($session['user']['hitpoints'] >= $session['user']['maxhitpoints'] && $override_maxhitpoints == false) {
                } else {
                    if ($session['user']['hitpoints'] + $hitpoints > $session['user']['maxhitpoints'] && $override_maxhitpoints == false) {
                        $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
                        $out[] = sprintf_translate("`^Your hitpoints have been `@fully`^ restored.`n");
                    } else {
                        if ($override_maxhitpoints == false) {
                            $hitpoints = min($session['user']['maxhitpoints'] - $session['user']['hitpoints'], $hitpoints);
                        }
                        if ($hitpoints > 0) {
                            $session['user']['hitpoints'] += $hitpoints;
                            $out[] = sprintf_translate("`^You have been `@healed`^ for %s points.`n", $hitpoints);
                        }
                    }
                }
            } else {
                if ($hitpoints < 0) {
                    if ($session['user']['hitpoints'] + $hitpoints > 0) {
                        output("`^You `4loose`^ %s hitpoints.", abs($hitpoints));
                        $session['user']['hitpoints'] += $hitpoints;
                    } else {
                        if (!$killable) {
                            $session['user']['hitpoints'] = 1;
                            $out[] = sprintf_translate("`^You were `\$almost`^ killed.`n");
                        } else {
                            $experience = -$killable / 100;
                            $session['user']['hitpoints'] = 0;
                            $session['user']['alive'] = 0;
                            $out[] = sprintf_translate("`\$You die.`n");
                        }
                    }
                }
            }
        }
        if (isset($turns) && $turns != 0) {
            $session['user']['turns'] += $turns;
            debuglog("'s turns were altered by {$turns} by item {$item['itemid']}.");
            if ($turns > 0) {
                if ($turns == 1) {
                    $out[] = sprintf_translate("`^You `@gain`^ one turn.`n");
                } else {
                    $out[] = sprintf_translate("`^You `@gain`^ %s turns.`n", $turns);
                }
            } else {
                if ($session['user']['turns'] <= 0) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your turns.`n");
                    $session['user']['turns'] = 0;
                } else {
                    if ($turns == -1) {
                        $out[] = sprintf_translate("`^You `\$lose`^ one turn.`n");
                    } else {
                        $out[] = sprintf_translate("`^You `\$lose`^ %s turns.`n", abs($turns));
                    }
                }
            }
        }
        if (isset($attack) && $attack != 0) {
            $session['user']['attack'] += $attack;
            debuglog("'s attack was altered by {$attack} by item {$item['itemid']}.");
            if ($attack > 0) {
                $out[] = sprintf_translate("`^Your attack is `@increased`^ by %s.`n", $attack);
            } else {
                if ($session['user']['attack'] <= 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your attack except the strength of your bare fists.`n");
                    $session['user']['attack'] = 1;
                } else {
                    $out[] = sprintf_translate("`^Your attack is `\$decreased`^ by %s.`n", abs($attack));
                }
            }
        }
        if (isset($defense) && $defense != 0) {
            $session['user']['defense'] += $defense;
            debuglog("'s defense was altered by {$defense} by item {$item['itemid']}.");
            if ($defense > 0) {
                $out[] = sprintf_translate("`^Your defense is `@increased`^ by %s.`n", $defense);
            } else {
                if ($session['user']['defense'] <= 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your defense except the durability of your everpresent T-Shirt.`n");
                    $session['user']['defense'] = 1;
                } else {
                    $out[] = sprintf_translate("`^Your defense is `\$decreased`^ by %s.`n", abs($defense));
                }
            }
        }
        if (isset($charm) && $charm != 0) {
            $session['user']['charm'] += $turns;
            if ($charm > 0) {
                $out[] = sprintf_translate("`^Your charm is `@increased`^ by %s.`n", $charm);
            } else {
                if ($session['user']['charm'] <= 0) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your charm.`n");
                    $session['user']['charm'] = 0;
                } else {
                    $out[] = sprintf_translate("`^Your charm is `\$decreased`^ by %s.`n", abs($charm));
                }
            }
        }
        if (isset($maxhitpoints) && $maxhitpoints != 0) {
            if ($maxhitpoints > 0) {
                $session['user']['maxhitpoints'] += $maxhitpoints;
                $out[] = sprintf_translate("`^Your maximum hitpoints are permanently `@increased`^ by %s.`n", $maxhitpoints);
            } else {
                reset($session['user']['dragonpoints']);
                $hp = 0;
                while (list($key, $val) = each($session['user']['dragonpoints'])) {
                    if ($val == "hp") {
                        $dkhp++;
                    }
                }
                $minhp = $session['user']['level'] * 10 + $hp * 5;
                if ($session['user']['maxhitpoints'] + $maxhitpoints < $minhp) {
                    $maxhitpoints = $session['user']['maxhitpoints'] - $minhp;
                }
                if ($maxhitpoints < 0) {
                    $out[] = sprintf_translate("`^Your maximum hitpoints are permanently `\$decreased`^ by %s.`n", abs($maxhitpoints));
                    $session['user']['maxhitpoints'] += $maxhitpoints;
                }
            }
        }
        if (isset($uses)) {
            $modules = modulehook("specialtymodules");
            $names = modulehook("specialtynames");
            if (is_array($uses)) {
                while (list($key, $val) = each($uses)) {
                    if ($val > 0) {
                        if ($val == 1) {
                            $out[] = sprintf_translate("`^You `@gain`^ one point in %s.`n", $val, $names[$key]);
                        } else {
                            $out[] = sprintf_translate("`^You `@gain`^ %s points in %s.`n", $val, $names[$key]);
                        }
                    } else {
                        $val = min(abs($val), get_module_pref("uses", $modules[$key]));
                        if ($val == 1) {
                            $out[] = sprintf_translate("`^You `\$lose`^ one point in %s.`n", $val, $names[$key]);
                        } else {
                            $out[] = sprintf_translate("`^You `\$lose`^ %s points in %s.`n", $val, $names[$key]);
                        }
                        $val *= -1;
                    }
                    increment_module_pref("uses", $val, $modules[$key]);
                }
            } else {
                if ($uses == 'looseall') {
                    while (list($key, $val) = each($modules)) {
                        set_module_pref("uses", 0, $val);
                    }
                    $out[] = "`^You `\$lose all`^ uses in `\$all`^ specialties.`n";
                } else {
                    if (is_numeric($uses) && $uses > 0 && $session['user']['specialty'] != "") {
                        increment_module_pref("uses", $uses, $modules[$session['user']['specialty']]);
                        $out[] = sprintf_translate("`^You `@gain`^ %s points in %s.`n", $uses, $names[$session['user']['specialty']]);
                    } else {
                        if (is_numeric($uses) && $session['user']['specialty'] != "") {
                            $out[] = sprintf_translate("`^You `\$lose`^ %s points in %s.`n", $uses, $names[$key]);
                        }
                    }
                }
            }
        }
        if (isset($increment_specialty) && $increment_specialty > 0) {
            require_once "lib/increment_specialty.php";
            while ($increment_specialty) {
                increment_specialty("`^");
                $increment_specialty--;
            }
            $giveoutput = false;
        }
        if (isset($gems) && $gems != 0) {
            $session['user']['gems'] += $gems;
            debuglog("'s gems were altered by {$gems} by item {$item['itemid']}.");
            if ($gems > 0) {
                if ($gems == 1) {
                    $out[] = sprintf_translate("`^You `@gain`^ one gem.`n");
                } else {
                    $out[] = sprintf_translate("`^You `@gain`^ %s gems.`n", $gems);
                }
            } else {
                $gems = min(abs($gems), $session['user']['gems']);
                if ($gems == 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ one gem.`n", $gems);
                } else {
                    $out[] = sprintf_translate("`^You `\$lose`^ %s gems.`n", $gems);
                }
            }
        }
        if (isset($gold) && $gold != 0) {
            $session['user']['gold'] += $gold;
            debuglog("'s gold were altered by {$gold} by item {$item['itemid']}.");
            if ($gold > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s gold.`n", $gold);
            } else {
                $gold = min(abs($gold), $session['user']['gold']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s gold.`n", $gold);
            }
        }
        if (isset($experience) && $experience != 0) {
            if (is_float($experience)) {
                $bonus = round($session['user']['experience'] * $experience, 0);
            } else {
                $bonus = $experience;
            }
            $session['user']['experience'] += $experience;
            debuglog("'s experience was altered by {$bonus} by item {$item['itemid']}.");
            if ($bonus > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s experience.`n", $bonus);
            } else {
                $bonus = min(abs($bonus), $session['user']['experience']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s experience.`n", $bonus);
            }
        }
        if (isset($deathpower) && $deathpower != 0) {
            $session['user']['deathpower'] += $deathpower;
            if ($deathpower > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s favor with `\$Ramius`0.`n", $deathpower);
            } else {
                $deathpower = min(abs($deathpower), $session['user']['deathpower']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s favor with `\$Ramius`0.`n", $deathpower);
            }
        }
        if (isset($gravefights) && $gravefights != 0) {
            $session['user']['gravefights'] += $gravefights;
            if ($gravefights > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s gravefights.`n", $gravefights);
            } else {
                $deathpower = min(abs($gravefights), $session['user']['gravefights']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s gravefights.`n", $gravefights);
            }
        }
        if (isset($extraflirt) && is_module_active("lovers") && $extraflirt == true && get_module_pref("seenlover", "lovers")) {
            set_module_pref("seenlover", false, "lovers");
            $him = sprintf_translate("him");
            $her = sprintf_translate("her");
            require_once "lib/partner.php";
            $out[] = sprintf_translate("`^You miss %s`^ and want to see %s again.`n", get_partner(), $session['user']['sex'] ? $him : $her);
        }
        if (isset($extratravel) && is_module_active("cities") && $extratravel != 0) {
            increment_module_pref("traveltoday", -$extratravel, "cities");
            if ($extratravel > 0) {
                $out[] = sprintf_translate("`^You feel `@refreshed`^.");
                $out[] = sprintf_translate("`^You may travel %s times `@more`^ today.`n", $extratravel);
            } else {
                $out[] = sprintf_translate("`^You feel `\$tired`^.");
                $out[] = sprintf_translate("`^You may travel %s times `\$less`^ today.`n", $extratravel);
            }
        }
        if (isset($buff) && is_array($buff)) {
            require_once "lib/buffs.php";
            apply_buff("item-{$item['itemid']}", $buff);
            $out[] = sprintf_translate("`^Something feels strange within your body.`n");
        }
        if (isset($extrabuff) && is_array($extrabuff)) {
            require_once "lib/buffs.php";
            while (list($key, $val) = each($extrabuff)) {
                if (has_buff($key)) {
                    while (list($vkey, $vval) = each($val)) {
                        $session['bufflist'][$key][$vkey] += $vval;
                        $things = true;
                    }
                }
            }
            if ($things) {
                $out[] = sprintf_translate("`^You feel something strange happening.`n");
            }
        }
        if (isset($strip)) {
            require_once "lib/buffs.php";
            if (has_buff($strip)) {
                strip_buff($strip);
                $out[] = sprintf_translate("`^You have a weird feeling.`n");
            }
        }
    }
    foreach ($out as $index => $text) {
        if (is_array($text)) {
            foreach ($text as $sec => $text2) {
                $newout[] = $text2;
            }
        } else {
            $newout[] = $text;
        }
    }
    $args = modulehook("itemeffect", array("out" => $newout, "item" => $item));
    $out = $args['out'];
    if (count($out) == 0) {
        if ($noeffecttext == "") {
            $args = modulehook("item-noeffect", array("msg" => "`&Nothing happens.`n", "item" => $item));
            $out[] = sprintf_translate($args['msg']);
        } else {
            if ($giveoutput) {
                $out[] = sprintf_translate($noeffecttext);
            }
        }
    }
    $effect_text = join($out, "");
    tlschema();
    return $effect_text;
}